• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

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-
0
mightofnight
Asked:
mightofnight
  • 6
  • 3
  • 2
  • +3
1 Solution
 
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
 
ZylochCommented:
What about:

$_SESSION["customer_id"] = $temp["currentowernID"];
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
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
 
suresh_aspCommented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 6
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now