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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.