PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
carleihar
Forum Commoner
Posts: 36 Joined: Fri Nov 13, 2009 5:59 pm
Post
by carleihar » Sun Feb 07, 2010 4:30 pm
Using this code, how would I end the first while loop and then do different code and the loop through that same loop again?
Code: Select all
$q = "SELECT something FROM whatever WHERE something='$id'";
$r = @mysqli_query ($dbc, $q); // Run the query.
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
blah blah blah
}
Thanks!
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Sun Feb 07, 2010 5:08 pm
to end the first loop insert a break; after blah blah blah
carleihar
Forum Commoner
Posts: 36 Joined: Fri Nov 13, 2009 5:59 pm
Post
by carleihar » Sun Feb 07, 2010 7:38 pm
That's not really what I was talking about...I want to start a loop, echo some something from each iteration of the loop, stop the loop to put some HTML in, then continue the loop.
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Mon Feb 08, 2010 3:11 am
yeah i know, but i just posted what i do know
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Mon Feb 08, 2010 4:36 am
Save the data in an array and reuse that array.
Code: Select all
while ($row = mysqli_fetch_assoc($r)) {
$data[] = array('id'=>$row['id'], 'name'=>$row['name']);
}
print_r($data);
carleihar
Forum Commoner
Posts: 36 Joined: Fri Nov 13, 2009 5:59 pm
Post
by carleihar » Mon Feb 08, 2010 11:04 am
Yeah, that works... (sorry, I'm still a little new). It shows
Array ( [horse_id] => 12 [date_created] => 2009-11-16 )
for each array. How can I get just that information (the 12 and the date) and not all the Array([' stuff?
Thank you for your help!
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Tue Feb 09, 2010 1:58 am
Code: Select all
foreach($data as $d)
{
echo $d['horse_id'];
echo $d['date_created'];
echo "<br />\n";
}