0

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
title || lyrics
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 directly in the part of my script that prints the search results, it sort of works but it gives me a message: forbidden... You don't have permission to access.....[my server dir]..."the lyrics from the title displayed here"...on this server.

This is my script...

<?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 "<hr>";
			echo "<h4 align='right'> Search for '$name' found $num_rows\n Results...</h4>";
			
				
				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 
								
		       	if($num_rows==0){
					echo "Sorry, search found zero results.";  //if there are zero rows, then it will echo this out. 
				} else {
					print '<p class="sansserif"><b>Song title : </b> <a href="'.$lyrics.'">'.$title.'</a><br />';
					print "<b>Author</b>: $Author <br />" . "<b>Reference</b>: $ref <br />" . "<b>Lyrics</b>: $rest</p>";				
					} 
				}
					} 
					else{ 
					echo  "<p><b>Please enter search term, we suggest the name of an author or a song title</p></b><hr/>";



					} 
				} 
			} 
?>
2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by cwarn23
0

print '<p class="sansserif"><b>Song title : </b> <a href="'.$lyrics.'">'.$title.'</a><br />';

That line is incorrect and you will need to use something like the following if you haven't got a .htaccess file:

print '<p class="sansserif"><b>Song title : </b> <a href="index.php?id='.$title.'">'.$title.'</a><br />';

The above code assumes your code is in index.php and to retrieve the title in the url, use the variable $_GET

0

Please can you clarify, how & where exactly can I use the $_GET in my script? am kind of new at this...

Edited by mstrlouis: n/a

0

Well $_GET is basically a url variable. So those variables you see in the url after the question mark can the retrieved with $_GET and are treated like regular variables. I hope that explained it. Perhaps a google search will help too.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.