Page 1 of 1

Doing a SELECT COUNT(P_ID) - help!

Posted: Mon Nov 11, 2002 2:41 am
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.

Posted: Mon Nov 11, 2002 2:56 am
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

Posted: Wed Nov 13, 2002 3:33 pm
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;

Tickety Boo

Posted: Mon Nov 18, 2002 3:25 am
by Darren Griffin
Thanks folks, I'm all tickety boo now !

Ta muchly.

Darren.