Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Fetech a value from a array?

Posted on 2004-10-28
14
Medium Priority
?
207 Views
Last Modified: 2006-11-17
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
Comment
Question by:mightofnight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +3
14 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 12441176
Do this:

$temp = mysql_fetch_assoc($check_result);
$_SESSION[customer_id] = $temp["currentowernID"];
0
 
LVL 2

Author Comment

by:mightofnight
ID: 12441204
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
 
LVL 36

Expert Comment

by:Zyloch
ID: 12441230
What about:

$_SESSION["customer_id"] = $temp["currentowernID"];
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Expert Comment

by:suresh_asp
ID: 12441272
Try this

$temp = mysql_fetch_array($check_result);
$_SESSION["customer_id"] = $temp["currentownerID"];
0
 
LVL 2

Expert Comment

by:suresh_asp
ID: 12441283
Note: with mysql_fetch_array

you can access element in array both ways

$temp[0] or $temp['currentownerID']
0
 
LVL 2

Author Comment

by:mightofnight
ID: 12441293
$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
 
LVL 2

Author Comment

by:mightofnight
ID: 12441300
suresh_asp - i am retring give me a couple..
0
 
LVL 2

Author Comment

by:mightofnight
ID: 12441313
ok so that worked.. so your saying that only works with the fetch_array and not the fetch row?
0
 
LVL 2

Author Comment

by:mightofnight
ID: 12441320
and then what will happen if there are multiple of rows in the array?
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 12441531
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
 

Expert Comment

by:mkortleven
ID: 12442235
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
 
LVL 2

Accepted Solution

by:
suresh_asp earned 1000 total points
ID: 12442622
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
 
LVL 20

Expert Comment

by:virmaior
ID: 12443999
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
 
LVL 2

Author Comment

by:mightofnight
ID: 12452847
Thaks for all the help guys! You really helped clearify things for me!

-Travis
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question