PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
include "dbconn.php";
if ($update == "delete") {
$query = mysql_query ("delete FROM stocknotification where title = $title");
echo "<div class='admincompletedbox'>
<b>That comment was deleted.</b></div>";
}
echo "<table width='715' cellpadding='1' cellspacing='0' class='table' bordercolor='#FFFFFF' border='1' style='border-collapse: collapse;'>";
$resultcat = mysql_query ("SELECT DISTINCT title FROM stocknotification ORDER BY title");
if (mysql_num_rows($resultcat)==0)
{
echo "<tr><td><div class='sectionhead'>No one has yet posted a comment..</div></td></tr>";
}
else
{
while ($rowcat = mysql_fetch_object($resultcat))
{
echo "<tr><td colspan='2'><div class='sectionadminhead'>$rowcat->title</div></td></tr>";
$result = mysql_query ("SELECT * COUNT (title) as num_of FROM stocknotification WHERE title = '$rowcat->title'");
echo "<tr><td>";
echo $row['num_of'] ." have registered for this product.";
echo"</td><td>
</td>
</tr>";
}
mysql_free_result($result);
}
mysql_free_result($resultcat);
mysql_close($sqlconn);
echo "</table>";
Firstly I am getting this error:
Warning: mysql_free_result(): 5 is not a valid MySQL result resource in /usr/local/psa/home/vhosts/shop.co.uk/httpdocs/support/includes/notifications.inc on line 53
The database has two row of entries. One for one Title and one for a different Title.
It's basically doing a count of everything producing the different titles, but showing "2" for both.
S.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Nearly always, when you get the error "not a valid MySQL result resource", it means that your query failed, so any subsequent reference to its results causes this error. For this reason, you should always include error reporting in your code until you are confident that the database queries are working properly. Instead of:
$sql="SELECT * FROM foo WHERE bar=0";
$result=mysql_query($sql) or die("Query: $sql <br>" . mysql_error());
You don't need all those mysql_free_result() and mysql_close() functions. Those were necessary in early versions of PHP, but I think the consensus is that they are completely unnecessary with PHP4 and higher versions.