Hi , i'm trying to add a hyperlink in the php code , the "href" of the hyperlink is the books names generated from the db but i want to the clicked link to show the relative book description and the book's image in another page but i don't know how to get and passes the clicked book's name to another to make a sql statement that generate relative description .

Assume the name of your database is books and that it contains a table called book with the following field names book_id, title, description, picture.
The most important part of the code is in bold

Here is the code for the first page called books.php

<?php
$connection = mysql_pconnect("localhost", "root", "man") or die("Connection failed. ".mysql_error());
mysql_select_db("books") or die("Unable to select database.".mysql_error());

//Fetch books from the book tables
$query = "SELECT * FROM book";
$result = mysql_query($query) or die("Unable to process query. ".mysql_error());

//Display books as list
echo "LIST OF BOOKS AVAILABLE";
echo "<ol>";
	while($mybooks = mysql_fetch_object($result))
	{
		echo "<li>[B]<a href = 'description_page.php?book=".urlencode($mybooks->book_id)."'>$mybooks->title</a>[/B]</li>";
	}
echo "</ol>";

?>

The code for the second page, description_page.php is shown below

<?php
$connection = mysql_pconnect("localhost", "root", "man") or die("Connection failed. ".mysql_error());
mysql_select_db("books") or die("Unable to select database.".mysql_error());

echo "BOOk DESCRIPTION<br>";
//Now the value you passed from the other page is contained in $_GET['book']
//Now you can use this value to query your database for any information about 
//the books in your database as follows
$id = $_GET['book'];
$query = "SELECT * FROM book WHERE book_id = '$id' LIMIT 1";
$result = mysql_query($query) or die("Error processing query. ".mysql_error());
$book_returned = mysql_fetch_object($result);
echo "<table width = '400' border = '1'>";
	echo "<tr>";
		echo "<td colspan = '2'>".$book_returned->title."</td>";
	echo "</tr>";
	echo "<tr>";
		echo "<td>".$book_returned->picture."</td>";
		echo "<td>".$book_returned->description."</td>";
	echo "</tr>";
echo "</table>";




?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.