2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by cossay
0

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>";




?>

Edited by cossay: n/a

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.