GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Nov-2007, 04:54
juvenile386 juvenile386 is offline
New Member
 
Join Date: Jun 2007
Posts: 28
juvenile386 is an unknown quantity at this point

array variables


Hi! I'd just like to ask a "simple"(but not for me) question....

PHP Code:

while ($myrow = mysql_fetch_row($result)) {



        printf("<tr><td>%s %s</td><td>%s</td></tr>\n",
        $myrow[1], $myrow[2], $myrow[3]);
} 



I'm kinda confused with this variable called $myrow, where do these
$myrow[#] came from? does it only make sense if it was declared as
$myrow[], or $myrow[4]... etc...??

thanks for those who will be glad to help.
  #2  
Old 15-Nov-2007, 09:24
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: array variables


Sure it's for you too, as YOU are asking the question, and not whomever the other person "may be"...

But anyway, the variable $myrow becomes an array, as returned from the function mysql_fetch_row(). The $result is a "result row", returned as an enumerated array, from a known query, so the indexes correspond to the columns in the results.

So, as arrays are zero-indexed, $myrow[0] relates to column0 (the first column) in $result, $myrow[1] to column1 (the second column) in $result, and continues through $myrow[N] to columnN in $result.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 15-Nov-2007, 16:10
juvenile386 juvenile386 is offline
New Member
 
Join Date: Jun 2007
Posts: 28
juvenile386 is an unknown quantity at this point

Re: array variables


problem solved. thanks dude
  #4  
Old 15-Nov-2007, 16:31
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: array variables


Also, take a look at the function: mysql_fetch_array(), as it allows the variable to be indexed with either a number -- as used in the first post, OR the field name itself (case-sensitive, though) within quotes (double or single -- I've seen both used).

There are examples at the link provided, above.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
return string from a function Howard_L C Programming Language 4 18-Aug-2007 00:56
How to sort in C++ alphabetically wilen C++ Forum 5 20-Apr-2007 15:43
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 20:31
Pointer Usage in C++: Beginner to Advanced varunhome C++ Forum 0 19-Aug-2005 10:25
template comiling problems - need expert debugger! crq C++ Forum 1 01-Feb-2005 22:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:24.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.