Re: [PHP-DB] another PHP Sql question...
At 09:33 AM 8/29/2003, you wrote: > You can do: > while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) > { > extract ($row); > echo $feild_A . ' '; > > $row = $result->fetchRow(DB_FETCHMODE_ASSOC); > extract ($row); > echo $feild_A . ''; > } close, but doesn't handle odd row counts... while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { extract ($row); echo $feild_A; if( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) ) { extract ($row); echo ' ' . $feild_A . ''; } else { echo ''; /* optionally, add a 'last' here to skip extra db->call */ } } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] another PHP Sql question...
On Friday, Aug 29, 2003, at 02:14 US/Eastern, jsWalter wrote: But now I've been thrown a wrench in the form of double row display. my client wants... a b c d e f ... .. I need to create... row_1/feild_A row_1/feild_B row_2/feild_A row_2/feild_B ... And using the method of WHILE() doesn't cut it. Can some one enlighten me what syntax can I use to hit 2 rows at a time? Use "for". You'll need to know the number of rows returned by your query. Using MySQL, I find that out using mysql_num_rows($query). You'll need to adapt this for your database. So I would do it this way (probably not the most elegant, but it works): $your_query = mysql_query("select your data from your table",$db); // Run the query $row_count = mysql_num_rows($your_query); // Count rows returned $table_row_index = 1; // We'll use this to count your table rows echo "\r"; for ($i=0; $i<$row_count; $i++) { // Start with $i = 0, do while $i < number of rows, and increment $i with each loop $your_row = mysql_fetch_array($your_query); $field = $your_row['field']; echo "Row_$table_row_index/$field\r"; // This is all stuff you've done // so far we've just returned values from your query and written them to a table cell // Here's the trick: if $i is even, we're on the first cell of a row. If $i is odd, // we're on the second cell. We determine this with fmod($i/2); if the remainder // (the result) is 0, $i is even, if it's 1, $i is odd. if (fmod($i/2) != 1)) { // if $i is odd, we need to end this row and start another. echo "\r\r"; $table_row_index++; // Increment your row numbering. } } echo "\r"; Sorry about the weird comment wraps. I hope this makes sense. pjm -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] another PHP Sql question...
You can do: while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { extract ($row); echo $feild_A . ' '; $row = $result->fetchRow(DB_FETCHMODE_ASSOC); extract ($row); echo $feild_A . ''; } Tiberiu - Original Message - From: "jsWalter" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, August 29, 2003 8:14 AM Subject: [PHP-DB] another PHP Sql question... > I am querying a database just fine. > > Getting back what I expect, just fine. > > But now I've been thrown a wrench in the form of double row display. > > my client wants... > > a b > c d > e f >... > > Well, I've reached the end on my PHP/SQL knowledge (which really isn't all > that far!) > > Right now I'm doing (very much shortened)... > >// Query the database >$result = $db->query($strSql); > >// Always check that $result is not an error >if (DB::isError($result)) > die ($result->getMessage()); > >while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) >{ > extract ($row); > echo $feild_A . ''; >} > > OK, this is fine for a straight list! > > But I need to create... > > > row_1/feild_A > row_1/feild_B > > > row_2/feild_A > row_2/feild_B > >... > > And using the method of WHILE() doesn't cut it. > > Can some one enlighten me what syntax can I use to hit 2 rows at a time? > > Thanks > > Walter > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] another PHP Sql question...
One question: Do you mean that a & b are from the same column but are row 1 & 2 from your query result.? If so, you can possibly write a loop like so Dump all your records in an array; Start loop for as long you find records in array { Take the first record from your array and dump it into a variable (var1); Move the value from the variable var1 to another variable (var2); If both variables are set { Print the two variables with the html tags you want; Unset both variables; } } Add a handler to make sure you get the last records if it happens to be an od number off records; You'll have to do your own coding around this logic. Good luck Jack -Original Message- From: jsWalter [mailto:[EMAIL PROTECTED] Sent: Friday, August 29, 2003 9:46 AM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] another PHP Sql question... > "Boaz Yahav" <[EMAIL PROTECTED]> wrote in message > I'm not sure i understand the problem. > a,c,e come from one query result and b,d,f from another? No, they all come from the same table, but the same field name but from different rows of the database. > If it's all from the same query why not do : > > reult=mysql_query(". > > While($row = mysql_fetch_object($result)) { > Echo"$row->feild_A$row->feild_B"; > } > This method does not grap data from 2 rows at atime. I examined my example and noticed I goofed, it should have read... ... row_1/field_A row_2/field_A row_3/field_A row_4/field_A Same field, but diffeent rows. Sorry for the confusion. Walter -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] another PHP Sql question...
> "Boaz Yahav" <[EMAIL PROTECTED]> wrote in message > I'm not sure i understand the problem. > a,c,e come from one query result and b,d,f from another? No, they all come from the same table, but the same field name but from different rows of the database. > If it's all from the same query why not do : > > reult=mysql_query(". > > While($row = mysql_fetch_object($result)) { > Echo"$row->feild_A$row->feild_B"; > } > This method does not grap data from 2 rows at atime. I examined my example and noticed I goofed, it should have read... ... row_1/field_A row_2/field_A row_3/field_A row_4/field_A Same field, but diffeent rows. Sorry for the confusion. Walter -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] another PHP Sql question...
I'm not sure i understand the problem. Do a,c,e come from one query result and b,d,f from another? If it's all from the same query why not do : $result=mysql_query(". While($row = mysql_fetch_object($result)) { Echo"$row->feild_A$row->feild_B"; } Sincerely berber Visit http://www.weberdev.com/ Today!!! To see where PHP might take you tomorrow. Share your code : http://addexample.weberdev.com Search for PHP Code from your browser http://toolbar.weberdev.com -Original Message- From: jsWalter [mailto:[EMAIL PROTECTED] Sent: Friday, August 29, 2003 8:14 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] another PHP Sql question... I am querying a database just fine. Getting back what I expect, just fine. But now I've been thrown a wrench in the form of double row display. my client wants... a b c d e f ... Well, I've reached the end on my PHP/SQL knowledge (which really isn't all that far!) Right now I'm doing (very much shortened)... // Query the database $result = $db->query($strSql); // Always check that $result is not an error if (DB::isError($result)) die ($result->getMessage()); while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { extract ($row); echo $feild_A . ''; } OK, this is fine for a straight list! But I need to create... row_1/feild_A row_1/feild_B row_2/feild_A row_2/feild_B ... And using the method of WHILE() doesn't cut it. Can some one enlighten me what syntax can I use to hit 2 rows at a time? Thanks Walter -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php