Jump to content

PHP help


girl

Recommended Posts

Hello people.Happy New Year.I started new year with learning php, but there is something I need, but still don know. I have a table in database with records, and I want to have links in a page: link 1link 2...link n when I click on link 1, it selects and outputs the record with id1, link 2-with id 2 and so on.Will you please advice me a way to do it.Thanks for advance.

Link to comment
Share on other sites

HAPPY NEW YEAR GIRL tableid, title, subject 1. show id as linkHere how to with databasehttp://www.w3schools...ysql_select.asp in file menu.phpwho link by code... echo '<a href="page.php?id='. $row['id'] .'">'.$row['title'].'</a>'; 2. after clicked php will accept with GEThttp://www.w3schools...php/php_get.asp in file page.php sql string...'select * from your_table_name where id='.$_GET['id'] and show record... echo '<p>'.$row['title'].'<br/>'; echo '<p>'.$row['subject'].'<br/>';

Edited by kanchatchai
Link to comment
Share on other sites

Thank You very much.You know I have tried it, but I don know why when in menu.php I write echo '<a href="page.php?id='. $row['id'] .'">'.$row['title'].'</a>';it echoes only the first record of database, though I have a lot there.

Link to comment
Share on other sites

Post your code please.

Link to comment
Share on other sites

OK, here t is:menu.php <form action="page.php" method="get"> <?php include ("connect-db.php"); session_start(); mysql_select_db("db-name", $con); $id=mysql_query("SELECT * FROM tour_programs") or die($id."<br/><br/>".mysql_error() ); $row= mysql_fetch_array($id); echo '<a href="page.php?id='. $row['id'] .'">'.$row['tour_name'].'</a>'; echo "</br>"; ?> </form> page.php <?phpinclude ("connect-db.php");mysql_select_db("db-name", $con); $var=mysql_query("SELECT * FROM tour_programs where id='".$_GET["id"]."' ");$row= mysql_fetch_array($var);if($var === FALSE) { die(mysql_error()); // TODO: better error handling}echo '<p>'.$row['tour_name'].'<br/>';echo '<p>'.$row['description'].'<br/>'; ?>

Link to comment
Share on other sites

you need to loop through (eg while loop) the mysql result set to get all the data. now it is just showing the first results. please check the tutorials regarding this. there is example of it. also in page.php you need to check the $var before you use it otherwise it will show errors anyway.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...