php/mysql search display - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

php/mysql search display

mstrlouismstrlouis Posts: 3Member
I am trying to link one variable in the search results to its corresponding variable which is in the same row but on a different field result.

For Example
[b]title || lyrics[/b]
father || am i so proud to be your son...

If I search for father, I get father in the search results.

I am trying to get the title "father" to be displayed as a link so that when it is clicked, the lyrics: "I am so proud to be your son" will be displayed on screen. It can either be a pop up window or a new screen.

I tried linking the title to the lyrics with...

[code]'.$title.'[/code]

in the part of my script that prints the search results. The value if id was assigned to variable id like this

[code]$id=$_GET['id'][/code]

it takes me to a page with no results. Please help...


This is my script...

[code]<?php>
//-query the database table
$song="SELECT title,writers.Author,bible.ref,lyrics FROM writers LEFT JOIN bible ON writers.SongNo = bible.SongNo WHERE (`title` LIKE '%" . $name . "%' OR `Author` LIKE '%" . $name . "%')";


//-run the query against the mysql query function
$result=mysql_query($song);

//-create while loop and loop through result set
$num_rows = mysql_num_rows($result);

echo "
";
echo "

Search for '$name' found $num_rows
Results...

";


while($row=mysql_fetch_array($result)){
$Author =$row['Author'];
$lyrics=$row['lyrics'];
$title=$row['title'];
$SongNo=$row['SongNo'];
$ref=$row['ref'];
$rest = substr("$lyrics",0,180);
//-display the result of the array
$id=$_GET['id'];

if($num_rows==0){
echo "Sorry, search found zero results."; //if there are zero rows, then it will echo this out.
} else {
print '

Song title : '.$title.'
';
print "Author: $Author
" . "Reference: $ref
" . "Lyrics: $rest

";
}
}
}
else{
echo "

Please enter search term, we suggest the name of an author or a song title


";



}
}
}
?>[/code]

Sign In or Register to comment.