liam1412 Posted January 24, 2007 Share Posted January 24, 2007 I need to have 10 rows in one of my divs in order for the formating to remain in line. If I query my database and there are only 7 results I want to echo 3 blank rows to pad it out. I have come up with this but it doesn't work. Can anyone tell me why.[code]<?php$query = "blah";$result = mysql_query($query);$var1 = $result['field1'];$var2 = $result['field2'];$numrows = mysql_num_rows($result)?><table><?phpwhile($rows = mysql_fetch_array($result)){?><tr><td>$var1</td><td>$var2</td></tr><?phpif{$numrows != 10{?><tr><td><br /></td><td><br /></td></tr><?php$numrows = ($numrows + 1);}}?>[/code] Link to comment https://forums.phpfreaks.com/topic/35568-another-quick-and-probably-easy-question/ Share on other sites More sharing options...
craygo Posted January 24, 2007 Share Posted January 24, 2007 First which way do you want to list the data..like.1 2 3 4 56 7 8 9 10or 1 62 73 84 95 10Ray Link to comment https://forums.phpfreaks.com/topic/35568-another-quick-and-probably-easy-question/#findComment-168410 Share on other sites More sharing options...
liam1412 Posted January 24, 2007 Author Share Posted January 24, 2007 [quote]1 62 73 84 95 10[/quote]This way - This is on completely different query to the one you answered ten mins ago for me.Ta Link to comment https://forums.phpfreaks.com/topic/35568-another-quick-and-probably-easy-question/#findComment-168413 Share on other sites More sharing options...
liam1412 Posted January 24, 2007 Author Share Posted January 24, 2007 I have just notcied a mistake in the code that isn't actually there in my proper codethe line [code]if{$numrows != 10{[/code]does actually read as it should in my proper code.[code]if($numrows != 10){[/code] Link to comment https://forums.phpfreaks.com/topic/35568-another-quick-and-probably-easy-question/#findComment-168417 Share on other sites More sharing options...
craygo Posted January 24, 2007 Share Posted January 24, 2007 Try this[code]<table border="0" CELLSPACING="0" CELLPADDING="10" align="center"><?php//set 3 to 4 of you want 4 columns. Set it to 5 if you want 5, etc$numcols = 2; // how many columns to display$numcolsprinted = 0; // no of columns so far$num_rows = mysql_num_rows($result)// get each rowwhile($result = mysql_fetch_array($result)){{//get data - eg, reading fields 0 and 1$var1 = $result['field1'];$var2 = $result['field2'];if ($numcolsprinted == $numcols) {print "</tr>\n<tr>\n";$numcolsprinted = 0;}// output row from databaseecho "<td>$var1 $var2</td>\n";// bump up row counter$numcolsprinted++;} // end while loop$colstobalance = $numcols - $numcolsprinted;for ($i=1; $i<=$colstobalance; $i++) {}for($i=0; $i<10-$num_rows; $i++){if ($numcolsprinted == $numcols) {// Output blank rowprint "</tr>\n<tr>\n";$numcolsprinted = 0;}// output blank columnecho "<td> </td>\n";// bump up row counter$numcolsprinted++;}?></tr></table>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/35568-another-quick-and-probably-easy-question/#findComment-168422 Share on other sites More sharing options...
liam1412 Posted January 24, 2007 Author Share Posted January 24, 2007 Cheers mate.Thanks for your help Link to comment https://forums.phpfreaks.com/topic/35568-another-quick-and-probably-easy-question/#findComment-168450 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.