RE: [PHP-DB] Can't use field names in print
you need to use the *_fetch_array() functions i.e. if you are using MySQL $SQL = something; // build SQL query $result = mysql_query($SQL); // execute query, save all results in $result $firstResult = mysql_fetch_array($result); // create an array containing each returned record // subsequent calls to mysql_fetch_array($result) will get each record HTH Beau PS please excuse email butchering my single-line comments :) // -Original Message- // From: planomax [mailto:[EMAIL PROTECTED]] // Sent: Monday, 14 January 2002 10:13 AM // To: [EMAIL PROTECTED] // Subject: [PHP-DB] Can't use field names in print // // // To output each row, this works: // // print($row[0] - $row[1] - $row[2]br); // // But using the table's field names, I don't see anything: // // $ID=$row[ID]; // $test1=$row[test1]; // $test2=$row[test2]; // print ($ID - $test1 - $test2br); // // I'm used to using Cold Fusion and want to learn PHP. Any // help would be // appreciated. Thanks. // Pete // // // // -- // 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]
Re: [PHP-DB] Can't use field names in print
Thanks for the quick response. I left out the part you mention, here is the whole code (the one that works); ? $user = root; $pw = ; $db = pete; $mysql_access = mysql_connect(localhost, $user, $pw); mysql_select_db($db, $mysql_access); $result = mysql_query(select test2,test1,id from test, $mysql_access); while($row = mysql_fetch_row($result)) { print($row[0] - $row[1] - $row[2]br); } ? I just can't seem to be able to access the array using the column names from the table. Pete Beau Lebens [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... you need to use the *_fetch_array() functions i.e. if you are using MySQL $SQL = something; // build SQL query $result = mysql_query($SQL); // execute query, save all results in $result $firstResult = mysql_fetch_array($result); // create an array containing each returned record // subsequent calls to mysql_fetch_array($result) will get each record HTH Beau PS please excuse email butchering my single-line comments :) // -Original Message- // From: planomax [mailto:[EMAIL PROTECTED]] // Sent: Monday, 14 January 2002 10:13 AM // To: [EMAIL PROTECTED] // Subject: [PHP-DB] Can't use field names in print // // // To output each row, this works: // // print($row[0] - $row[1] - $row[2]br); // // But using the table's field names, I don't see anything: // // $ID=$row[ID]; // $test1=$row[test1]; // $test2=$row[test2]; // print ($ID - $test1 - $test2br); // // I'm used to using Cold Fusion and want to learn PHP. Any // help would be // appreciated. Thanks. // Pete // // // // -- // 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]
RE: [PHP-DB] Can't use field names in print
you should be able to just change the mysql_fetch_row to a mysql_fetch_array and then use the names rather than the numbers in your print (modified below, not tested :) // ? // $user = root; // $pw = ; // $db = pete; // // $mysql_access = mysql_connect(localhost, $user, $pw); // mysql_select_db($db, $mysql_access); // // $result = mysql_query(select test2,test1,id from test, // $mysql_access); // while($row = mysql_fetch_array($result)) // { // print($row[field1] . - . $row[field2] . - . $row[field3] . br); // } // ? /beau -- 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]