This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » development » Miscellaneous » foreach in php
foreach in php [message #96843] Tue, 06 April 2010 12:40 Go to next message
deadman  is currently offline deadman
Messages: 14
Registered: March 2010
Junior Member
can we use two or more conditions in foreach loop????


like this...

<?php foreach($allsuggestions as $st && $allactions as $ac): ?>

this thing isn't working.....please let me know if there is a solution...


thnx in advance
deadman
Re: foreach in php [message #96845 is a reply to message #96843 ] Tue, 06 April 2010 12:58 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
Errr.. what is that meant to do? Shocked. Do you want to iterate over one, and within that iterate over the other? If so, nest two foreach loops.

[Updated on: Tue, 06 April 2010 12:58]


Remember Palestine
Re: foreach in php [message #96847 is a reply to message #96845 ] Tue, 06 April 2010 13:17 Go to previous messageGo to next message
deadman  is currently offline deadman
Messages: 14
Registered: March 2010
Junior Member
here is my code........


<?php $m = 1 ; ?>
<?php foreach($allsuggestions as $st): ?>
<tr>
<td><?php echo $m; ?></td>
<td><?php echo $st->getSuggestion(); ?></td>
<td><?php echo $st->getSuggestionDate(); ?></td>
<td><?php foreach($allactions as $ac) echo $ac->getSuggestionStatus(); endforeach;?></td>
<td><?php echo $st->getReason(); ?></td>
</tr>
<?php $m = $m+1; ?>
<?php endforeach; ?>


I want to use SuggestionStatus from a different table whereas all other <td>'s are from different table.............
this code isn't working ......what am I supposed to do ??

thnx
deadman


Re: foreach in php [message #96849 is a reply to message #96847 ] Tue, 06 April 2010 14:57 Go to previous message
erland  is currently offline erland
Messages: 14
Registered: August 2007
Location: Oslo, Norway
Junior Member
This is something your model should take care of. If there is a relation between your two objects (assuming "Suggestion" and "Action"), you should be able to perform a

Suggestion::getAction()

That is in your case, a

$st->getAction()->getSuggestionStatus()


This schema would give you the mentioned logic (note the verbose notation):

(...)
Suggestion:
  columns:
    (...)
    action_id:
      type: integer(4)
  relations:
    Action:
      class: Action
      local: id
      foreign: action_id

Action:
  columns:
    (...)
    suggestion_status:
      type: varchar(255) *

*: if this is what you want


This is not necessarily the only/best/preferred solution, but it may prove to be a starting point. The gist of it: Build a sensible data/object model Smile

Regards,
Erland
Previous Topic:eclipse + svn
Next Topic:Looking for mid to senior PHP developer for a working partner position
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software