Forum Moderators: coopster
this is what they wrote:
Now we will run a query to find out how many items (rows) match the category being viewed. This will be the total amount of items that can be showed.This query can look something like this:
$q = mysql_query("SELECT * FROM `code` WHERE `type` = '".addslashes($_GET['cat'])."'");
if(!$q) die(mysql_error());
$total_items = mysql_num_rows($q);
I change the query for my mysql table:
<?php
// Make a MySQL Connection
// Connects to your Database
include 'library/config.php';
include 'library/opendb.php';
$q = mysql_query("SELECT * FROM pharmacy WHERE id = '".addslashes($_GET['cat'])."'");
if(!$q) die(mysql_error());
$total_items = mysql_num_rows($q);
echo " total = ".$total_items;
include 'library/closedb.php';
?>
now when i run the query the oupt is:
total = 0
but there are many rows in the table pharmacy, where is the problem and what .addslashes means here?
[edited by: jatar_k at 12:54 am (utc) on Dec. 2, 2006]
[edit reason] no urls thanks [/edit]
Also, do not use addslashes [us2.php.net] to escape the variable within the query, use mysql_real_escape_string [us2.php.net].