Fetech a value from a array?

here is a problem i keep running into i do a simple sql query to get soem values from my database..

exp:
$vincheck = "select * from vin where vin = $_POST[vin]";
$check_result = mysql_query($vincheck,$conn) or die(mysql_error());

i then access this information like this
  $temp = mysql_fetch_row($check_result);
  $_SESSION[customer_id] = $temp[5];

This works fine but what i really want, is instead of using $temp[5] i want it to be the vale from the table so it's easier to understand and also not depedant on the table structure.

so i tried replacing $temp[5] with $temp[currentownerID] and i can never get this to work..

currentownerID is the 6th row in the table (rember counting starts at 0)

-Thanks in advance for any help-
LVL 2
mightofnightAsked:
Who is Participating?
 
suresh_aspConnect With a Mentor Commented:
Try this,

mysql_fetch_array returns an array of single record/row only

to get more rows

$detail_report = "";

while($temp = mysql_fetch_array($check_result))
{
$detail_report .= "<br>checkvin temp= ".$temp["currentownerID"]."";
}

echo $detail_report;
0
 
ZylochCommented:
Do this:

$temp = mysql_fetch_assoc($check_result);
$_SESSION[customer_id] = $temp["currentowernID"];
0
 
mightofnightAuthor Commented:
i had tried that and it doesn't work :( i have done it in both single and double quotes just to make sure.  I even copied and pasted the name of the record from phpmyadmin just to make sure i was spelling it right.
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
ZylochCommented:
What about:

$_SESSION["customer_id"] = $temp["currentowernID"];
0
 
suresh_aspCommented:
Try this

$temp = mysql_fetch_array($check_result);
$_SESSION["customer_id"] = $temp["currentownerID"];
0
 
suresh_aspCommented:
Note: with mysql_fetch_array

you can access element in array both ways

$temp[0] or $temp['currentownerID']
0
 
mightofnightAuthor Commented:
$detail_report .= "<br>checkvin temp= ".$temp[5]."";
$detail_report .= "<br>checkvin temp= ".$temp["currentownerID"]."";
$detail_report .= "<br>checkvin temp= ".$temp[currentownerID]."";
$detail_report .= "<br>checkvin temp= ".$temp['currentownerID']."";
echo $detail_report

gives me this

checkvin temp= 1
checkvin temp=
checkvin temp=
checkvin temp=

i couldn't get any of the other stuff to function right
0
 
mightofnightAuthor Commented:
suresh_asp - i am retring give me a couple..
0
 
mightofnightAuthor Commented:
ok so that worked.. so your saying that only works with the fetch_array and not the fetch row?
0
 
mightofnightAuthor Commented:
and then what will happen if there are multiple of rows in the array?
0
 
RoonaanCommented:
how would there be "multiple rows in the array" ?

You can build your own array offcourse:
$s = array();
$s['a'] = array(1,2,3,4,5);
$s['b'] = array('a','b','c','d');
print_r($s);

But better would be just to read the manual on arrays...

Regards

-r-
0
 
mkortlevenCommented:
Is your column name in the same case? MySQL table and column names are case-sensitive.
Try
    print_r($temp);
Then you can see the column names.

Marc
0
 
virmaiorCommented:
quite possibly not the source of your problem but these two lines have bad syntax...

$vincheck = "select * from vin where vin = $_POST[vin]";
and
$_SESSION[customer_id] = $temp[5];

you shouldn't use $_POST[vin]
it should be $_POST['vin']

so the lines become:

$vincheck = 'SELECT * FROM vin WHERE vin = ' . $_POST['vin'];

and

$_SESSION['customer_id'] = $temp[5];

respectively...

the php website has a long explanation of how you shouldn't assume that [*] will be interpreting * as a string literal

0
 
mightofnightAuthor Commented:
Thaks for all the help guys! You really helped clearify things for me!

-Travis
0
All Courses

From novice to tech pro — start learning today.