MySQL selects only one data?

advertisements

I am trying to figure out a solution on how I am going to display my data from the database. However I want to to show one specific entry. Here is my database design:

I am using PHP to connect it with a website. On the website I would like it to display from the story table: "This is a book about the internet!" Only that nothing else only that specific entry. The book_number is a primary key and is auto incremented.

Here is my current code:

<?php
// Change variables if going to a server.
$username = "root";
$password = "";
$hostname = "localhost";

//connect
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";

//Select book database.
$selected = mysql_select_db("book",$dbhandle)
  or die("Could not select examples");

  //select all the records from the book database
$result = mysql_query("SELECT book_name, story, time_track FROM book");
//fetch data
while ($row = mysql_fetch_array($result)) {
   echo "ID:".$row{'book_name'}." Name:".$row{'story'}."
   ".$row{'time_track'}."<br>";
}

//close
mysql_close($dbhandle);

?>

My current code connects and displays all entry's I would like it to display as specified above.

Also I would like it to display one entry at a time from story table since I will be making more then one books and the story will be divided for multiple pages.


You need to filter your records through SQL Like this:

$book_number = $_GET['book_number'];
$result = mysql_query("SELECT book_name, story, time_track FROM book
WHERE book_number = '$book_number'
");

You can pass this book_number variable through URL (GET) with/without encryption.

It is better to encrypt variables while sending them on URLs.