Reply
How to resume foreach loop?
Old 11-06-2009, 09:58 PM How to resume foreach loop?
Average Talker

Posts: 17
Name: Gary
Trades: 0
Is there a way to resume or continue with the next $value of the foreach loop if the query result is null or empty? If so, how please? The way this is supposed to work is $_POST['select'] contains multiple zip codes. As $value is iterated, vacpct is selected from the database to be placed in an array. The problem is, if a zip code has 0 (zero) for vacpct, the result of the query is null or empty (not sure which) as only zip codes that have vacpct that are greater than 0 (zero) are to be selected. When this happens, the action stops, and the next $value(s) or zip codes are not itereated. I need a way to continue with the next $value when this happens. Thanks in advance.


PHP Code:
foreach ($_POST['selectzip'] as $value)  {

if (
$value != " ") {

$resultsvacpct "SELECT vacpct FROM wamuexp where  vacpct > 0 &&  zip LIKE '$value%'  ORDER BY vacpct";
$sql_resultsvacpct mysql_query($resultsvacpct,$dbc); 

$i=0
while (
$row mysql_fetch_array($sql_resultsvacpct))

// load array with data from table 
$vacpctarr[] = $row[vacpct]; 

//echo "$vacpctarr[$i]<br>"; 

$i $i 1


}

gdaniels is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-07-2009, 03:31 AM Re: How to resume foreach loop?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Converting Video For YouTube
Posts: 2,553
Name: Keith Marshall
Location: West Hartford, CT
Trades: 0
Just use continue to iterate the next loop. So your check line at the top of the loop could be:

if ((int)$value <= 0) continue;
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to How to resume foreach loop?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.10572 seconds with 13 queries