Fwd: Re: mysql_num_rows, resource id #

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This much is working:

<?PHP
ini_set('error_reporting',E_All);
DEFINE ("host","localhost");
DEFINE ("user","root");
DEFINE ("password","password");
DEFINE ("database","questions");

$connection=mysql_connect(host,user,password) or die ('Could not connect' . mysql_error() );

$dbConnect=mysql_select_db('questions');
if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}

$result = mysql_query("Select answer from answers where studentID='A123456789'") or die(mysql_error());
$rows = mysql_num_rows($result);
echo $rows . "\n";
$answer = mysql_fetch_row($result);
foreach($answer as $a)
{
	echo $a;
}


?>
The output is 
1 
1			
which is correct.

One small step at a time, hopefully forward.

Richard.
--- Begin Message ---
Richard Dunne wrote:
In my code below, I am trying to verify that the query is selecting data from both rows of my answers table. I have run the query on my MySQL CLI and getting answers from both rows, but running this script I get $rows = 0. I can't figure out why its not returning 2 for the number of rows. It is not giving me any error msgs such as cannot connect.
Also can tell me where I can find documentation on resource id #, such as resource(5)?
<?PHP
DEFINE ("host","localhost");
DEFINE ("user","root");
DEFINE ("password","pasword");
DEFINE ("database","questions");

$connection=mysql_connect(host,user,password) or die ('Could not connect' . mysql_error() );

$dbConnect=mysql_select_db('questions',$connection);
if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}

$result = mysql_query("Select answer from answers where studentID='A123456789'") or die(mysql_error());
$rows = mysql_num_rows($result);
echo $rows;


?>
Still no luck then. Try selecting the DB without the connection parameter:

$dbConnect=mysql_select_db('questions');

And don't forget to set error_reporting(E_ALL) above your code.


--- End Message ---
-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux