Need a hand with some code...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
remo9999
Forum Newbie
Posts: 1
Joined: Sun Feb 12, 2006 8:58 pm
Contact:

Need a hand with some code...

Post by remo9999 »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I'm by no means a PHP coder.  I'm just a recycled Clipperhead...  I AM, however, working on a program to pull information from a database for owners of Mitsubishi 3000GT/Dodge Stealth autos... 

This is working just fine... 

What I'm trying to do, however, is ferret out the row number for a specific VIN number, matching this criteria...

Code: Select all

$query ="SELECT * from carinfo where modelyear='$lmodelyear' AND submodel='$lsubmodel' AND interior='$linterior' AND exterior='$lexterior' AND opton='$lopton' AND modelcode='$lmodelcode' AND class='$lclass'";
$result1 = mysql_query($query)
or die ("couldn't execute query");


while($row = mysql_fetch_array($result1))
{
$counter=$counter+1;
extract($row);
}
$exactlyidentical=$counter;

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Need a hand with some code...

Post by Benjamin »

remo9999 wrote: $query ="SELECT * from carinfo where modelyear='$lmodelyear' AND submodel='$lsubmodel' AND interior='$linterior' AND exterior='$lexterior' AND opton='$lopton' AND modelcode='$lmodelcode' AND class='$lclass'";
$result1 = mysql_query($query)
or die ("couldn't execute query");


while($row = mysql_fetch_array($result1))
{
$counter=$counter+1;
extract($row);
}
$exactlyidentical=$counter;
I don't know what your question is but if the query is failing it might be because you are missing backticks and your variables are not being rendered. I changed it as follows.

Code: Select all

$query ="SELECT * from `carinfo` where `modelyear`='" . $lmodelyear . "' AND `submodel`='" . $lsubmodel . "' AND `interior`='" . $linterior . "' AND `exterior`='" . $lexterior . "' AND `opton`='" . $lopton . "' AND `modelcode`='" . $lmodelcode . "' AND `class`='" . $lclass . "'";
$result1 = mysql_query($query)
or die ("couldn't execute query");


while($row = mysql_fetch_array($result1))
{
$counter=$counter+1;
extract($row);
}
$exactlyidentical=$counter;
Last edited by Benjamin on Sun Feb 12, 2006 9:47 pm, edited 2 times in total.
VmusicV
Forum Newbie
Posts: 23
Joined: Sun Jun 15, 2003 10:45 pm
Location: Columbus

row num for vehicle id num

Post by VmusicV »

Hi,
If you explained what your data structure is (vehicle or auto table has what colulmns), that might make it easier to help.
If you A)know the VIN and b) The VIN is one of the columns, why wouldn't you use it in your query? WHERE vin='$requested_vin' obviously most people don't walk around knowing their VIN

when you retrieve a row from the mysql_fetch_array, you get an associative array - depending how you call mysql_query you can reference that associative array a couple of ways

$column_1 = $row[0];
$column_2 = $row[1];
$column_3 = $row[3]; ///// you see this way, you have to KNOW what the columns are

--- or ---------
$veh_make = $row['veh_make']; /// here you reference the column name
$veh_model = $row['veh_model'];

see the example below

Code: Select all

<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
   die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
   printf("ID: %s  Name: %s", $row["id"], $row["name"]);
}

mysql_free_result($result);
?>
Post Reply