Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skipping in a while?

Status
Not open for further replies.

youradds

Programmer
Joined
Jun 27, 2001
Messages
817
Location
GB
I'm just wondering, how would one go about skipping a 'while' loop for a MySQL result? I have;

// do a while to grab the data...
while ($row = mysql_fetch_array ($result)) {


//make sure we only show dates that they want to see...
foreach ($dates as $val) {
if ($row[DueDate] == $val) { echo &quot;<font color=green>match!</font>&quot;; $ok = 1; last; }
}

// skip if the date is not correct to show...
if (!$ok) { next; }

if ($row[Done] == 1) { $done = &quot;<font color=green>Yes</font>&quot;; } else { $done = &quot;<font color=red>No</font>&quot;; }
$_entries .= &quot;$row[DueDate]&quot;;


} // end the 'while'

Basically, I need to skip to the next entry in the results where I have next; , and also stop the 'foreach' where I have 'last'. Is 'next' a valid command in PHP? I know both next/last are valid in Perl, but I'm not so sure about PHP.

I'm pretty stuck here :(

Cheers

Andy
 
&quot;Basically, I need to skip to the next entry in the results where I have next;&quot; - i dont understand this...

Known is handfull, Unknown is worldfull
 
[tt]while ($row = mysql_fetch_array ($result)) {
foreach ($dates as $val) {
if ($row[DueDate] == $val){
echo &quot;<font color=green>match!</font>&quot;;
$ok = 1;
end for;
} //end if
} // end for
if($ok){
if ($row[Done] == 1){
$done = &quot;<font color=green>Yes</font>&quot;;
}else{
$done = &quot;<font color=red>No</font>&quot;;
}
$_entries .= &quot;$row[DueDate]&quot;;
}//end if
} //end while[/tt]

I'm not completely sure on that end for.
If it will exit out of the foreach loop.

'... and then it wouldn't compile?'
t_avatar.jpg
 
when i've got
$ok = 1;
end for;

replace end for;
with break;

break ends execution of the foreach.

'... and then it wouldn't compile?'
t_avatar.jpg
 
Thanks...it worked like a charm :)

Andy
 
youradds,

Have you ever considered keeping each date in its own record?
It might be a better use of the powers of a SQL database to employ the query function to sort out what's displayed and what's not.
Since you stuck more than one date into the same record that is not possible.

Although the planning and layout of tables takes more thought the application flow and clarity will be easier when the returned datasets already are filtered to the specified condition.

As I said before, that is only possible if a record actually represents one datum, not a collection of data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top