You should use fieldnames in your selects... I'd imagine count(*) would be
slower just as select * is slower.

-jm

-----Original Message-----
From: Joe Sheble (Wizaerd) [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 16, 2001 9:46 AM
To: PHP
Subject: RE: [PHP] MySQL COUNT Won't Work


I do lots and lots of count()'s in PHP and have never had any problems... 
of course, I do it a bit differently than you did..

// I always have these in a top level include
$UserName = "noneYa";
$Password = "yeahRight";
$myDatabase = "uhhuh";

$dbConn = mysql_connect( "localhost", $UserName, $Password ) or die( 
"Cannot Connect To Database Server" );
mysql_select_db( $myDatabase ) or die( "Unable To Connect To Database: " . 
$myDatabase );
// up to here

// then I always make sure the file is included at the top of my page, and 
then call this query like this...
$qQuery = "SELECT Count(*) as nTotal FROM someDB";
$rQuery = mysql_query( $qQuery, $dbConn );
$qrQuery = mysql_fetch_array( $rQuery );
print( $qrQuery["nTotal"] );



At 11:37 AM 2/16/01 -0600, Jeff Oien wrote:
>That's not it. Get:
>Warning: Supplied argument is not a valid MySQL-Link resource in
>count.php3 on line 14
>Jeff Oien
>
> > Shouldn't that be
> >
> > $result = mysql_query($sql,$db)
> >       or die("Couldn't execute query.");
> >
> > So you're querying the database, and not the connection?
> >
> >
> > HTH
> > Jon
> >
> >
> > -----Original Message-----
> > From: Jeff Oien [mailto:[EMAIL PROTECTED]]
> > Sent: 16 February 2001 17:27
> > To: PHP
> > Subject: [PHP] MySQL COUNT Won't Work
> >
> >
> > I'm totally stuck on this code. I get the error
> > "Couldn't execute query." so I know where it's
> > failing but can't figure out what's wrong. I have
> > a database with 'title' as one of the fields. Based
> > on code in PHP Fast and Easy.
> > Jeff Oien
> >
> > <?php
> > $db_name = "Music";
> > $table_name = "music";
> >
> > $connection = mysql_connect("localhost", "xxxx", "xxxx")
> >       or die("Couldn't connect.");
> >
> > $db = mysql_select_db($db_name, $connection)
> >       or die("Couldn't select database.");
> >
> > $sql = "SELECT COUNT (title) FROM music";
> >
> > $result = mysql_query($sql,$connection)
> >       or die("Couldn't execute query.");  //<<error from here
> >
> > $count = mysql_result($result,0,"count(title)");
> >
> > echo "$count";
> > ?>
> >
> > --
> > PHP General 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 General 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 General 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 General 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 General 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]

Reply via email to