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
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-27-2008, 08:18 PM   #1 (permalink)
The Visitor
 
Join Date: Mar 2008
Posts: 2
Thanks: 1
djscour is on a distinguished road
Confused 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
djscour is offline  
Reply With Quote
Old 03-28-2008, 01:55 PM   #2 (permalink)
The Contributor
 
flyingbuddha's Avatar
 
Join Date: Jan 2008
Location: Birmingham, UK
Posts: 60
Thanks: 10
flyingbuddha is on a distinguished road
Default

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 :)
__________________
Pro. Geek
http://www.mikeholloway.co.uk

Last edited by flyingbuddha : 03-28-2008 at 01:56 PM. Reason: typos
flyingbuddha is offline  
Reply With Quote
The Following User Says Thank You to flyingbuddha For This Useful Post:
djscour (03-29-2008)
Old 03-29-2008, 01:53 AM   #3 (permalink)
The Visitor
 
Join Date: Mar 2008
Posts: 2
Thanks: 1
djscour is on a distinguished road
Default

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
djscour is offline  
Reply With Quote
Reply



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


All times are GMT. The time now is 11:30 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