Page 1 of 1

Need a hand with some code...

Posted: Sun Feb 12, 2006 9:04 pm
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]

Re: Need a hand with some code...

Posted: Sun Feb 12, 2006 9:22 pm
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;

row num for vehicle id num

Posted: Sun Feb 12, 2006 9:28 pm
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);
?>