<?php
mysql_connect("localhost","phplanet","password");
mysql_select_db("phplanet_codebank");
function countnum($cat)
{
$getamount = mysql_query("SELECT * FROM code WHERE category='$cat'");
$collect = mysql_affected_rows($getamount);
echo "($collect)";
}
?>
The above code is for my PHP site. I'm having trouble with it though. The function will count how many code snippets are in the given category, for example...
countnum(databases)
will count how many code snippets are in the databases category. However it only shows the brackets () and nothing in between, please help!
URL is >>> <!-- m --><a class="postlink" href="http://www.phplanet.co.uk/code.phpbecause">http://www.phplanet.co.uk/code.phpbecause</a><!-- m --> mysql_affected_rows is only used for delete, insert, update
not select queries.So I need to use mysql_fetch_array
edit
-----
do i need to update the sql query to use the sum() thing?http://www.php.net/manual/en/function.mysql-num-rows.phpOriginally posted by Rydberg
<!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.mysql-num-rows.php">http://www.php.net/manual/en/function.m ... m-rows.php</a><!-- m -->
Thank you very much, appriciate it.
mysql_connect("localhost","phplanet","password");
mysql_select_db("phplanet_codebank");
function countnum($cat)
{
$getamount = mysql_query("SELECT * FROM code WHERE category='$cat'");
$collect = mysql_affected_rows($getamount);
echo "($collect)";
}
?>
The above code is for my PHP site. I'm having trouble with it though. The function will count how many code snippets are in the given category, for example...
countnum(databases)
will count how many code snippets are in the databases category. However it only shows the brackets () and nothing in between, please help!
URL is >>> <!-- m --><a class="postlink" href="http://www.phplanet.co.uk/code.phpbecause">http://www.phplanet.co.uk/code.phpbecause</a><!-- m --> mysql_affected_rows is only used for delete, insert, update
not select queries.So I need to use mysql_fetch_array
edit
-----
do i need to update the sql query to use the sum() thing?http://www.php.net/manual/en/function.mysql-num-rows.phpOriginally posted by Rydberg
<!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.mysql-num-rows.php">http://www.php.net/manual/en/function.m ... m-rows.php</a><!-- m -->
Thank you very much, appriciate it.