Need a help to show related file to show from mysql DB

Started on the old forum in October 2020 · view the original in the archive · old links redirect here

11 replies · 116 views · started 6 years ago · 1 min read

3 participants
ayesham Developer · 69 posts #1

i'm working on an autoindex mp3 downloading script, GET_($id) @ Download page shows relevant id information. from $artist variable I need to search my DB_table and view Artists other songs in this page.

table is like

table name 'mp3'

id - songurl - Song Title - Artist - Music - Lyrics - Size - Category - Date

please help me

something else Fellow · 2,296 posts #2
$result = mysqli_query($con, "SELECT songurl, SongTitle FROM mp3 WHERE Artist='".$artist."'");
$out = 'More songs by same artist: <br/><br/>';
while($row = mysqli_fetch_assoc($result))
{
$out .= '<a href="'.$row[0].'">'.$row[1].'</a><br/>';
}
echo $out;
ayesham Developer · 69 posts #3

it shows blank bro, tried so meny timesand I don't know why?

But I just copied songurl, SongTitle FROM mp3 WHERE Artist="Gayan" and run on Phpmyadmin sql it is showing results .

ayesham Developer · 69 posts #4
<?php include(db_con.php); $result = mysqli_query($con, "SELECT `songurl`, `Songtitle`, `artist`, `cover` FROM `mp3` WHERE `artist`='".$artist."'"); while($row = mysqli_fetch_array($result)) { ?> <?php echo $row['cover'];?> <?php echo $row['artist'];?> <?php echo $row[' SongTitle'];?> <?php } mysqli_close($con); ?>
something else Fellow · 2,296 posts #5
<?php
include(db_con.php);
$artist = mysqli_real_escape_string($con, $_REQUEST['artist']);  //use mysqli_real_escape_string on any user inputs to help avoid mysql injections
//variable $artist needs to be set to something or collected from url or a form ($_GET or $_POST or for both $_REQUEST)

$result = mysqli_query($con, "SELECT `songurl`, `Songtitle`, `artist`, `cover` FROM `mp3` WHERE `artist`='".$artist."'");

while($row = mysqli_fetch_array($result))
{
echo $row['cover'].'<br/>'
.$row['artist'].'<br/>'
.$row['SongTitle'].'<br/><br/>'; //note you had a space in: $row['_SongTitle'];
//try not to open and close php too much as it will cause your script to slow down, also avoid using too many echo's 
}
mysqli_close($con);
?>
something else Fellow · 2,296 posts #6

to use php parsing in the forums use: [php]Your code here[/php]

=

Your code here

or for other codes: [code]Your code here[/code]

=

Your code here
👍 1
Share
s2k Junior · 11 posts #7

Hi ayesham,

Have you tried to catch any errors from the query? perhaps try:

<?php
include("db_con.php");

$result = mysqli_query($con, "SELECT `songurl`, `Songtitle`, `artist`, `cover` FROM `mp3` WHERE `artist`='".$artist."'");

// check that a result was found?
if (!$result) {
printf("Error: %s\n", mysqli_error($link));
}

// perhaps for debugging maybe just dump the result if the above doesn't work?
// this should give you a peak inside the result variable
die(var_dump($result));

while ($row = mysqli_fetch_array($result)) {
echo "{$row['cover']}<br/>";
echo "{$row['artist']}</br>";
echo "{$row['SongTitle']}";
}

mysqli_close($con);
?>

Also I would recommend escaping your parameters like something else suggested, hope this helps

👍 1
Share
something else Fellow · 2,296 posts #8

Slight adjustment of s2k 's code:

// check that a result was found?
if (!$result) {
printf("Error: %s\n", mysqli_error($con));
}
ayesham Developer · 69 posts #10

tried my best but it shows blank only brothers

something else Fellow · 2,296 posts #11

With it as your code:

<?php
include(db_con.php); //guessing mysqli has been connected here and stored in variable $con

$result = mysqli_query($con, "SELECT * FROM mp3 WHERE artist='".$_REQUEST['artist']."'");

while($row = mysqli_fetch_array($result))
{
?>

<?php echo $row['cover'];?><br/>
<?php echo $row['artist'];?><br/>
<?php echo $row['SongTitle'];?>

<?php

}

mysqli_close($con);
?>

Note: This is unprotected against mysqli injections

ayesham Developer · 69 posts #12
$result = mysqli_query($con, "SELECT * FROM files WHERE artist='".$row['artist']."'");

while($row = mysqli_fetch_array($result))
{

this was working fine thanks genius? 🙂

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close