TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 08-30-2009, 05:36 PM   #1 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default While loop is over my head

Hi,

The WHILE and FOREACH loops below are elementary, yet how they work keeps evading my mental grasp. Here is a UDF:

PHP Code:
$c_pettype "horse" ;
 
 function 
getpets($c_pettype)
 {
 
  
$q "SELECT *
       FROM t_petdata
         WHERE pettype = '
$c_pettype'" ;
          
 
$result mysql_query($q) or die ('bad query') ;

 
$j ;

 [
color="Red"]while($row mysql_fetch_assoc($result))[/color]
 { 
     [
color="Red"]foreach($row as $key => $value)[/color]
     {
         
$array[$j][$key] = $value ;
     }
                
     return 
$array ;
 }
 

So, I get the arrays, and the general concept of looping, etc., but the concepts of "WHILE($row = ...)" and "FOREACH($row as...) are not clear to me. I mean, where does "$row" come from?

Is there a way to help me understand this on a simple level?

Thanks!

Dave

Last edited by codefreek : 09-01-2009 at 05:32 PM. Reason: php tags added, please read note, Thank you!
Dave is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested while loop needed for this? gtifllm General 1 08-17-2009 07:50 PM
Horizontal nested loop problem Dracula General 3 06-05-2008 03:12 PM
Another quetion - Loop inside a loop Jmz General 1 05-30-2008 09:07 PM
Need help on nested loop! pabin Absolute Beginners 4 05-12-2008 10:27 AM
Best Way To Loop In A Table? StevenF Absolute Beginners 16 03-14-2008 04:26 PM


All times are GMT. The time now is 09:43 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design