[PHP] Re: [PHP-DB] I cant get the logic for this...
"; // while there is data... while($row = mysql_fetch_object($res)) { // begin new row if appropriate. // NOTE: Of necessity, I separate this from the // end-of-row test; otherwise, a query returning // an exact multiple of the table width would // result in a table with an empty final row. if (0 == $nPos) echo ""; // write a cell and increment location echo "".your_stuff.""; $nPos++; // end row if appropriate and reset location if ($nWidth == $nPos) { echo ""; $nPos = 0; } } // calculate padding needed for final row // NOTE: if-and-only-if padding is required, // the row must be terminated; otherwise the // row must have already been terminated. $nEmpty = $nWidth - ($nPos+1); if ($nEmpty > 0) echo " "; // end table echo ""; ?> > >So my result returns say seven results, I have a table, and I want to > >show > >3 results per row of the table... I.e.: > > > >Table > >TR > >TD = result1 /TD TD result2 /TD TD = result3 /TD > >/TD > >/TR > >TR > >TD = result4 /TD TD result5 /TD TD = result6 /TD > >/TD > >/TR > >TR > >TD = result7 /TD TD resultempty /TD TD = resultempty /TD > >/TD > >/TR > >/table > > > >The last two td in row 3 are empty because result found 7 results. > > > >This cant be fixed so echo statements wont work as the result could > >Be 3 or 10 or 56 or whatever. > > > >As Always your help and or guidance in this matter is appreciated. > > > >Dave Carrera > >Php / MySql Development > >Web Design > >Site Marketing > >http://www.davecarrera.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RE: [PHP-DB] I cant get the logic for this...
try this - in pseudo-code, can't do everything for you :) max = 3 col = 0 echo "table" while (row = db_results) if (col == 0) echo "tr" echo "td data /td"; if (col == max - 1) echo "/tr" col = (col + 1) % max wend if col > 0 for i = 1 to max - col echo "td nbsp td" next echo "/tr" end if echo "/table" -Original Message- From: David Redmond [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 19, 2002 3:05 PM To: 'SpamSucks86'; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: [PHP] RE: [PHP-DB] I cant get the logic for this... If you use the following code it should work well. I used 2 counters, one for the columns and one for the row. It's a bit messy but it works. Cheers NB: Code is untested but copied from a working example with unnecessary bits removed. \n"; $counterRow = 0; $counterCol = 0; $counterResults = mysql_num_rows($result); for ($i = 0; $i < $counterResults; $i++) { if (($colCounter < 3) && ($counterRow == 0)) { echo " \n"; $counterRow = 1; } echo " Column Data\n"; $counterCol++; if ($counterCol == 3) { echo " \n"; $counterCol = 0; $counterRow = 0; } } echo "\n"; ?> -Original Message----- From: SpamSucks86 [mailto:[EMAIL PROTECTED]] Sent: Tuesday, 19 February 2002 12:35 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: [PHP] RE: [PHP-DB] I cant get the logic for this... I had this same problem. It's very aggravating. Jason G's solution won't work, because $oRow will always be true as long as there is more results, NOT if there are less than 3 results left. Why don't you true something like this 0) { //echo your row with 3 cells $numevenrows = $numevenrows - 1; } if ($numrows == 2) { //Write the last row with only two cells. You might want to just close the old table and make a new one and center it so that those two cells are centered, or you could use colspan="2" in the HTML so that one of the cells spans more. } elseif ($numrows == 1) { //same thing } ?> This code is definitely untested, but I think you should understand the logic behind it, I did more commenting than I did coding. -Original Message- From: Jason G. [mailto:[EMAIL PROTECTED]] Sent: Monday, February 18, 2002 9:11 AM To: Dave Carrera; [EMAIL PROTECTED] Subject: Re: [PHP-DB] I cant get the logic for this... $nWidth = 3; $oRow = TRUE; while($oRow) { //Write tr here for($i=0; $i<$nWidth; $i++) { $oRow = mysql_fetch_object($dbResult); //Write here } //write /tr here } At 12:06 PM 2/18/2002 +, you wrote: >Hi all, > >I want to display return results from my query (which works fine) >In I tidy way on screen. > >So my result returns say seven results, I have a table, and I want to >show >3 results per row of the table... I.e.: > >Table >TR >TD = result1 /TD TD result2 /TD TD = result3 /TD >/TD >/TR >TR >TD = result4 /TD TD result5 /TD TD = result6 /TD >/TD >/TR >TR >TD = result7 /TD TD resultempty /TD TD = resultempty /TD >/TD >/TR >/table > >The last two td in row 3 are empty because result found 7 results. > >This cant be fixed so echo statements wont work as the result could >Be 3 or 10 or 56 or whatever. > >As Always your help and or guidance in this matter is appreciated. > >Dave Carrera >Php / MySql Development >Web Design >Site Marketing >http://www.davecarrera.com > > > > >-- >PHP Database Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] RE: [PHP-DB] I cant get the logic for this...
If you use the following code it should work well. I used 2 counters, one for the columns and one for the row. It's a bit messy but it works. Cheers NB: Code is untested but copied from a working example with unnecessary bits removed. \n"; $counterRow = 0; $counterCol = 0; $counterResults = mysql_num_rows($result); for ($i = 0; $i < $counterResults; $i++) { if (($colCounter < 3) && ($counterRow == 0)) { echo " \n"; $counterRow = 1; } echo " Column Data\n"; $counterCol++; if ($counterCol == 3) { echo " \n"; $counterCol = 0; $counterRow = 0; } } echo "\n"; ?> -Original Message- From: SpamSucks86 [mailto:[EMAIL PROTECTED]] Sent: Tuesday, 19 February 2002 12:35 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: [PHP] RE: [PHP-DB] I cant get the logic for this... I had this same problem. It's very aggravating. Jason G's solution won't work, because $oRow will always be true as long as there is more results, NOT if there are less than 3 results left. Why don't you true something like this 0) { //echo your row with 3 cells $numevenrows = $numevenrows - 1; } if ($numrows == 2) { //Write the last row with only two cells. You might want to just close the old table and make a new one and center it so that those two cells are centered, or you could use colspan="2" in the HTML so that one of the cells spans more. } elseif ($numrows == 1) { //same thing } ?> This code is definitely untested, but I think you should understand the logic behind it, I did more commenting than I did coding. -Original Message- From: Jason G. [mailto:[EMAIL PROTECTED]] Sent: Monday, February 18, 2002 9:11 AM To: Dave Carrera; [EMAIL PROTECTED] Subject: Re: [PHP-DB] I cant get the logic for this... $nWidth = 3; $oRow = TRUE; while($oRow) { //Write tr here for($i=0; $i<$nWidth; $i++) { $oRow = mysql_fetch_object($dbResult); //Write here } //write /tr here } At 12:06 PM 2/18/2002 +, you wrote: >Hi all, > >I want to display return results from my query (which works fine) >In I tidy way on screen. > >So my result returns say seven results, I have a table, and I want to >show >3 results per row of the table... I.e.: > >Table >TR >TD = result1 /TD TD result2 /TD TD = result3 /TD >/TD >/TR >TR >TD = result4 /TD TD result5 /TD TD = result6 /TD >/TD >/TR >TR >TD = result7 /TD TD resultempty /TD TD = resultempty /TD >/TD >/TR >/table > >The last two td in row 3 are empty because result found 7 results. > >This cant be fixed so echo statements wont work as the result could >Be 3 or 10 or 56 or whatever. > >As Always your help and or guidance in this matter is appreciated. > >Dave Carrera >Php / MySql Development >Web Design >Site Marketing >http://www.davecarrera.com > > > > >-- >PHP Database Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: [PHP-DB] I cant get the logic for this...
I had this same problem. It's very aggravating. Jason G's solution won't work, because $oRow will always be true as long as there is more results, NOT if there are less than 3 results left. Why don't you true something like this 0) { //echo your row with 3 cells $numevenrows = $numevenrows - 1; } if ($numrows == 2) { //Write the last row with only two cells. You might want to just close the old table and make a new one and center it so that those two cells are centered, or you could use colspan="2" in the HTML so that one of the cells spans more. } elseif ($numrows == 1) { //same thing } ?> This code is definitely untested, but I think you should understand the logic behind it, I did more commenting than I did coding. -Original Message- From: Jason G. [mailto:[EMAIL PROTECTED]] Sent: Monday, February 18, 2002 9:11 AM To: Dave Carrera; [EMAIL PROTECTED] Subject: Re: [PHP-DB] I cant get the logic for this... $nWidth = 3; $oRow = TRUE; while($oRow) { //Write tr here for($i=0; $i<$nWidth; $i++) { $oRow = mysql_fetch_object($dbResult); //Write here } //write /tr here } At 12:06 PM 2/18/2002 +, you wrote: >Hi all, > >I want to display return results from my query (which works fine) >In I tidy way on screen. > >So my result returns say seven results, I have a table, and I want to >show >3 results per row of the table... I.e.: > >Table >TR >TD = result1 /TD TD result2 /TD TD = result3 /TD >/TD >/TR >TR >TD = result4 /TD TD result5 /TD TD = result6 /TD >/TD >/TR >TR >TD = result7 /TD TD resultempty /TD TD = resultempty /TD >/TD >/TR >/table > >The last two td in row 3 are empty because result found 7 results. > >This cant be fixed so echo statements wont work as the result could >Be 3 or 10 or 56 or whatever. > >As Always your help and or guidance in this matter is appreciated. > >Dave Carrera >Php / MySql Development >Web Design >Site Marketing >http://www.davecarrera.com > > > > >-- >PHP Database Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: [PHP-DB] I cant get the logic for this...
I had this same problem. It's very aggravating. Jason G's solution won't work, because $oRow will always be true as long as there is more results, NOT if there are less than 3 results left. Why don't you true something like this 0) { //echo your row with 3 cells $numevenrows = $numevenrows - 1; } if ($numrows == 2) { //Write the last row with only two cells. You might want to just close the old table and make a new one and center it so that those two cells are centered, or you could use colspan="2" in the HTML so that one of the cells spans more. } elseif ($numrows == 1) { //same thing } ?> This code is definitely untested, but I think you should understand the logic behind it, I did more commenting than I did coding. -Original Message- From: Jason G. [mailto:[EMAIL PROTECTED]] Sent: Monday, February 18, 2002 9:11 AM To: Dave Carrera; [EMAIL PROTECTED] Subject: Re: [PHP-DB] I cant get the logic for this... $nWidth = 3; $oRow = TRUE; while($oRow) { //Write tr here for($i=0; $i<$nWidth; $i++) { $oRow = mysql_fetch_object($dbResult); //Write here } //write /tr here } At 12:06 PM 2/18/2002 +, you wrote: >Hi all, > >I want to display return results from my query (which works fine) >In I tidy way on screen. > >So my result returns say seven results, I have a table, and I want to >show >3 results per row of the table... I.e.: > >Table >TR >TD = result1 /TD TD result2 /TD TD = result3 /TD >/TD >/TR >TR >TD = result4 /TD TD result5 /TD TD = result6 /TD >/TD >/TR >TR >TD = result7 /TD TD resultempty /TD TD = resultempty /TD >/TD >/TR >/table > >The last two td in row 3 are empty because result found 7 results. > >This cant be fixed so echo statements wont work as the result could >Be 3 or 10 or 56 or whatever. > >As Always your help and or guidance in this matter is appreciated. > >Dave Carrera >Php / MySql Development >Web Design >Site Marketing >http://www.davecarrera.com > > > > >-- >PHP Database Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP-DB] I cant get the logic for this...
$nWidth = 3; $oRow = TRUE; while($oRow) { //Write tr here for($i=0; $i<$nWidth; $i++) { $oRow = mysql_fetch_object($dbResult); //Write here } //write /tr here } At 12:06 PM 2/18/2002 +, you wrote: >Hi all, > >I want to display return results from my query (which works fine) >In I tidy way on screen. > >So my result returns say seven results, I have a table, and I want to >show >3 results per row of the table... I.e.: > >Table >TR >TD = result1 /TD TD result2 /TD TD = result3 /TD >/TD >/TR >TR >TD = result4 /TD TD result5 /TD TD = result6 /TD >/TD >/TR >TR >TD = result7 /TD TD resultempty /TD TD = resultempty /TD >/TD >/TR >/table > >The last two td in row 3 are empty because result found 7 results. > >This cant be fixed so echo statements wont work as the result could >Be 3 or 10 or 56 or whatever. > >As Always your help and or guidance in this matter is appreciated. > >Dave Carrera >Php / MySql Development >Web Design >Site Marketing >http://www.davecarrera.com > > > > >-- >PHP Database Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php