redarrow Posted March 9, 2007 Share Posted March 9, 2007 Lets exsplain how to use a link to see entrys from a page to another ok. . <?php //database connection $db=mysql_connect("localhost","username","password"); mysql_select_db("database_name",$db); //select statement example ok all book entry's lol. $query1="select * from books "; $result=mysql_query(query1); //while loop to get all the books while($record=myslq_fetch_assoc($result)){ // echo book information ok title price and a link to see that book information. echo" ".$record['book_title']," <br> ".$record['price']." <br> <a href='read_more.php?id=".$record['id']."'>More Info</a><br><br>"; } ?> Now where going to a page read_more.php to view the book information and use the id what is in the link to get the book full information. read_more.php <?php // database connection $db=mysql_connect("localhost","username","password"); mysql_select_db("database_name",$db); //select statement that gets the books from the id in the url. $query1="select * from books where id=".$_GET[ 'id']." "; $result=mysql_query($query1); //read that book we just selected. while($rec=myslq_fetch_assoc($result)){ // echo book information that was selected. echo" ".$rec['book_title']." <br> ".$rec['price']." <br> ".$rec['date_book_was_made']."<br>".$rec['book_description']." <br>"; } ?> now you can see the book that the user selected from a url in the url we use a varable what was the id of the book then we went to a page and looked at the book that was selected from the link. That it ok. Quote Link to comment https://forums.phpfreaks.com/topic/41997-for-new-php-users-only-how-to-get-one-page-entry-to-another-example-ok/ Share on other sites More sharing options...
Rin Posted March 9, 2007 Share Posted March 9, 2007 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/41997-for-new-php-users-only-how-to-get-one-page-entry-to-another-example-ok/#findComment-203635 Share on other sites More sharing options...
illuz1on Posted March 9, 2007 Share Posted March 9, 2007 Hey Whats wrong here? //select statement example ok all book entry's lol. $sql = "SELECT * FROM shops"; $data = mysql_query($sql); while($record = mysql_fetch_assoc($data)) //while loop to get all the books while($record=myslq_fetch_assoc($result)){ $id = $record['id']; $name = $record['name']; $picture = $record['picture']; $rating = $record['rating']; $sdesc = $record['sdesc']; // echo book information ok title price and a link to see that book information. echo ' echo '$id<br>$name<br><a href='read_more.php?id=$id'>More Info</a><br><br>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/41997-for-new-php-users-only-how-to-get-one-page-entry-to-another-example-ok/#findComment-203690 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Hey Whats wrong here? //select statement example ok all book entry's lol. $sql = "SELECT * FROM shops"; $data = mysql_query($sql); while($record = mysql_fetch_assoc($data)) //while loop to get all the books while($record=myslq_fetch_assoc($result)){ $id = $record['id']; $name = $record['name']; $picture = $record['picture']; $rating = $record['rating']; $sdesc = $record['sdesc']; // echo book information ok title price and a link to see that book information. echo ' echo '$id<br>$name<br><a href='read_more.php?id=$id'>More Info</a><br><br>'; } ?> The [ code ] and [ /code ] tags are your friend. What was wrong was you added an extra while loop. Here is how it should look. <?php //select statement example ok all book entry's lol. $sql = "SELECT * FROM shops"; $data = mysql_query($sql); while($record = mysql_fetch_assoc($data)) { $id = $record['id']; $name = $record['name']; $picture = $record['picture']; $rating = $record['rating']; $sdesc = $record['sdesc']; // echo book information ok title price and a link to see that book information. echo $id . $name . "<a href=read_more.php?id=".$id.">More Info[/url]"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/41997-for-new-php-users-only-how-to-get-one-page-entry-to-another-example-ok/#findComment-203693 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.