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 22-May-2005, 18:34
justinhn justinhn is offline
New Member
 
Join Date: May 2005
Posts: 3
justinhn is on a distinguished road

Basic PHP For Loop Help


Hi Guys,

I have a general enquiry about PHP syntax. I'm having trouble creating a VERY simple for loop using PHP, i think the best way to explain this is by an example:
say if i want to create a loop which changes the values of different variables of incrementing names at every loop, how would i do this:

$date1 = sunday
$date2 = monday
$date3 = tuesday
... $date7 = saturday

for ($i=1; $i<8; $i++) {
$date.$i==1;
}

the above code doesnt work, i hope you guys can see what im trying to do here.
trying to amend $date1 == 1, then $date2 == 1... $date7== 1.

What should be the correct code for $date.$i==1?

Thanks,
- Justin
  #2  
Old 22-May-2005, 19:56
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Hello justinhn,

I'll be honest - I really don't understand what you're asking.

However, I would suggest you use an array for something like this... for example:

PHP Code:

<?php

$date[1] = 'sunday';
$date[2] = 'monday';
$date[3] = 'tuesday';
//... 
$date[7] = 'saturday';

for( $i=1; $i<8; $i++ )
{
    $date[$i] = 1; // this is where I really got confused; you used a COMPARISON operator here in your example!
}

?>

 
 

Recent GIDBlogFirst week of IA training 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
Help ! I need help starting up on Php ! onauc MySQL / PHP Forum 11 04-Jan-2005 23:57
uisng php to display php dopee MySQL / PHP Forum 6 14-May-2004 18:40
php software dopee MySQL / PHP Forum 0 04-May-2004 11:26
[Linux] Installing PHP --with-mcrypt JdS Web Hosting Forum 0 20-Aug-2003 08:40
All the big PHP script collections that matter jrobbio MySQL / PHP Forum 5 06-Jun-2003 16:14

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

All times are GMT -6. The time now is 01:31.


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