I am trying to to put a music from my table in phpmyadmin into a modal box. I have been able to have them in a modal box but it puts all of them in and I only want the specific music allocated to a specific button to play.
Here is my code:
audio.php
<?php
/*the variables*/
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "arashi_site";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
/*sql to extract the data*/
$sql = "SELECT * FROM music";
$result = mysqli_query($conn, $sql);
/*condition to see if there are any results*/
if (mysqli_num_rows($result) > 0) {
/*a loop function to output */
while($row = mysqli_fetch_assoc($result)) {
/*echos the data within each column*/
/*within the final <td>, audio controls will be echoed to play the song files. When the user clicks any of the buttons in the audio controls, they will remain in the second section the the site and not be sent back to the top.*/
echo "<button type='button' class='btn btn-info btn-lg' data-toggle='modal' data-target='#myModal'>" . $row["song_name"] . "</button>";
}
}
else {
echo "0 results";
}
mysqli_close($conn);
?>
audio2.php:
<?php
/*the variables*/
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "arashi_site";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
/*sql to extract the data*/
$sql = "SELECT song_name FROM music";
$result = mysqli_query($conn, $sql);
/*condition to see if there are any results*/
if (mysqli_num_rows($result) > 0) {
/*a loop function to output */
while($row = mysqli_fetch_assoc($result)) {
echo "<audio id='sound' controls>
<source src='audio/" .$row['song_name']."' type='audio/mpeg'>
Your browser does not support the audio element.
</audio>";
}
}
else {
echo "0 results";
}
mysqli_close($conn);
?>
Related
please can someone help me with this code? It shows all the users’ info but i need it to show only the info of the logged user.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "username";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT AEG FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 3) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["AEG"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
Upon login, store the email/username/id in a $_SESSION variable;
$_SESSION['email'] = $email; // in this example I used email
Then on your file, you can access session variables using $_SESSION['variable'] and use it on your sql statement;
My modifications are the ones with comments.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "username";
/*Store session data in a variable*/
$email = $_SESSION['email'];
/**********************************/
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
/*Add where clause to your sql statement*/
$sql = "SELECT AEG FROM users WHERE email ='".$email."'";
/****************************************/
$result = $conn->query($sql);
if ($result->num_rows > 3) {
while($row = $result->fetch_assoc()) {
echo "id: " . $row["AEG"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
Try this one if you are having 4 user then it is showing only one
if($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo "id: " . $row["AEG"]. "<br>";
}
}
else
{
echo "0 results";
}
When i click the submit button for my search from, for each result there is a paragraph with a ">" which is put at the top of the page and I have no idea where it comes from. Here's my code (using wordpress)
[insert_php]
$db_host = "localhost";
$username = "root";
$password = "";
$dbname = "Tickets";
// Create connection
$conn = new mysqli($db_host, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if((isset($_POST['Search'])) && ($_POST['Search'] != '')){
$search = $_POST['Search'];
$sql = "SELECT * FROM `Problem_Solutions` WHERE (`Problem_Type` LIKE '%$search%') OR (`Solution_Title` LIKE '%$search%')";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
if ($count > 0){
echo "<table><th>Title</th><th>Solution</th><th>Count</th>";
while ($row = mysqli_fetch_array($query)){
echo "<tr><td>".$row['Solution_Title']."</td>";
echo "<td>".$row['Solution']."</td>";
echo "<td>".$row['Count']."</td>";
echo "<<td><form name='form' method='POST'><input style='background:#6B8E23;' type='submit' name='".$row['Solution_ID']. "' value='This Solution Solved My Problem' /></form></td></tr>";
} echo "</table>";
}else{
echo " 0 results found";
}
}
$conn->close();
[/insert_php]
Your problem is in this line:
echo "<<td><form name='f
Delete the first <
What I wan't to do is create buttons that are automatically generated from the database. So when I add a new record in the database the button is created Is this possible with a loop? So yes how do I create the button.
This is what I have so far:
<?php
$servername = "localhost";
$username = "root";
$password = "Iamthebest1009";
$dbname = "dktp";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM theme";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "". $row["theme_name"]. "<br>";
}
} else {
echo "no results";
}
$conn->close();
?>
Yes it is possible. you need to echo html
<?php
$servername = "localhost";
$username = "root";
$password = "Iamthebest1009";
$dbname = "dktp";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM theme";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$your_url ="https://www.google.com";
echo "". $row["theme_name"]. "<br>";
echo '<input type="button" name="' . $row["theme_name"]. '" value="'. $row["theme_name"].'">';
}
} else {
echo "no results";
}
$conn->close();
?>
I've been spending hours on this one.
So I got two tables, the "candidate_list" table and "election_title" table. I need to display all the candidates running in a certain election/club by matching the "ename" column on both tables. Also, it has an if while statement because it is highly dependent on admin input. Hope you can help me with this one.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "voting_system";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT ename FROM election_title ORDER BY `sdate` ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$ename= $row['ename'];
?>
<p><font size= "6px" align = "center" color = "#efbf77"> <?php echo $row['ename']. "<br>";?></p>
<?php
$servername1 = "localhost";
$username1 = "root";
$password1 = "";
$dbname1 = "voting_system";
$conn1 = new mysqli($servername1, $username1, $password1, $dbname1);
if ($conn1->connect_error) {
die("Connection failed: " . $conn1->connect_error);
}
$sql = "SELECT * FROM candidate_list WHERE ename IN (SELECT ename FROM election_title);";
$result = $conn1->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$ename= $row['ename'];
$pos= $row['pos'];
$fname= $row['fname'];
$mname= $row['mname'];
$lname= $row['lname'];
?>
<button type="submit" class = "ename"> <?php echo "<p class = 'bold'>" .$row['ename']. " </p>" .$row['pos']. "<br>" .$row['fname']. " " .$row['mname'] . " " .$row['lname'];?> </button>
<?php
}
} else {
echo "0 results";
}
$conn->close();
?>
<?php
}
} else {
echo "0 results";
}
$conn1->close();
?>
As of now, it only display one election title. I need it to loop and display all my elections together with its respective candidates.
UPDATE: The query has worked after some reading on INNER JOINS. Thanks for your help guys! :)
This is my query, and it is working fine, but how do I have the results returned in an HTML TABLE. for example I want the first 5 results on row 1 the next 5 on row 2 and so on. Any help would be great. Thank you!
<?php
$servername = "XXX";
$username = "XXX";
$password = "XXX";
$dbname = "XXX";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM manufacturer LIMIT 10 OFFSET 0";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<td><a href="index.php?route=product/manufacturer/info&
manufacturer_id='. $row["manufacturer_id"] .'"><img src="image/' .
$row["image"] .'"></a></td>';
}
} else {
echo "0 results";
}
$conn->close();
<?php
$servername = "XXX";
$username = "XXX";
$password = "XXX";
$dbname = "XXX";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn- >connect_error);
}
$sql = "SELECT * FROM manufacturer LIMIT 10 OFFSET 0";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$i=0;
while($row = $result->fetch_assoc()) {
If($i==5){
echo "</tr>";
echo "<tr>";
$i=0;
}
echo '<td><a href="index.php? route=product/manufacturer/info&
manufacturer_id='. $row["manufacturer_id"] .'">. <img src="image/' .
$row["image"] .'"></a></td>';
$i++;
}
} else {
echo "0 results";
}
$conn->close();