Re: [PHP-DB] query + loop problem From: Andrey Hristov (ahristov <email protected>)
Date: 11/28/01

echo "<table>\r\n";
while($row = mysql_fetch_assoc($result)) { // if assoc is not available - will work but double results
    foreach($row as $key => $value){
        echo "<tr><td>$key</td><td>$value</td></tr>\r\n";
    }
}//----end loop
echo "</table>\r\n";

HTH
Regards,
Andrey Hristov
IcyGEN Corporation
http://www.icygen.com
BALANCED SOLUTIONS

----- Original Message -----
From: "Russ Michell" <r.j.michell <email protected>>
To: <php-db <email protected>>
Sent: Wednesday, November 28, 2001 5:36 PM
Subject: [PHP-DB] query + loop problem

> Hi there everyone:
>
> I have a generic query containing variables, substituted for values dependant upon specific
> circumstances:
>
> file://----query the DB on the basis of searches employing text input fields (LIKE)
> if($sql_clause == 'LIKE') {
> $sql = "SELECT * FROM $table WHERE $field $sql_clause '%$query%'";
> }
> file://----query the DB on the basis of searches employing select menus ('=')
> else if($sql_clause == '=') {
> $sql = "SELECT * FROM $table WHERE $field $sql_clause '$query'";
> }
> $result = mysql_query($sql,$connect) or printerror("Query Failure!","06");
> $numrows = mysql_num_rows($result);
>
>
> Instead of the usual 'hard-coded' method within the loop as below:
>
> file://----loop using hard-coded variables
> while($row = mysql_fetch_array($result)) {
> $field1 = $row[fieldname1];
> $field2 = $row[fieldname2]; file://----etc
> }//----end while loop
>
> I'd like to be able to have this dynamically enabled as below:
>
> file://----loop using relevant field names to display correct page content
> while($row = mysql_fetch_array($result)) {
>
> file://----generic method of extracting rownames according to '$table' (above) goes here
>
> }//----end loop
>
> Does anyone have a clue how to do this???
>
> Many Thanks!
> Russ
>
>
> #-------------------------------------------------------#
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe <email protected>
> For additional commands, e-mail: php-db-help <email protected>
> To contact the list administrators, e-mail: php-list-admin <email protected>
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe <email protected>
For additional commands, e-mail: php-db-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>