p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Unable to assign $row[ ] array contents to a variable


Message #1 by "Trey Carroll" <treycarroll@y...> on Thu, 12 Sep 2002 16:41:00
Once I get the $row using mysql_fetch_row I can display the contents but I 
cannot assign them to a variable.


CODE:
$query = "SELECT report_preference FROM customer WHERE               
user_name='$user_name'";

echo "query= $query";
			
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
   {
    $report_preference = $row[0];
    echo "rep pref = $report_prefence";
    echo "row0=".$row[0];						
   }

OUTPUT (The Correct contents should be 'form':
     query= SELECT report_preference FROM customer WHERE user_name='treyc'
     rep pref = 
     row0=form

Any help would be greatly appreciated.

I have about a dozen of these just like this on my site that are working 
fine.  I'm not seeing the problem here.
Message #2 by "Pedro" <ufhbiqwj001@s...> on Thu, 12 Sep 2002 17:35:25 +0200
you have a typo

while($row = mysql_fetch_row($result))
   {
    $report_preference = $row[0];
    echo "rep pref = $report_prefence";

***                          ^^^^^^^^ should be preference

    echo "row0=".$row[0];						
   }


> -----Original Message-----
> Once I get the $row using mysql_fetch_row I can display the 
> contents but I 
> cannot assign them to a variable.

Message #3 by "Trey Carroll" <treycarroll@y...> on Thu, 12 Sep 2002 17:47:06
A thousand apologies.  ...Really thought I had looked it over 
thoroughly.   Thanks for your help.

> you have a typo

while($row = mysql_fetch_row($result))
   {
    $report_preference = $row[0];
    echo "rep pref = $report_prefence";

***                          ^^^^^^^^ should be preference

    echo "row0=".$row[0];						
   }


> -----Original Message-----
> Once I get the $row using mysql_fetch_row I can display the 
> contents but I 
> cannot assign them to a variable.

Message #4 by "Pedro" <ufhbiqwj001@s...> on Thu, 12 Sep 2002 19:08:55 +0200
no need to apologize

as my grandfather used to say:
  four eyes see more (but not necessarily better) than two

well, ... ... he really used to say:
  "two heads think more (but not necessarily better) than one"


Happy coding!

> -----Original Message-----
> A thousand apologies.  ...Really thought I had looked it over 
> thoroughly.   Thanks for your help.


  Return to Index