Doing a SELECT COUNT(P_ID) - help!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Darren Griffin
Forum Newbie
Posts: 4
Joined: Mon Nov 11, 2002 2:41 am

Doing a SELECT COUNT(P_ID) - help!

Post by Darren Griffin »

Hi

I'm trying run the following SQL statement against a MySQL database.

Code: Select all

SELECT COUNT(P_ID) FROM PACKAGES
No I know the SQL is correct, but what I can't do is display the result. I think this is largely due to my extreme lack of PHP knowledge. I can run and execute the SQL, but can't display the result. I'm using the code below. Could somebody explain why it isn't working and give me an example of hoiw it should be written? Better still, does anyone know of any comprehensive PHP/MySQL tutorials on the web they could point me to please?

<?
$rs = mysql_query("SELECT COUNT(P_ID) FROM PACKAGES") or die ("Query Failed");
$fv = $rs->Fields("P_ID");
print $fv->value;
?>

Thanks,

Darren.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

take a look at the example at http://www.php.net/manual/en/ref.mysql.php

mysql_query returns an identifier used by other mysql_...-function to retrieve the real data, e.g. mysql_fetch_row or mysql_fetch_object
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post by MeOnTheW3 »

$sql = "SELECT COUNT(P_ID) AS P_ID FROM PACKAGES";
$result = mysql_query($sql,$connection);
$returned = mysql_fetch_object($result);

$fv = $returned->P_ID;
Darren Griffin
Forum Newbie
Posts: 4
Joined: Mon Nov 11, 2002 2:41 am

Tickety Boo

Post by Darren Griffin »

Thanks folks, I'm all tickety boo now !

Ta muchly.

Darren.
Post Reply