Re: [PHP-DB] query + loop problem
Nice one folks! Thanks for your help - it's amazing what happens to one's brain once you start to think about the problem in hand enough (enough that is, to attmept to make it make sense to others!..) - I sussed the problem, using a similar method described to me my several of you. (and a little bit of RFTM on my part r.e: mysql_fetch_assoc() and mysql_fetch_array() ... Many thanks for your help. Russ On Wed, 28 Nov 2001 17:49:54 +0200 Andrey Hristov <[EMAIL PROTECTED]> wrote: > echo "\r\n"; > while($row = mysql_fetch_assoc($result)) { // if assoc is not available - will work >but double > results foreach($row as $key => $value){ > echo "$key$value\r\n"; } > }//end loop echo "\r\n"; > > HTH > Regards, Andrey Hristov > IcyGEN Corporation http://www.icygen.com > BALANCED SOLUTIONS > > - Original Message - > From: "Russ Michell" <[EMAIL PROTECTED]> > To: <[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: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > > > -- > PHP Database 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] > #---# "Believe nothing - consider everything" Russ Michell Anglia Polytechnic University Webteam Room 1C 'The Eastings' East Road, Cambridge e: [EMAIL PROTECTED] w: www.apu.ac.uk/webteam www.theruss.com #---# -- PHP Database 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-DB] query + loop problem
Try using mysql_query to describe the table in question (describe $table), and use the output as a list of field names (and types). I wrote a generic script to do this for an app... can provide if needed (although it sure looks a little hacked right now, hmmm) -db Russ Michell wrote: > Hi there everyone: > > I have a generic query containing variables, substituted for values dependant upon >specific > circumstances: > > //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%'"; > } > //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: > > //loop using hard-coded variables > while($row = mysql_fetch_array($result)) { > $field1 = $row[fieldname1]; > $field2 = $row[fieldname2]; //etc > }//end while loop > > I'd like to be able to have this dynamically enabled as below: > > //loop using relevant field names to display correct page content > while($row = mysql_fetch_array($result)) { > > //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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- -- Dan Barton Terrestrial Program Biologist Asst. Data Manager Point Reyes Bird Observatory http://www.prbo.org [EMAIL PROTECTED] [EMAIL PROTECTED] -- PHP Database 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-DB] query + loop problem
echo "\r\n"; while($row = mysql_fetch_assoc($result)) { // if assoc is not available - will work but double results foreach($row as $key => $value){ echo "$key$value\r\n"; } }//end loop echo "\r\n"; HTH Regards, Andrey Hristov IcyGEN Corporation http://www.icygen.com BALANCED SOLUTIONS - Original Message - From: "Russ Michell" <[EMAIL PROTECTED]> To: <[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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP Database 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-DB] query + loop problem
Hi there everyone: I have a generic query containing variables, substituted for values dependant upon specific circumstances: //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%'"; } //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: //loop using hard-coded variables while($row = mysql_fetch_array($result)) { $field1 = $row[fieldname1]; $field2 = $row[fieldname2]; //etc }//end while loop I'd like to be able to have this dynamically enabled as below: //loop using relevant field names to display correct page content while($row = mysql_fetch_array($result)) { //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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]