[PHP-DB] How can I get the number of entries retrieved by a "SELECT - FROM" Thanks!

2003-06-21 Thread ed anderson
Dell 4500, mem 1g, disk 45g, mhz 2g, Mysql-3.23.54a-linux-i686, PHP-4.30,
httpd_2.0.44

Thanks to Paul DuBois, Roger Davis, Helen Sallee, Ronan Chilvers, and Edward
Dudlik
for thier response to my question.  I've included the a (one of many?)
snippit of code that
I've decided to use as a pattern for a (class) to be developed.

Thanks again:

Ed anderson

sample.php

sample.php 
see page 405 "msql cookbook" for code used to develop $h_nrows 
"; $tn = "";
$r = ""; $rn =  "";
#
$h_query = " SELECT  *
FROM employees
  WHERE  id=$h_id1  OR  id=$h_id2  OR  id=$h_id3";
 printf("mysql_query: $h_query\n");
#
$h_result_id =  mysql_query($h_query, $mysql_connect);
 if(! $h_result_id)
  die (" mysql_query h $mysql_connect\n");
 $h_nrows = @mysql_num_rows ($h_result_id);
#
if ($h_nrows == 0)
 print ("Note: h query has no result set\n");
  $dat_h_id  = mysql_result($h_result_id,$i,"id");
  $dat_first = mysql_result($h_result_id,$i,"first");
  $dat_last  = mysql_result($h_result_id,$i,"last");
#
#
#
echo "";
for ($i = 0; $i < $h_nrows; $i++)
{ echo "$r";
   $dat_h_id  = mysql_result($h_result_id,$i,"id");
echo "$t  $dat_h_id$tn";
$dat_first = mysql_result($h_result_id,$i,"first");
echo "$t  $dat_first$tn";
$dat_last  = mysql_result($h_result_id,$i,"last");
echo "$t  $dat_last $tn";
echo "$t  $i$tn";
echo "$t  $h_nrows  $tn";
echo "$rn";
} echo "";
#
?>

sample.php end 



using mozilla browser -http://127.0.0.1/sample.php

sample.php
see page 405 "msql cookbook" code used to develop $h_nrows
mysql_query: SELECT * FROM employees WHERE id=3 OR id=4 OR id=5
3 Brad   Johnson 0 3
4 aa   bb 1 3
5 WW   EE 2 3


sample.php end


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



Re: [PHP-DB] How can I get the number of entries retrieved by a"SELECT - FROM"

2003-06-13 Thread Ronan Chilvers
On 12 Jun,2003 at 18:21 Becoming Digital wrote:

> > The PHP "SELECT FROM" below (before snip) listed the expected data.
> > Is there a way to get the digit "3" into a PHP variable
> 
> $data = mysql_result($result,1,"name"));
> 
> 
> > How do I trap or collect or save the digit "3" generated the
> > mysql "SELECT COUNT(*)" statement below?
> 


Or do 

SELECT COUNT(*) AS mycount ...

which will give you a result set with, eg: an array key called 'mycount' that you can 
grab.

Ronan

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



Re: [PHP-DB] How can I get the number of entries retrieved by a"SELECT - FROM"

2003-06-12 Thread Becoming Digital
> The PHP "SELECT FROM" below (before snip) listed the expected data.
> Is there a way to get the digit "3" into a PHP variable

$data = mysql_result($result,1,"name"));


> How do I trap or collect or save the digit "3" generated the
> mysql "SELECT COUNT(*)" statement below?

Same as above.  Store it in a PHP variable and retrieve it later.

Edward Dudlik
Becoming Digital
www.becomingdigital.com


- Original Message -
From: "ed anderson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, 12 June, 2003 17:58
Subject: [PHP-DB] How can I get the number of entries retrieved by a "SELECT -
FROM"


Dell 4500, mem 1g, disk 45g, mhz 2g, Mysql-3.23.54a-linux-i686, PHP-4.30,
httpd_2.0.44



1. How do I trap or collect or save the digit "3" generated the
   mysql "SELECT COUNT(*)" statement below?

2. The PHP "SELECT FROM" below (before snip) listed the expected data.
   Is there a way to get the digit "3" into a PHP variable?

SELECT h_id, name FROM tbtm # displays
  WHERE h_id="1"# three
 OR h_id="2"   # lines
 OR h_id="3";  # of data

SELECT COUNT(*) FROM tbtm   # displays
  WHERE h_id='1'# the
 OR h_id='2'# digit
 OR h_id='3';   # three

+--+
| COUNT(*) |
+--+
|3 |
+--+
1 row in set (0.00 sec)



 The next PHP is the same as the "SELECT FROM" above.
\n",  mysql_result($result,1,"h_id"));
 printf("name: %s\n",mysql_result($result,1,"name"));

#
?>


Thanks

[EMAIL PROTECTED]


--
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



[PHP-DB] How can I get the number of entries retrieved by a "SELECT - FROM"

2003-06-12 Thread ed anderson
Dell 4500, mem 1g, disk 45g, mhz 2g, Mysql-3.23.54a-linux-i686, PHP-4.30,
httpd_2.0.44



1. How do I trap or collect or save the digit "3" generated the
   mysql "SELECT COUNT(*)" statement below? 
   
2. The PHP "SELECT FROM" below (before snip) listed the expected data.
   Is there a way to get the digit "3" into a PHP variable?

SELECT h_id, name FROM tbtm # displays
  WHERE h_id="1"# three
 OR h_id="2"   # lines
 OR h_id="3";  # of data

SELECT COUNT(*) FROM tbtm   # displays
  WHERE h_id='1'# the
 OR h_id='2'# digit
 OR h_id='3';   # three

+--+
| COUNT(*) |
+--+
|3 |
+--+
1 row in set (0.00 sec)



 The next PHP is the same as the "SELECT FROM" above.
\n",  mysql_result($result,1,"h_id"));
 printf("name: %s\n",mysql_result($result,1,"name")); 

#
?>


Thanks

[EMAIL PROTECTED]


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