Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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
 
 
Register now for full access!
Old 11-07-2009, 03:31 AM Re: How to resume foreach loop?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
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 offline
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.10362 seconds with 12 queries