Here is my code:
//Connect to config file
include(dirname(__FILE__)."/../config.php");
//Connect to the database
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
//Get Total Products
$result = mysql_query("SELECT * FROM $dbProductsTable WHERE sub_cat = '$subcat'");
$TotalProducts = mysql_num_rows($result);
//Create Pages
if (TotalProducts <= 12){
$pages = '';
}else{
$pages = " <ul id=\"pagination\" class=\"group\">
<li><a class=\"current\" href=\"#\">1</a></li>
<li><a href=\"#\">2</a></li>
<li><a href=\"#\">3</a></li>
<li><a href=\"#\">4</a></li>
</ul>";
}
//Get from sql info we need
$sql = mysql_query("SELECT * FROM $dbProductsTable WHERE sub_cat = '$subcat' LIMIT 0 , 12");
$data = mysql_query($sql) or die(mysql_error());
//Make first letter UpperCase
$subcatname = ucfirst($subcat);
//Get Basket Count
$basketcount = count($_COOKIE['products']);
//Get All Products
while($row = mysql_fetch_array($data))
{
//Get Product Path
$productPath = $Domain.'/'.strtolower($row['category']).'/'.str_replace(" ","",$row['product_name']).'_'.$row['product_id'];
//Build Products List
$products = $products." <li class=\"all-products-list-item\">
<a href=\"$productPath\" title=\"{$row['product_name']}\"><img src=\"$ProductImageFolder{$row['thumb_image']}\" alt=\"{$row['product_name']}\" border=\"0\" height=\"245\" width=\"180\"/></a>
<h3><a href=\"$productPath\">{$row['product_name']}</a></h3>
<p>£{$row['price']}</p>
</li>\n";
}
and here is the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1
i have tried running it throught phpmyadmin and the sql works perfect, i cant find what the problem is ?
Thanks
Here is the error:
Change it to
You are running a query with
$sql = mysql_query(...), and are assigning the resource to the variable$sql. Right after that, you try to run a query with the variable$sqlas a parameter. At this point$sqlwill contain the resource, not the query.