dark22horse Posted May 7, 2007 Share Posted May 7, 2007 Hi guys I have succesfully selected pictures and text from a database and displayed them in a table. But now I need to be able to click on the picture and then it opens a page with all the details from the databse about it. I know I need to have some code that selects the ID from the databse and then shows the pictures and text. The problem I am having is getting the picture to have the unique ID. any help?? Quote Link to comment https://forums.phpfreaks.com/topic/50378-solved-setting-id/ Share on other sites More sharing options...
MadTechie Posted May 7, 2007 Share Posted May 7, 2007 see here (same idea) if you want someone you do the work for you see here Quote Link to comment https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-247390 Share on other sites More sharing options...
Mutley Posted May 7, 2007 Share Posted May 7, 2007 In your database make a new field called "id" set it as a MEDIUMINT (type) and auto_increment (other), as a Primary Key. Then when you click an image, you can do an 'id' (I'm guessing it lists all the images, so add the 'id' to the query) and display it in the URL of the link that will goto the new page with all the picture information on, like: <a href="info.php?id=<?=$id?> image here </a> On the info.php, you get the 'id' by doing: $id = $_GET['id']; Then make a new query to SELECT all the info WHERE id = '$id' I hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-247395 Share on other sites More sharing options...
dark22horse Posted May 11, 2007 Author Share Posted May 11, 2007 Cheers for the help, a bit late doing this. I have an error, Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\Program Files\xampp\htdocs\site\Cars2.php on line 76 This is the link part, unsure what I have done wrong. That is as far as I can get, I have posted the info.php as well. <? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","root",""); //select which database you want to edit mysql_select_db("car"); //select the table $result = mysql_query("select * from car"); //grab all the content while($r=mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $price=$r["price"]; $description=$r["description"]; $photo=$r["photo"]; $id=$r["id"]; //display the row echo "$price"; echo "$description"; echo "<a href="info.php?id=<?=$id?> image here </a>"; } ?> info.php <? $id = $_GET['id']; mysql_connect("localhost","root",""); mysql_select_db("car"); $result = mysql_query("select * from car WHERE id = '$id'"); while($r=mysql_fetch_array($result)) { $price=$r["price"]; $description=$r["description"]; $photo=$r["photo"]; $id=$r["id"]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-250805 Share on other sites More sharing options...
per1os Posted May 11, 2007 Share Posted May 11, 2007 echo "<a href="info.php?id=<?=$id?> image here </a>"; should be echo '<a href="info.php?id=' . $id . '"> image here </a>'; Quote Link to comment https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-250807 Share on other sites More sharing options...
dark22horse Posted May 11, 2007 Author Share Posted May 11, 2007 Cheers for that, I know have it linking to the the info.php But now that isnt working. <? $id = $_GET['id']; mysql_connect("localhost","root",""); mysql_select_db("car"); $result = mysql_query("select * from car WHERE id = '$id'"); while($r=mysql_fetch_array($result)) { $price=$r["price"]; $description=$r["description"]; $photo=$r["photo"]; $id=$r["id"]; } ?> This time I dont get an error, but it doesnt show anythign. Quote Link to comment https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-250823 Share on other sites More sharing options...
per1os Posted May 11, 2007 Share Posted May 11, 2007 Time for some debugging. $result = mysql_query("select * from car WHERE id = '$id'") or DIE(mysql_error()); Also I do not see where you are echoing anything to the screen, am I blind? Quote Link to comment https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-250827 Share on other sites More sharing options...
MadTechie Posted May 11, 2007 Share Posted May 11, 2007 you see nothing cos you printed nothing.. Quote Link to comment https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-250833 Share on other sites More sharing options...
dark22horse Posted May 11, 2007 Author Share Posted May 11, 2007 Yeah sorry guys, didn't paste the whole echo. It works now, cheers for all the help. This forum is quality!!!! Quote Link to comment https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-250840 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.