How to upload a folder of images using php and mysql - php

Basically I have to create a jukebox type chart via mysql and php using xampp.
I've done the basics of setting up the table my referring to mysql database etc. I just don't get how to code the path to the image folder I have created. My Image folder is in htdocs under my folder I created called Jukebox. This is my coding:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jukebox";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM Music";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table>
<tr>
<th>Artist</th>
<th>Title</th>
<th>Album</th>
<th>Albumcover</th>
<th>Play</th>
</tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo
"<tr>
<td>" . $row["Artist"]. "</td>
<td>" . $row["Title"]. "</td>
<td>" . $row["Album"]. "</td>
<td>" . $row["Albumcover"]
. "</td>
<td>" . $row["Play"] . "</td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
} ?>
</body>
</html>
This is what my php coding looks like
This is my image folder which i wish to create a path to so that all the album art can come up in the albumcover column
How do I create this path with php and mysql

<style>
.preview
{
width:400px;
border:solid 1px #dedede;
padding:10px;
color:#cc0000;
}
</style>
<?php
// output data of each row
while($row = $result->fetch_assoc()) {
echo
"<tr>
<td>" . $row["Artist"]. "</td>
<td>" . $row["Title"]. "</td>
<td>" . $row["Album"]. "</td>
<td><img class='preview' src='jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"]."></td>
<td>" . $row["Play"] . "</td>
</tr>";
}

No need to do anything special. You are working from a base directory of /jukebox/, your images reside in /jukebox/img/. Let's make it work:
<img src=\"/jukebox/img/".$row['Albumcover']."\"/>
Within your loop. Now the album cover will appear as an image in that row.

Related

Phpmyadmin not opening html table (potential server issue)

I am having issues with linking mysql to html through a server, the ports are all in order and the I have had no issues in linking the server to phpmyadmin. I have no password on the server and the username is 'root'.
please help :)
<?php
$servername = "localhost";
$username = "root"
$password= "";
$database = "stock_order";
$connection = new mysqli($servername, $username, $password, $database)
I believe this might be an error because my server port is 3008 however, that shouldn't be an issue
// checking connection
if ($connection)->connect_error {
die("connection failed: " . $connection ->connect_error);
}
//read the data from the customer table
$sql = "SELECT * FROM customertable";
$result = $connection->query($sql);
if (!$result) {
die("Invalid query: " .$connection->error);
}
// while loop - reads data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . $row["ItemID"] . "</td>
<td>" . $row["ItemName"] . "</td>
<td>" . $row["Quantity"] . "</td>
<td>" . $row["Description"] . "</td>
<td>" . $row["DeliveryMerchant"] . "</td>
<td>" . $row["Cost_of_item"] . "</td>
<td>" . $row["VAT_Percentage"] . "</td>
<td>" . $row["VAT"] . "</td>
<td>" . $row["Total_cost_of_item"] . "</td>
<td>
<a class='btn btn-primary btn-sm' href='update'>Update</a>
<a class='btn btn-danger btn-sm' href='delete'>Delete</a>
</td>
</tr>";
}
?>
</thead>
<tbody>
<tr>
<td>78956</td>
<td>Merch 2008 Monitor 4K</td>
<td>1</td>
<td>Fragile</td>
<td>TPL Resources</td>
<td>£1080</td>
<td>20%</td>
<td>£216</td>
<td>£1296</td>
<td>
<a href='update'>Update</a>
<a href='delete'>Delete</a>
</td>
</tr>
</tbody>
</table>
<body>
</body>
<?php
$conn-mysqli_connect("localhost", "root", "", "customer_order_table");
$sql = "SELECT * FROM stock_order";
$result = $conn ->query($sql);
if ($result->num_rows > 0) {
while ($row = $result -> fetch_assoc()) {
echo "<tr><td>" . $row["itemID"] . "<tr><td>" . $row["ItemName "] . "<tr><td>" .
$row["Quantity"] .
"<tr><td>" . $row["Description"] . "<tr><td>" . $row["DeliveryMerchant"] . "<tr>
<td>" . $row["VAT_Percentage"]
. "<tr><td>" . $row["VAT"] . "<tr><td>" . $row["Total_cost_of_item"] . "<tr><td>"
}
}
else {
echo "No Results";
}
$conn ->close();
?>
</style>
</table>
</body>
</html>
when I type in 'localhost/customertable/' in the address bar the page cannot be found, displaying an error 404.
Thanks in advance :)

Merge and display 2 database and 2 tables

Hey guys i have a problem, there is a page where i need to display data acording to date, but from 2 databases and from 2 tables from each databases,
1 Database name = highmob_comenzi Tables = players and vanzari
2 Database name = highmob_comenzi2 Tables = players and vanzari
this is the code what i got , i have tryed "select * from players, vanzari" but still no luck, even that wont extract data from both databases :(
<table class='table table-responsive-sm table-bordered table-striped table- sm' border="2px">
<thead>
<tr>
<th>Locatia Vanzari</th>
<th>Tip. Cert.</th>
<th>Nr.</th>
<th>Status Comanda Mobila</th>
<th>Status Comanda Tapiterii</th>
<th>Status Livrare</th>
<th>Ora Livrare</th>
<th>Detalii Comanda</th>
<th>Total</th>
<th>Avans</th>
<th>Rest</th>
<th></th>
</tr>
<?php
$servername = "localhost";
$username = "id";
$password = "pw";
$dbname = "highmob_comenzi2";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = ("select *
from highmob_comenzi.players
cross join highmob_comenzi.vanzari
union all
select *
from highmob_comenzi2.players
cross join highmob_comenzi2.vanzari
WHERE statuslivrare >= CURRENT_DATE()");
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "
</thead>
<tbody>
<tr>
<td>HERE DATABASE NAME</td>
<td><a href='vezibilettransportcomenzi.php?id=" . $row["id"] . "' target='_blank' class='btn btn-sm btn-warning'>Tip. Cert.</a></td>
<td>" . $row["id"] . "</td>
<td>
" . $row["statuscomanda"] . "
</td>
<td>" . $row["statuscomandatapiterii"] . "</td>
<td>" . $row["statuslivrare"] . "</td>
<td>" . $row["oralivrare"] . "</td>
<td>" . $row["detaliicomanda"] . "</td>
<td>
" . $row["totaldeplata"] . "</td>
<td>" . $row["avans"] . " <br><a style='color:red;'>" . $row["banipreluati"] . "</a></td>
<td>" . $row["restdeplata"] . "<br><a style='color:red;'>" . $row["banipreluatirest"] . "</a></td>
<td><a href='edit.php?id=" . $row["id"] . "' target='_blank' class='btn btn-sm btn-primary' >Vezi comanda</a></td>
</tr>
";
}
} else {
echo "Nu sunt transporturi!";
}
$conn->close();
?>
</tbody>
</table>
you can access to the table in the same query without problem eg (assuming the tables have the same struct in both the database):
select *
from highmob_comenzi.players
cross join highmob_comenzi.vanzari
union all
select *
from highmob_comenzi2.players
cross join highmob_comenzi2.vanzari
this is only a sample for accessing to the 2 database in a single query. you must rethink the query with you join and condition
but based on you comment seem you need just (assuming that statuslivrare is a colum of the vanzari table)
select *
from highmob_comenzi.players
cross join highmob_comenzi.vanzari
WHERE vanzari.statuslivrare >= CURDATE()");
<?php
$servername = "localhost";
$username = "ID";
$password = "PW";
$dbname1 = "highmob_comenzi2";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname1 );
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = ("select * from highmob_comenzi2.players cross join highmob_comenzi2.vanzari
");
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "
</thead>
<tbody>
<tr>
<td>HERE DATABASE NAME</td>
<td><a href='vezibilettransportcomenzi.php?id=" . $row["id"] . "' target='_blank' class='btn btn-sm btn-warning'>Tip. Cert.</a></td>
<td>" . $row["id"] . "</td>
<td>
" . $row["statuscomanda"] . "
</td>
<td>" . $row["statuscomandatapiterii"] . "</td>
<td>" . $row["statuslivrare"] . "</td>
<td>" . $row["oralivrare"] . "</td>
<td>" . $row["detaliicomanda"] . "</td>
<td>
" . $row["totaldeplata"] . "</td>
<td>" . $row["avans"] . " <br><a style='color:red;'>" . $row["banipreluati"] . "</a></td>
<td>" . $row["restdeplata"] . "<br><a style='color:red;'>" . $row["banipreluatirest"] . "</a></td>
<td><a href='edit.php?id=" . $row["id"] . "' target='_blank' class='btn btn-sm btn-primary' >Vezi comanda</a></td>
</tr>
";
}
} else {
echo "Nu sunt transporturi!";
}
$conn->close();
?>
This is what i got and its working, it displays data from 1 database nammed highmob_comenzi2 and tables players and vanzari, but im getting alot of duplicates on display and also i need to insert a WHERE clause :
WHERE statuslivrare >= CURRENT_DATE()
any ideea?

How to style td's that are selecting MySQL data

I can't seem to work out how I can style the td's in the following code.
I want the Match Details to be aligned to the right. Normally I would just insert straight in, but this doesn't seem to work.
I also want to bolded the away team row.
Any idea?
Cheers
<h3>SEPTEMBER 2017</h3>
<table><?php $sql = "SELECT * FROM `results` WHERE `year`='2017' AND `Division`='AA1' AND `month`='September'";
$result = $conn ->query($sql);
if ($result-> num_rows > 0) {
while($row = $result -> fetch_assoc()) {
echo "<tr><td>" . $row["day"] . ", " . $row["date"] . " " . $row["month"] . "</td> <td>" . $row["awayteam"] . "</td> <td>" . $row["homescore"] . " - " . $row["awayscore"] . "</td> <td>" . $row["venue"] . "</td> <td>ESFA League</td><td>Match details</td></tr><br>";
}
"</table>";
} else {
echo "No games listed for this month";
}
?></table>
to styling your display data you need to apply css code as declared in <style> tag.
<style>
.table-boarderd{
border: 1px solid black;
text-align: left;
}
.pull-right{
text-align: right;
}
.bold{
font-weight: bold;
}
</style>
<h3>SEPTEMBER 2017</h3>
<table class="table-boarderd">
<?php
$sql = "SELECT * FROM `results` WHERE `year`='2017' AND `Division`='AA1' AND `month`='September'";
$result = $conn ->query($sql);
?>
<?php
if ($result-> num_rows > 0) {
while($row = $result -> fetch_assoc()){ ?>
<tr>
<td><?=$row["day"]?></td>
<td><?=$row["date"]?></td>
<td><?=$row["month"]?></td>
<td class="pull-right bold"><?=$row["awayteam"]?></td>
<td><?=$row["homescore"]?>-<strong><?=$row["awayscore"]?></strong></td>
<td><?=$row["venue"]?></td>
<td>ESFA League</td>
<td>Match details</td>
</tr><br/>
<?php } ?>
</table>
<?php }
else {
echo "No games listed for this month";
}
?>
As I have used custom css with table awayteam cell you can use at anywhere
Write the css for the code in head tag
table, th, td {
border: 1px solid black;
text-align: right;
}
Then you're trying it the false way, because the straight way in is possible. Also you've closed your table twice. I removed it once. Try this:
<h3>SEPTEMBER 2017</h3>
<table><?php $sql = "SELECT * FROM `results` WHERE `year`='2017' AND `Division`='AA1' AND `month`='September'";
$result = $conn ->query($sql);
if ($result-> num_rows > 0) {
while($row = $result -> fetch_assoc()){
echo "<tr><td>" . $row["day"] . ", " . $row["date"] . " " . $row["month"] . "</td> <td><b>" . $row["awayteam"] . "</b></td> <td>" . $row["homescore"] . " - " . $row["awayscore"] . "</td> <td>" . $row["venue"] . "</td> <td>ESFA League</td><td style="text-align: right;">Match details</td></tr><br>";
}
}
else {
echo "No games listed for this month";
}
?></table>

How do I create a directory path on PHP

I have created a database on phpmyadmin via xampp. I'm currently trying to make a music player and I am having difficulty linking my music folder to my php coding. I don't know the right syntax or the location I should be working on either within my coding to implement the music player.
This is how my php translate currently and if you look at the Play column, it references the audio file's name
And this is where all my music is stored
Someone please help me, please..1
Here's my coding as well
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jukebox";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM Music";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table>
<tr>
<th>Artist</th>
<th>Title</th>
<th>Album</th>
<th>Albumcover</th>
<th>Play</th>
</tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo
"<tr>
<td>" . $row["Artist"]. "</td>
<td>" . $row["Title"]. "</td>
<td>" . $row["Album"]. "</td>
<td><img src='/jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"]."></td>
<td>" . $row["Play"] . "></td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
?>
</body>
</html>
<td>
<img src='"<?php echo $_SERVER['DOCUMENT_ROOT']; ?>"'/jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"].">
</td>
try this one

Create a path to image folder using mysql and php

Basically I have to create a jukebox type chart via mysql and php using xampp.
I've done the basics of setting up the table my referring to mysql database etc. I just dont get how to code the path to the image folder I have created.
My Image folder is in htdocs under my folder I created called Jukebox.
This is my code:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jukebox";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM Music";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table>
<tr>
<th>Artist</th>
<th>Title</th>
<th>Album</th>
<th>Albumcover</th>
<th>Play</th>
</tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo
"<tr>
<td>" . $row["Artist"]. "</td>
<td>" . $row["Title"]. "</td>
<td>" . $row["Album"]. "</td>
<td>" . $row["Albumcover"]
. "</td>
<td>" . $row["Play"] . "</td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
?>
</body>
</html>
This is what comes up as my online jukebox, and in the Album cover column I want the album art to come up
And this is where my images are, how would i create the path to img folder so the album art comes up?
I'm assuming you want the image in the "Albumcover" part of your code. If so you can echo out a html line. You can name your images in the "jukebox" folder with the album name. The code will appear as
<td>" . $row["Artist"]. "</td>
<td>" . $row["Title"]. "</td>
<td>" . $row["Album"]. "</td>
<td>" <img src=\"jukebox/".$row["Album"].".png\" >"</td>
For that all images will need to be of file type png which is easy to do, just save them normally and add .png at the end. The same album name on your database will need to be the same name given to the file. There are other filetypes you can use such as .jpg.
I don't really see your problem.
What do you store in "albumcover"?
Let's say you save the relative path to your albumcover.
So you can print out
<td><img src="' . $row["Albumcover"] . '"></td>
Use your mp3 as a tag and open that in a new tab.May be this is you needed.I assume jukebox/mp3/ as your mp3 folder
<?php
// output data of each row
while($row = $result->fetch_assoc()) {
echo
"<tr>
<td>" . $row["Artist"]. "</td>
<td>" . $row["Title"]. "</td>
<td>" . $row["Album"]. "</td>
<td><img src='jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"]."></td>
<td><a href='jukebox/mp3/" . $row["Play"] . "' target='blank'>" . $row["Play"] . "</a>
</td>
</tr>";
}

Categories