pcbguy Posted December 3, 2007 Share Posted December 3, 2007 I have this code that shows all the entries in my database with the picture. I want to be able to select a specific entry from the database to display. I have the "position" column set to be the primary key. How can I change this to work? Thanks. <?php //Connects to your database include "connect.php"; //Retrieves data from MySQL $data=mysql_query("SELECT * FROM for_sale")or die(mysql_error()); //Puts it into an array while($info=mysql_fetch_array($data)) { //Outputs the image and other data Echo"<img src=http://www.mysite.net/images/".$info['picture']."><br>"; Echo"<b>Position:</b>".$info['position']."<br>'"; Echo"<b>Year:</b>".$info['year']."<br>'"; Echo"<b>Make:</b>".$info['make']."<br>'"; Echo"<b>Model:</b>".$info['model']."<br>'"; Echo"<b>Price:</b>".$info['price']."<br>'"; Echo"<b>Description:</b>".$info['description']."<hr>'"; } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted December 3, 2007 Share Posted December 3, 2007 Easiest way is to create a URL for each Row, include that Position (id) as link.php?id=$info. Then have a new page with $_GET['id'] which reads that URL, gets the id in $info and you can just display that one. Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted December 3, 2007 Share Posted December 3, 2007 Change your SQL query $data=mysql_query("SELECT picture,position FROM for_sale")or die(mysql_error()); You can choose whichever ones you want to SELECT Quote Link to comment Share on other sites More sharing options...
pcbguy Posted December 3, 2007 Author Share Posted December 3, 2007 So Change your SQL query $data=mysql_query("SELECT picture,position FROM for_sale")or die(mysql_error()); You can choose whichever ones you want to SELECT So if I change it to 'position' I can select the position number and it will only call that one result? Quote Link to comment Share on other sites More sharing options...
pcbguy Posted December 3, 2007 Author Share Posted December 3, 2007 Okay. I changed it to: $data=mysql_query("SELECT position FROM for_sale")or die(mysql_error()); But now the picture doesn't display and the rest of the info does. Do I have to add something after the web address? Quote Link to comment Share on other sites More sharing options...
pcbguy Posted December 3, 2007 Author Share Posted December 3, 2007 Easiest way is to create a URL for each Row, include that Position (id) as link.php?id=$info. Then have a new page with $_GET['id'] which reads that URL, gets the id in $info and you can just display that one. Not sure how to do this. I am a definite newby. Could you expand? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 3, 2007 Share Posted December 3, 2007 Thats because the SELECT position means you are only grabbing the position data and not the rest. You want to SELECT * FROM for_sale WHERE position = $info But that wont work until you set the Varialble $info, which you can do with $_GET Quote Link to comment Share on other sites More sharing options...
pcbguy Posted December 3, 2007 Author Share Posted December 3, 2007 Okay. It is starting to make sense. Thanks for your help. I'm sure I will have another question. I set the $info at the top with $_GET, right? Quote Link to comment Share on other sites More sharing options...
pcbguy Posted December 3, 2007 Author Share Posted December 3, 2007 could I just set position=991 if I only wanted that entry to appear? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 3, 2007 Share Posted December 3, 2007 Give it a try Quote Link to comment Share on other sites More sharing options...
pcbguy Posted December 3, 2007 Author Share Posted December 3, 2007 It worked. Outstanding. You are my hero. Thanks for the help. Now I can move onto the next phase. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 3, 2007 Share Posted December 3, 2007 No problem. If you want to make a page full of Links that point to each record, then you'll want to use a $_GET function. Also, don't forget to mark the Topic as Solved. Quote Link to comment Share on other sites More sharing options...
pcbguy Posted December 3, 2007 Author Share Posted December 3, 2007 Okay. Still not sure about the $_GET. Can you give an example? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 3, 2007 Share Posted December 3, 2007 Check out Wildteen's post here http://www.phpfreaks.com/forums/index.php/topic,169952.msg750668.html#msg750668 Quote Link to comment Share on other sites More sharing options...
pcbguy Posted December 3, 2007 Author Share Posted December 3, 2007 Thanks again. Quote Link to comment 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.