Jump to content

help with my coding for search output?


kelseyirene

Recommended Posts

Hi! I have a question about my coding for this. I have two separate files. The first is a search from where I search an author's last name, and the second is a php file that outputs the author first and last name, photo, and other titles by that are all stored in my database. The code seems to mostly work fine except for one problem: it outputs the number of times equal with the number of titles stores under the author's name. So, for Roberto Bolano, it outputs five times because there are five titles. Is there anyway I can make the code repeat the query only once?

 

<?
include("connect.php");

$search=$_POST['search'];

$query = mysql_query("SELECT * FROM TitleInfo WHERE author_last LIKE '%$search%' LIMIT 0, 50") or trigger_error (mysql_error());

while ($row = @mysql_fetch_array($query))
{
$var3=$row["author_first"];
$var4=$row["author_last"];

echo "<h1>";
echo $var3;
echo " ";
echo $var4;
echo "</h1>";
echo "<br><br>";
echo "<img src='images/$search.jpg' border=1>";
echo "<br><br>";
echo "Other titles by:<br>";

$sql = mysql_query("SELECT * FROM TitleInfo WHERE author_last LIKE '%$search%'") or trigger_error (mysql_error());

while($r=mysql_fetch_array($sql))
{
    $v1=$r["title"];
    echo $v1;
    echo "<br>";
}
}
?>

 

thank you so so much!

Link to comment
https://forums.phpfreaks.com/topic/184815-help-with-my-coding-for-search-output/
Share on other sites

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.