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
https://forums.phpfreaks.com/topic/80016-solved-i-want-to-view-a-specific-result/
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?

 

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.