Jump to content

[SOLVED] I want to view a specific result


pcbguy

Recommended Posts

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>'";
}
?>

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
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.