| | |
How to show more than one result in while loop
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
hello friends..
above code i use for fetching data.. one result in one row at a time..!!!
now i m try to show two result in one row..!!!
in other words.. two different data in one row..!!!
how can i do that...???
php Syntax (Toggle Plain Text)
<?while($row=(mysql_fetch_array(result)) {?> <tr> <td><?echo $row['photo']?></td> <td><?echo $row['info']?></td> </tr> <?}?>
above code i use for fetching data.. one result in one row at a time..!!!
now i m try to show two result in one row..!!!
in other words.. two different data in one row..!!!
how can i do that...???
Last edited by nish123; Sep 29th, 2009 at 1:06 pm.
How about:
I find it messy to go in and out of PHP so I modified it to make it all PHP.
PHP Syntax (Toggle Plain Text)
<?PHP while($row=(mysql_fetch_array(result)) { echo " <td>$row['photo']</td><td>$row['info']</td> "; if ($row=(mysql_fetch_array(result)) { echo " <td>$row['photo']</td><td>$row['info']</td> "; } echo "</tr>"; } ?>
I find it messy to go in and out of PHP so I modified it to make it all PHP.
Last edited by chrishea; Sep 29th, 2009 at 3:34 pm.
•
•
•
•
How about:
PHP Syntax (Toggle Plain Text)
<?PHP while($row=(mysql_fetch_array(result)) { echo " <td>$row['photo']</td><td>$row['info']</td> "; if ($row=(mysql_fetch_array(result)) { echo " <td>$row['photo']</td><td>$row['info']</td> "; } echo "</tr>"; } ?>
I find it messy to go in and out of PHP so I modified it to make it all PHP.
Just no. For two reasons: Reason 1) You're duplicating code, if he wants to change the td's to dd's or something like that he has to change it in two places, Reason 2) I'm not even going to begin with how much more ugly that looks when compared to exiting PHP
The best way to go about it is to keep a counter and whenever it's divisible by 2 you've looped twice so end the row and start another one.
php Syntax (Toggle Plain Text)
<tr> <?php $i = 1; while($row=mysql_fetch_array(result)): ?> <?php if (!($i++ % 2) ): ?> </tr><tr> <?php endif ?> <td><?php echo $row['photo'] ?></td> <td><?php echo $row['info'] ?></td> <?php endwhile ?> </tr>
Last edited by ShawnCplus; Sep 29th, 2009 at 5:28 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
This may be a worth while solution ... You can change the number if columns to whatever you want and it will simply start a new row when you reach that number of columns. Adjust the cellspacing, cellpadding, and aligns accordingly. Just a thought.
PHP Syntax (Toggle Plain Text)
$i = 0; $num_of_cols = 5; echo "<table cellspacing=\"10\" cellpadding=\"10\"><tr>"; while($row=(mysql_fetch_array(result)) { echo ($i!= 0 && $i%$num_of_cols == 0)?'</tr><tr>':''; echo "<td valign=\"bottom\" align=\"center\">"; echo "<Your_output_here>"; echo"</td>"; $i++; } echo '</tr></table>';
![]() |
Similar Threads
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result (PHP)
- help in stored procedure-result of a loop using cursor (MS SQL)
- Result without while loop (PHP)
- Visual Basic Help! (Visual Basic 4 / 5 / 6)
- recognize end of pps show by visual basic (Visual Basic 4 / 5 / 6)
- how to show PC clock in the screen using TASM (Assembly)
- display results of search from drop down menu (PHP)
Other Threads in the PHP Forum
- Previous Thread: Help me convert this ASP into PHP plz :-)
- Next Thread: Show region behavior for a php generated txt box
| Thread Tools | Search this Thread |
ajax apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail match md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion regex remote script search server session sessions sms smtp soap source space sql strip_tags survey syntax system table tutorial undefined update upload url validator variable video virus votedown web window.onbeforeunload=closeme; xml youtube






