johnwayne77 Posted February 3, 2007 Share Posted February 3, 2007 i connect to the db: mysql_connect("localhost", "admin", "pass") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); now, i have a table called: 'shipment' with three fields: tracking name address I keep the tracking (which is unique) in a cookie for later use -- so I can do this : $tracking = $_COOKIE['tracking']; $check = mysql_query("SELECT * FROM shipment WHERE tracking = '$tracking'")or die(mysql_error()); Now, my problem is that I need to echo the name and address for tracking and I don't know how. How do I do that? Any Ideas?. Link to comment https://forums.phpfreaks.com/topic/36938-solved-how-do-i-fetch-data-from-mysql-table/ Share on other sites More sharing options...
wildteen88 Posted February 3, 2007 Share Posted February 3, 2007 Now loop through the result set with a while loop: while($row = mysql_fetch_assoc($check)) { echo $row['name'] . ' - ' . $row['address'] . ' - ' . $row['tracking'] . "<br />"; } Link to comment https://forums.phpfreaks.com/topic/36938-solved-how-do-i-fetch-data-from-mysql-table/#findComment-176237 Share on other sites More sharing options...
Orio Posted February 3, 2007 Share Posted February 3, 2007 Read some basic php-mysql tutorials.... <?php $check = mysql_query("SELECT * FROM shipment WHERE tracking = '$tracking'")or die(mysql_error()); $row = mysql_fetch_array($check); echo $row['name']." Lives in ".$row['address']; ?> @wildteen88- You're faster But no need for a loop, "tracking" is unique. Orio. Link to comment https://forums.phpfreaks.com/topic/36938-solved-how-do-i-fetch-data-from-mysql-table/#findComment-176238 Share on other sites More sharing options...
ldsmike88 Posted February 3, 2007 Share Posted February 3, 2007 You have to put the query into an array like so: $shipment = mysql_fetch_array($check); then to display the rest you would do echo it like this: echo $shipment['name']; or echo $shipment['address']; I hope this helps! Link to comment https://forums.phpfreaks.com/topic/36938-solved-how-do-i-fetch-data-from-mysql-table/#findComment-176240 Share on other sites More sharing options...
johnwayne77 Posted February 3, 2007 Author Share Posted February 3, 2007 thanks for the solution mmmyeah, I guess basic mysql knowledge ... gotta read more cheers~ Link to comment https://forums.phpfreaks.com/topic/36938-solved-how-do-i-fetch-data-from-mysql-table/#findComment-176241 Share on other sites More sharing options...
wildteen88 Posted February 3, 2007 Share Posted February 3, 2007 Didn't see the where clause in the query there Orio. I thought it was just a normal Select all from table. I quickly read the post properly. Link to comment https://forums.phpfreaks.com/topic/36938-solved-how-do-i-fetch-data-from-mysql-table/#findComment-176242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.