Jump to content

Recommended Posts

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??

Link to comment
https://forums.phpfreaks.com/topic/50378-solved-setting-id/
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-247395
Share on other sites

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"];

?>

Link to comment
https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-250805
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/50378-solved-setting-id/#findComment-250823
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.