Jump to content

MYSQL select in a varible


iJoseph

Recommended Posts

I have some code that I need to put into a variable to post onto a site. But is just comes up with the actual code, not the result. Here is the code:

 

<?php
$search = $_GET['search'];

if($search == '') die('You didn\'t fill out the Search field.');

$con = mysql_connect("localhost","hhh","hhh");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("music", $con);

$result = mysql_query(" SELECT * FROM songs WHERE album='$search'");

$num_rows = mysql_num_rows($result);

if($num_rows == 0) die('No results were found.');

$content = '
<?php
echo "<table border=\"1\"><tr> <td width=\"33.333%\"><b>Song name</b></td> <td width=\"33.333%\"><b>Artist</b></td> <td width=\"33.333%\"><b>Album</b></td> </tr>";

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

echo "<tr> <td><a href=\"play.php?id=" . $row[\'id\'] . "\">" . $row[\'song\'] . "</a></td> <td><a href=\"search_artist.php?search=" . $row[\'band\'] . "\">" . $row[\'band\'] . "</a></td> <td>" . $row[\'album\'] . "</td> </tr>";

  }
echo "</table> <p>This page shows all of the songs in an album.</p>";
?>
';
include "layout/index.php";
?>

 

I would be thankfull of any help. I'm not that good at PHP, I'm only 13 :)

Link to comment
https://forums.phpfreaks.com/topic/203438-mysql-select-in-a-varible/
Share on other sites

Didn't you mean like this?

 

$content = "<table border=\"1\"><tr> <td width=\"33.333%\"><b>Song name</b></td> <td width=\"33.333%\"><b>Artist</b></td> <td width=\"33.333%\"><b>Album</b></td> </tr>";
while($row = mysql_fetch_array($result))  {
  $content .= "<tr> <td><a href='play.php?id={$row['id']}'>{$row['song']}</a></td> <td><a href='search_artist.php?search={$row['band']}'>{$row['band']}</a></td> <td>{$row['album']}</td> </tr>";
}
$content .= "</table> <p>This page shows all of the songs in an album.</p>";

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.