I want to fetch information from one table and loop that until it's done, with the help of a while loop. Although, I want one column to be printed only once inside the loop.
There's two solutions I've come up with...
<?php $i = 0; // while loop start if($i == 0){ // stuff to print $i++; } // while loop end ?> And ofcourse, I could just make another query before the while loop.
But these methods really aren't too efficient. Is there a less messy way to do this?
Actually, I'd be okay with running another query before the while loop, if it didn't get so messy, and perhaps if I could just re-use the query intended for the loop (I fetch everything from the table). I tried experimenting with mysql_fetch_field, but I'm not sure I get how it works, or if that even helps here * embarrassed *
Currently, the code looks like so:
$fetch = mysql_query("SELECT * FROM `pms` JOIN `pm_conversations` ON pms.ConvID = pm_conversations.ID WHERE `ConvID`='".$_GET['id']."'"); $i = 0; while($print = mysql_fetch_array($fetch)){ if($i == 0){ echo $print['Subject']; $i++; } <table> <th><?=$print['From']?>, <?=$print['DateSent']?></th> <tr><td><?=$print['Message']?></td></tr> </table> }