eugene2009 Posted November 17, 2009 Share Posted November 17, 2009 Hey so if i have a table with all the rows numbered with a customerid. Say I wanted to fetch each row on a seperate page with a get method. how will I be able to do that? for instance i have rows with customer information. how will I be able to display them on seperate pages. ?customerid=343 and from there it will show all that customers information in a table. Im not sure how to explain this. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/181829-solved-fetching-row-with-get-method/ Share on other sites More sharing options...
ngreenwood6 Posted November 17, 2009 Share Posted November 17, 2009 yes you can get the records by doing that. You would create a page customer_records.php(whatever you want). Then when the user visits that page you pass it there customerid so it would look like customer_records.php?id=12345. Then on that page you would do something like this: <?php $id = $_GET['id']; //gets the id from url $query = "SELECT * FROM table WHERE id='$id'"; //select records with passed id mysql_query($query); //perform query Then you can do whatever you want with the data. Quote Link to comment https://forums.phpfreaks.com/topic/181829-solved-fetching-row-with-get-method/#findComment-958915 Share on other sites More sharing options...
eugene2009 Posted November 17, 2009 Author Share Posted November 17, 2009 thank you so much.. and another question.. say the previous page "customer_list.php" lists all the names of the customers. when you click on one of the names it will take them to customer_records.php well how exactly can I link all the names with the proper id's ? thank you for the help Quote Link to comment https://forums.phpfreaks.com/topic/181829-solved-fetching-row-with-get-method/#findComment-958918 Share on other sites More sharing options...
ngreenwood6 Posted November 17, 2009 Share Posted November 17, 2009 Kind of the same way but you would get the customer list. So it would be something like this: <?php $query = "SELECT * FROM customer_list"; //get the customer list $result = mysql_query($query); //perform the query //display the customer list while($row = mysql_fetch_array($result)){ echo '<a href="customer_records.php?id='.$row['customer_id'].'">'.$row['customer_name'].'</a>'; //create a link with the customers id as the $_GET['id'] } So pretty much all you are doing is appending the customers id to the end of the url that you are taking them to. Hopefully that helps. Quote Link to comment https://forums.phpfreaks.com/topic/181829-solved-fetching-row-with-get-method/#findComment-958927 Share on other sites More sharing options...
eugene2009 Posted November 17, 2009 Author Share Posted November 17, 2009 i ran into a problem... Just a quick narrowed down example.. $query = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($db_name); $id = $_GET['id']; //gets the id from url $query = "SELECT * FROM comments WHERE id='$id'"; //select records with passed id $result = mysql_query($query); //perform the query $row = mysql_fetch_row($result); echo 'The customers name is, '.$row['name'].' and he made a purchase on, '.$row['date'].'.<BR>'; ?> What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/181829-solved-fetching-row-with-get-method/#findComment-958973 Share on other sites More sharing options...
ngreenwood6 Posted November 17, 2009 Share Posted November 17, 2009 Your first line is assigning mysql_connect to $query. What is or isnt happening. Also try this: mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($db_name); $id = $_GET['id']; //gets the id from url $query = "SELECT * FROM comments WHERE id='$id'"; //select records with passed id $result = mysql_query($query); //perform the query $row = mysql_fetch_assoc($result); echo 'The customers name is, '.$row['name'].' and he made a purchase on, '.$row['date'].'.<BR>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181829-solved-fetching-row-with-get-method/#findComment-959552 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.