PHP Programming > General PHP Help
What's wrong with this query?
traydavid:
When the code below is called, the admin has just logged in and is only supposed to see the products linked to his/her customer id number, or custid.
The admins table contains admins who have a unique adminid and a customer id, or custid. This custid number is associated with a unique customer (my clients) in the customers table. I'm using the customers table to 'associate' the admins to the customers.
I'm trying to make the php get the custid number by saying SELECT custid from customers (my clients table) where adminid=adminid (the admin id of the person who just logged in).
This code is pulling ALL the products from the products table, regardless of which admin is logged in. A serious problem. Any help is appreciated. Thanks.
--- PHP Code: ---<?php
echo "<label><h3>Browse Procucts:<br></h3> </label><br>\n";
$query="SELECT custid from customers where adminid=adminid";
$result=mysql_query($query);
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
$custid = $row['custid'];
$query2="SELECT count(prodid), productname FROM products WHERE custid = $custid";
$result2 = mysql_query($query2);
$row=mysql_fetch_array($result2);
$total = $row[0];
$entreename = $row['productname'];
echo "<a href=\"smalladmin.php?content=testpage&custid=$custid\">$productname</a> ($total)<br>\n";
}
?>
--- End code ---
Sarthak Patel:
--- Quote ---hello traydavid,
i think your $query is wrong.
$adminid is define some where or you have to get admin id from database.
And your $query should be like this
$query="SELECT custid from customers where adminid=".$adminid;
AND
your $query2 is like this
$query2="SELECT count(prodid), productname FROM products WHERE custid =".$custid;
And Replace below code
echo "<a href=\"smalladmin.php?content=testpage&custid=$custid\">$productname</a> ($total)<br>\n";
with my code
echo "<a href=\"smalladmin.php?content=testpage&custid=".$custid."\">".$productname."</a> (".$total.")<br>\n";
i hope this will helpful for you and direct you in correct direction.
Reply your feedback
~~SR~~
--- End quote ---
Autobrofaw:
Yes, really. So happens. Let's discuss this question. Here or in PM.
ErnieAlex:
Also, one thing TrayDavid, is you use $row in the first query and again in the second inside a While using the $row.. Can't do that!
You use While ($row=.... and INSIDE that while, you change $row... So, the while will get messed up...
You change $query to $query2, but, not $row... Hope that helps, too...
Sarthak Patel:
--- Quote ---hello Autobrofaw,
sure we can discuss this question here as well as PM.
--- End quote ---
Navigation
[0] Message Index
[#] Next page
Go to full version