TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   newbie - what does this code mean? (http://www.talkphp.com/absolute-beginners/2533-newbie-what-does-code-mean.html)

djscour 03-27-2008 08:18 PM

newbie - what does this code mean?
 
Hi,

Warning I'm a total newbie at both php and any type of coding at all. I was hoping someone could explain a line of code in a for loop for a php/mysql tutorial that I I've been trying to do. The following is the loop:

for ($i=0; $i< $nRows; $i++){


$row = mysql_fetch_array($qResult);


$rString .="&ID".$i."=".$row['ID']."&visitor".$i."=".$row['visitor']."&time".$i."=".$row['time']."&comment".$i."=".$row['comment'];
}


echo $rString."&";

The part I don't fully grasp is:

$rString .="&ID".$i."=".$row['ID']."&visitor".$i."=".$row['visitor']."&time".$i."=".$row['time']."&comment".$i."=".$row['comment'];
}


My guess is this formats the output and calls the variables that will display in the echo $rString."&"; I guess what I don't understand is partially syntax related. I understand that the stuff with $ in it are variables and the stuff in the [ ] refers to items in the array but I don't understand what the stuff with the ampersand is doing. Also why does the = sign have to be in quotes? Thanks.

djscour

flyingbuddha 03-28-2008 01:55 PM

Hey djscour,

Wow, that lines a bit of a mouthful isn't it, you could do with breaking it down if you're struggling
PHP Code:

// &ID1 = x
$rString.= "&ID".$i."=".$row['ID'];    

// &visitor1 = x
$rString.= "&visitor".$i."=".$row['visitor'];

// &time1 = x
$rString.= "&time".$i."=".$row['time'];

// &comment1 = x
$rString.= "&comment".$i."=".$row['comment']; 

The ampersand (&) is a variable separator, generally used in querystring's (url) or for loading into another language such as flash.
How is $rString being used, in terms of where else is it called in the script?

Regarding the equal sign (=), $rString is being used to concatenate different variables into one string, the full output would look something like:
Code:

&ID1=x&visitor1=x&time1=x&comment1=x
Hope this helps a little :)

djscour 03-29-2008 01:53 AM

Hey Flying Buddha (by the way cool name),

Thanks a lot for responding. That definitely helped me understand a bit more.

That's precisely what the tutorial is doing - using a flash interface.

Also thanks for the alternate way of writing out that code. It is way easier to read that way.

DJScour


All times are GMT. The time now is 03:16 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0