Jump to content

Inifite while loop terror


mkultron

Recommended Posts

Hi guys,

 

I'm having a bit of bother running this while loop, it's infinite. Could you give me some tips on getting it fixed please?

 

        while($row = mysql_fetch_array( $result )) {

	$stuffandthings = mysql_result($result, $i, 'stuffandthings');
                echo '<td>' . $row['stuffandthings'] . '</td>';

        }

 

Thanks

MK

Link to comment
Share on other sites

Sorry I actually need it set out like this (with the line you replaced) as it's the only way I seem to be able to format the date the way I want it without it setting everythig to today's date, however when I use the line you took out it produces an infinite loop. Any idea how I can avoid this while still retaining the correct formatted date?

 

while($row = mysql_fetch_array( $result )) {

			$mydate = mysql_result($result, $i, 'mydate');
			$dt = new DateTime($mydate);
			echo '<td>' . $dt->format("jS F Y, g:i a") . '</td>';
}

 

Thanks

MK

Link to comment
Share on other sites

You don't need to use mysql_result. mysql_fetch_array already places each column value into the $row array. You just need to reference the $row['column_name_here'] that holds your date.

 

Also, why don't you simply select the date formated the way you want it in your query? There's no need for any slow parsed, tokenized, interpreted php code.

Link to comment
Share on other sites

OK, thanks. I tried this and it posts the first result once and the second one over and over (btw I'm pulling more values out of the database using * but I've left them out for the purpose of this post).

 

$result = mysql_query("SELECT *, DATE_FORMAT(mydate, '%a %b %e %Y %H:%i') AS mydate FROM stuff.eventstest ORDER BY mydate ASC") 
or die(mysql_error());  


        while($row = mysql_fetch_assoc($result)) {

			echo $row['mydate'];
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.