General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 14th, 2004, 10:35 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
for loop in an array

I need to do the following any ideas:

PHP Code:
for ($i 1$i <= 10$i++) {
        
$day_array = array('view_match.php?id='.$event_id'linked-day');
        
$day_of_event $row['DATENUMBER'];
        
$test1 = ($day_of_event=>$day_array); //<-- THIS LINE CREATES AN ERROR

    

__________________
regards,


Fulton

Reply With Quote
  #2  
Old January 14th, 2004, 02:48 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
I am not seeing what it is you are trying to do here. It looks like you want to get information from $day_of_event which may be an associative array using the $day_array value as an index... is this close?

I also do not see where your for loop comes into play and where you would need to use the $i variables. Why is it looping up to 10?

Maybe you need a foreach to iterate an associative array?

Reply With Quote
  #3  
Old January 18th, 2004, 10:19 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Sorry my previous post was really bad, here is what i am trying to do, but without success:

PHP Code:
 $result mysql_query("select id, match_date_time from table") or die ("Cannot select from schedule table. ".mysql_error()."");
    
    
        while (list(
$id$match_date_time) = mysql_fetch_row($result)) {
           
//echo "Key: $id; Value: $match_date_time<br />\n";
           
$test $id=>array('index.php?id='$id,'linked'); // <-- THIS LINES CREATE THE ERROR
          
echo $test."<br>";
        } 


Any ideas??

Reply With Quote
  #4  
Old January 18th, 2004, 03:12 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I dont understand why you're making the array...

why not just do this:
$test = "index.php?id=$id";

although if you insist on the array... try this:
$test = array('index.php?id='. $id,'linked');

if that fails, try $test[] = ...

Reply With Quote
  #5  
Old January 18th, 2004, 03:38 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
I need to create a list of arrays, which will then be put into another array.
i.e.
PHP Code:
 $page = array(array($id=>array('index.php?id='$id,'linked'), $id=>array('index.php?id='$id,'linked'), $id=>array('index.php?id='$id,'linked')); 


does that make better sense.

Reply With Quote
  #6  
Old January 18th, 2004, 04:35 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I'm pretty sure this syntax here will cause an error:
$id=>array(stuff)

try simply taking the $id=> out and just doing array(stuff)

Reply With Quote
  #7  
Old January 18th, 2004, 04:47 PM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
it needs to be like this as the function requires it
$id=>array('index.php?id='. $id,'linked')

This is how it looks
PHP Code:
 $days = array(
      
2=>array('/weblog/archive/2004/Jan/02','linked-day'),
      
3=>array('/weblog/archive/2004/Jan/03','linked-day'),
      
8=>array('/weblog/archive/2004/Jan/08','linked-day'),
      
22=>array('/weblog/archive/2004/Oct/22','linked-day')
  );

while (
$day <= $maxdays){
        if(
$weekday == 7){ #start a new week
            
$calendar .= "</tr>\n<tr>";
            
$weekday 0;
        } 

but i want to get the day values from a database.

Reply With Quote
  #8  
Old January 18th, 2004, 06:06 PM
Mike_r Mike_r is offline
ExoCrew
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 68 Mike_r User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Use this function :

$array = array();

array_push ( $array, "STUFF, here it can be a sub-array too" );

Convert your code to use this function..
__________________
ExoHelpDesk
ExoCrew Free Services

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > for loop in an array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT