PHP MySql Select record and display in new window

Ok,

I'm on phase 2 of a project I'm working on and now I need to be able to select a record from my car listing. I have the php setup to read all the records from the database and display them on the screen, but now I need to be able to select a record and display its information in a new window.  I have a link in each record (Check Availability) I was thinking about using to select the record, but I'm still trying to figure out how to go about this. Can anyone help me out? I have attached a screenshot of what the display looks like.
Untitled.jpg
rraymond1130Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
What is the button? Is it a button or a styled anchor tag
If an anchor then just pass the car id into the anchor href
If its a button then change it to an anchor tag
0
Ray PaseurCommented:
Please post the URL of the page.  It will be much more helpful than a picture!
0
rraymond1130Author Commented:
Its a anchor href. And I'm thinking I can use the VIN as the car id. Since each car has its own VIN. How would you format that href?

http://rraymond.com/sandbox/NewCars.php
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

GaryCommented:
When you writing out the car details you must have an id from the database, just append that to your anchor link and in the popup $_GET that value.to do your database call with.
0
Ray PaseurCommented:
You might want to check the validity of the HTML document.
http://validator.w3.org/check?uri=http%3A%2F%2Frraymond.com%2Fsandbox%2FNewCars.php&charset=%28detect+automatically%29&doctype=Inline&group=0

The URL of a single-car-lookup script might have an argument something like this:

<a target="_blank" href="path/to/script.php?vin=ZFBCFADH8EZ009083"><img src="/sandbox/images/ChkAvail.jpg" /></a>

Inside the script, you will find the VIN in $_GET['vin']
0
rraymond1130Author Commented:
OK,

I'm a little confused here. How do I find the database id assigned to the record? So on my CarDetails.php page I would do a $_GET['fieldname']?
0
Ray PaseurCommented:
Let's say you put this kind of link into each car displayed on the NewCars.php page:

<a target="_blank" href="CarDetails.php?vin=ZFBCFADH8EZ009083"><img src="/sandbox/images/ChkAvail.jpg" /></a>


In the PHP script of the CarDetails.php page you will find a variable named $_GET['vin'] and it will contain "ZFBCFADH8EZ009083" which is the VIN for one car.

You can look up the other details about the car by using the VIN in a data base query.  Be sure to use LIMIT 1 when you write the SELECT query to avoid a table scan.
0
rraymond1130Author Commented:
Ok Ray,

Finally I have some time to work on this. I screwed my head on right this morning and figured out the <a target="_blank" href="CarDetails.php?vin=ZFBCFADH8EZ009083"><img src="/sandbox/images/ChkAvail.jpg" /></a>

I am running into a problem with my query. Here is my query:

<?php
$thisVin = $_GET['vin'];
echo $thisVin;
$connection = mysql_connect('localhost', 'username', 'password');
mysql_select_db('my-database');

$query = "Select
vehicles.DriveTrain, vehicles.Transmission, vehicles.Make, vehicles.GenericColorInterior, vehicles.OemModelCode, vehicles.EngineDisplacement, vehicles.EngineSize, vehicles.OEMColorNameExterior, vehicles.VIN, vehicles.StockNumber, vehicles.InternetPrice, vehicles.Mileage, vehicles.VehicleType, vehicles.MSRP, vehicles.Year, vehicles.Body, vehicles.Trim, vehicles.Model, links.PhotoUrls
FROM vehicles, links
WHERE vehicles.VIN = links.VIN AND vehicles.VIN = $thisVin LIMIT 1";
 
$result = mysql_query($query) or die ("bad query '$query' : ".mysql_error()); //Let me know if the query is bad or has syntax errors

?>

Here is my results:

bad query 'Select vehicles.DriveTrain, vehicles.Transmission, vehicles.Make, vehicles.GenericColorInterior, vehicles.OemModelCode, vehicles.EngineDisplacement, vehicles.EngineSize, vehicles.OEMColorNameExterior, vehicles.VIN, vehicles.StockNumber, vehicles.InternetPrice, vehicles.Mileage, vehicles.VehicleType, vehicles.MSRP, vehicles.Year, vehicles.Body, vehicles.Trim, vehicles.Model, links.PhotoUrls FROM vehicles, links WHERE vehicles.VIN = links.VIN AND vehicles.VIN = WDDGF8AB8DR247608 LIMIT 1' : Unknown column 'WDDGF8AB8DR247608' in 'where clause'
0
rraymond1130Author Commented:
I can echo out the value of my variable but the query for some reason doesn't like it..
0
Ray PaseurCommented:
I think it needs quotes around the VIN value.

$query = "Select
vehicles.DriveTrain, vehicles.Transmission, vehicles.Make, vehicles.GenericColorInterior, vehicles.OemModelCode, vehicles.EngineDisplacement, vehicles.EngineSize, vehicles.OEMColorNameExterior, vehicles.VIN, vehicles.StockNumber, vehicles.InternetPrice, vehicles.Mileage, vehicles.VehicleType, vehicles.MSRP, vehicles.Year, vehicles.Body, vehicles.Trim, vehicles.Model, links.PhotoUrls
FROM vehicles, links
WHERE vehicles.VIN = links.VIN AND vehicles.VIN = '$thisVin' LIMIT 1"; 

Open in new window

0
Ray PaseurCommented:
You can also write your query like this.  I find it easier to read and keep organized.  I made a change to the WHERE clause that might be a little more efficient.

$query 
= 
"
SELECT
  vehicles.DriveTrain
, vehicles.Transmission
, vehicles.Make
, vehicles.GenericColorInterior
, vehicles.OemModelCode
, vehicles.EngineDisplacement
, vehicles.EngineSize
, vehicles.OEMColorNameExterior
, vehicles.VIN
, vehicles.StockNumber
, vehicles.InternetPrice
, vehicles.Mileage
, vehicles.VehicleType
, vehicles.MSRP
, vehicles.Year
, vehicles.Body
, vehicles.Trim
, vehicles.Model
, links.PhotoUrls
FROM vehicles, links
WHERE vehicles.VIN = '$thisVin' 
AND   links.VIN    = '$thisVin'
LIMIT 1
"
;

Open in new window

And you need to be careful about using external data in a query.  At the top of the script, you would want to make a change something like this.

<?php
error_reporting(E_ALL);

// CONNECT AND SELECT
$connection = mysql_connect('localhost', 'username', 'password');
mysql_select_db('my-database');

// ESCAPE VARIABLE FOR SAFE USE IN A QUERY
$thisVin = mysql_real_escape_string($_GET['vin']);
echo $thisVin;

Open in new window

And finally, you might want to avoid the use of a variable name containing $this because of the risk that it might be confused with a class property.  $this is a reserved word (pseudo-variable) in PHP.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rraymond1130Author Commented:
Thanks Guys for your help....
0
Ray PaseurCommented:
Thanks for the points! ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.