Re: [PHP] newbie algorithm help!!!!!
i have a mysql table with approx. 30 entries. I wanna get them(i know how to do that) and list them in a 2-column table. For those minimalist-typists among us... :-) $rowcount = 0; echo TABLETR\n; while (list($whatever) = mysql_fetch_row($result)){ echo TD$whatever/TD\n; $rowcount++; if ($rowcount % 2 == 0){ echo /TRTR\n; } } Change the 2 to other number for more columns. -- WARNING [EMAIL PROTECTED] address is an endangered species -- Use [EMAIL PROTECTED] Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] newbie algorithm help!!!!!
please share if you know hwo to di it. thanks you McShen [EMAIL PROTECTED] wrote in message 9gqm6o$g6n$[EMAIL PROTECTED]">news:9gqm6o$g6n$[EMAIL PROTECTED]... hi i have a mysql table with approx. 30 entries. I wanna get them(i know how to do that) and list them in a 2-column table. I have been trying to use a loop to do it. But it will only produce a 1-column table. it's like entry 1 entey 2 entry 3 entry 4 etc Please help me so that i can get this : entry1 entry2 entry3 entry4 Thanks in advanced. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] newbie algorithm help!!!!
is this what you want? there must be an easier way. i am sure some one else knows it be i would - ?php $result = mysql_query("select * from table"); ? table $i = 0; while($my_array = mysql_fetch_array($result)) { if($i%2) { print"td{$my_array[0]/td/tr"; } else { print"trtd{$my_array[0]}/td"; } $i++: } /table or am i completely off on what you need? please share if you know hwo to di it. thanks you""McShen"" [EMAIL PROTECTED] wrote in message9gqm6o$g6n$[EMAIL PROTECTED]">news:9gqm6o$g6n$[EMAIL PROTECTED]... hi i have a mysql table with approx. 30 entries. I wanna get them(i know how to do that) and list them in a 2-column table.I have been trying to use a loop to do it. But it will only produce a1-column table. it's like entry 1 entey 2 entry 3 entry 4 etc Please help me so that i can get this : entry1 entry2 entry3 entry4 Thanks in advanced. Thank You,Jon Yaggiewww.design-monster.comAnd they were singing . . . '100 little bugs in the code100 bugs in the codefix one bug, compile it again101 little bugs in the code101 little bugs in the code . . .'And it continued until they reached 0
RE: [PHP] newbie algorithm help!!!!!
I use this code to do this kind stuff: - BEGIN --- $result=mysql_query(...); $columns=2; //Count of columns $table="TABLE\n"; $table.='TR'; $col=0; //current column //Draw table content while ($row=mysql_fetch_row($result)){ $table.='TD'.$row[0].'/TD'; $col++; if ($col=$columns) { $table.="/TR\nTR"; $col=0;} // Next row } //Correct last row, add or remove empty cells. if ($col) { $table.=str_repeat('TDnbsp;/TD',$columns-$col); //Add empty cells }else{ $table=substr($table,0,strlen($table)-10); //Remove empty row } $table.="/TR\n"; $table.='/TABLE'; echo $table; - END --- X -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] newbie algorithm help!!!!!
You'll probably get as many approaches as replies. How about the following; after you have connected to mysql and selected the database; $query = SELECT * FROM table; $result = mysql_query ($query) or die (Query b$query/b failed. The error message was .mysql_error ()); // The following wipes out any trace of a memory table in the working $table element $table = ''; while ($rows = mysql_fetch_row ($result)) { $table[] = $rows[0];// add the row to a working table } mysql_free_result($result) // always do this as soon as you can $top = sizeof($table); $halfway = ceil($top/2);// round up if odd $col2 = $halfway; echo TABLE; for($col1 = 0; $col1 $halfway; $col1++) { echo TRTD$table[$col1]/TD; if($col2 $top) echo TD$table[$col2++]/TD/TR; else echo TDnbsp;/TD/TR; // this avoids that hole in your grid } echo /TABLE; -Original Message- From: Zak Greant [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 23, 2001 1:22 PM To: McShen Cc: Php-General Subject: Re: [PHP] newbie algorithm help! McShen wrote: hi i have a mysql table with approx. 30 entries. I wanna get them(i know how to do that) and list them in a 2-column table. I have been trying to use a loop to do it. But it will only produce a 1-column table. it's like entry 1 entey 2 entry 3 entry 4 etc Please help me so that i can get this : entry1 entry2 entry3 entry4 The code is easier to understand than the explanation! :) $query = SELECT * FROM table; $result = mysql_query ($query) or die (Query b$query/b failed. The error message was . mysql_error ()); // Initialize a value to stored the table rows $table = ''; // Initialize a counter for the column number $column = 0; // Loop through the query results while ($rows = mysql_fetch_row ($result)) { // Put the contents of the field into a cell $cell = td$rows[0]/td; // If we are in column 0 if (0 == $column) { // Start the row $table .= tr$cell; } else { // End the row $table .= $cell/tr\n; } // Make the column number equal to // The whole number remainder left over // from dividing the value of $column // plus one by two $column = ($column + 1) % 2; } // Handle dangling rows if (1 == $column) { $table .= td/td/tr\n; } echo table$table/table; Good Luck! --zak -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] newbie algorithm help!!!!!
I wanna get them(i know how to do that) and list them in a 2-column table. I have been trying to use a loop to do it. But it will only produce a 1-column table. it's like entry 1 entey 2 entry 3 entry 4 etc Please help me so that i can get this : entry1 entry2 entry3 entry4 Try this: ? echo TABLE\n; for ($i = 0; $i num_rows($query); $i++ ) { $row = mysql_fetch_array($query); if ($i % 2) { echo TR\n; } echo TD$row[value]/TD\n; } echo /TABLE\n; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] newbie algorithm help!!!!!
hi i have a mysql table with approx. 30 entries. I wanna get them(i know how to do that) and list them in a 2-column table. I have been trying to use a loop to do it. But it will only produce a 1-column table. it's like entry 1 entey 2 entry 3 entry 4 etc Please help me so that i can get this : entry1 entry2 entry3 entry4 Thanks in advanced. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] newbie algorithm help!!!!!
?php $array[0] = 0; $array[1] = 0; $array[2] = 0; $array[3] = 0; $array[4] = 0; $array[5] = 0; echo table tr ; foreach($array as $pos = $val) if ( !(@$row++ % 2) AND $row != 1) echo /trtr td$val /td ; else echo td$val /td ; echo /tr /table ; ? -- Chris Lee [EMAIL PROTECTED] McShen [EMAIL PROTECTED] wrote in message 9gqm6o$g6n$[EMAIL PROTECTED]">news:9gqm6o$g6n$[EMAIL PROTECTED]... hi i have a mysql table with approx. 30 entries. I wanna get them(i know how to do that) and list them in a 2-column table. I have been trying to use a loop to do it. But it will only produce a 1-column table. it's like entry 1 entey 2 entry 3 entry 4 etc Please help me so that i can get this : entry1 entry2 entry3 entry4 Thanks in advanced. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]