How do I create a directory path on PHP - 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

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 :)

PHP - Display Serial Numbers automatically using for loop

<thead>
<tr>
<th> S.No </th>
<th> Movie Name </th>
<th> Language </th>
</tr>
</thead>
<?php
$result = mysqli_query($connect,"SELECT * FROM movies ;")or die(mysqli_error());
$rows = mysqli_fetch_array($result);
?>
<tbody>
<?php
$counter=0;
foreach($result as $rows)
{
$counter=$counter+1;
?>
<?php echo "<tr><td>" . $counter . "</td><td>" . $rows['language'] . "</td><td>" . $rows['movie_name'] . "</td></tr>"; ?>
<?php } ?>
</tbody>
I want to display serial numbers in the table automatically for the fetched results . Here the serial number displays correctly for the first five results like 1,2,3,4,5 rows
but on the 2nd page the number shows like 8,9,10,6,7
Where i am making mistake ? I even tried while loop and forloop increment counter. Im using Bootstrap data table to display the results from database.
<?php
$result = mysqli_query($connect,"SELECT * FROM movies");
$counter=0;
while($rows = mysqli_fetch_array($result)){
echo "<tr><td>" . $counter . "</td>
<td>" . $result[$counter]['language'] . "</td>
<td>" . $result[$counter]['movie_name'] . "</td>
</tr>";
$counter++;
}
?>
This should work for you. You need to fetch the results inside a loop in order to parse them.
Try this
You have to declare the $i=1 outside of the while loop and $i++ inside the while loop. So it will display the number of rows available in the database.
You have to use while loop instated of foreach.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM movies";
$result = mysqli_query($conn, $sql);
//mysqli_close($conn);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<table>
<thead>
<tr>
<th> S.No </th>
<th> Movie Name </th>
<th> Language </th>
</tr>
</thead>
<tbody>
<?php
$i=1;
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($rows = mysqli_fetch_assoc($result)) {
echo "<tr>
<td>" . $i . "</td>
<td>" . $rows['language'] . "</td>
<td>" . $rows['movie_name'] . "</td>
</tr>";
$i++;
}
} else {
echo "0 results";
}
?>
</tbody>
</table>
</body>
</html>

getting data from database to html table using php

i want to fetch data from database and insert it in my html table here is my code i dont know where is my misatake:
<div class="ibox-content">
<?php
$servername = "localhost";
$username = "sehnoqta_userbmc";
$password = "u?gQ=uS%t;a?";
$dbname = "sehnoqta_bmc";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT name, lastname, phone FROM regis";
$result = $conn->query($sql);
$conn->close();
?>
<table dir="rtl" class="table table-striped table-bordered table-hover dataTables-example" >
<thead>
<tr>
<th>Name</th>
<th>Last Name</th>
<th>Phone</th>
<th>Email</th>
<th>Acc Type</th>
</tr>
</thead>
<tbody>
<?php
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo
"<tr><td>" . $row["name"]. "</td>
<td>" . $row["lastname"]. "</td>
<td>" . $row["phone"]. "</td></tr>";
<td>0795934799</td>
<td class="center">demo#demo.com</td>
<td>Admin</td>
}
echo "</table>";
}
?>
</tbody>
</table>
</div>
data i fetch from database shows out of table.
sorry for bad English :)
Theres just a Syntax error in your while loop. You need to print everything inside the echo command. As you can see in yours, you have echo(...); followed by some HTML still inside the php. So you should correct it by changing it to the following.
while($row = $result->fetch_assoc()) {
echo
"<tr><td>" . $row["name"]. "</td>
<td>" . $row["lastname"]. "</td>
<td>" . $row["phone"]. "</td></tr>
<td>0795934799</td>
<td class=\"center\">demo#demo.com</td>
<td>Admin</td>";
}
A good resource that you can use is phpchecker.com that checks your code for errors
Here is the code that works...
<?php
$servername = "localhost";
$username = "sehnoqta_userbmc";
$password = "u?gQ=uS%t;a?";
$dbname = "sehnoqta_bmc";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT name, lastname, phone FROM regis";
$result = $conn->query($sql);
$conn->close();
?>
<table dir="rtl" class="table table-striped table-bordered table-hover dataTables-example" >
<thead>
<tr>
<th>Name</th>
<th>Last Name</th>
<th>Phone</th>
<th>Email</th>
<th>Acc Type</th>
</tr>
</thead>
<tbody>
<?php
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo
"<tr><td>" . $row["name"]. "</td>
<td>" . $row["lastname"]. "</td>
<td>" . $row["phone"]. "</td>";
"<td>0795934799</td>";
"<td class='center'>demo#demo.com</td>";
"<td>Admin</td></tr>";
}
echo "</table>";
}
Hope this helps......
echo
"<tr><td>" . $row["name"]. "</td>
<td>" . $row["lastname"]. "</td>
<td>" . $row["phone"]. "</td>
<td>0795934799</td>
<td class='center'>demo#demo.com</td>
<td>Admin</td></tr>";

How to upload a folder of images using php and mysql

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.

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