Jump to content

Archived

This topic is now archived and is closed to further replies.

miz_luvly@hotmail.com

problem with php/mysql select statement

Recommended Posts

Hi guyz

I am in need of help with my php/mysql. It has given me headaches. It works fine in mysql but not in php. basically i want to filter result for the user who is currently logged in. Can someone plzzzzzzz have a look and tell me where im going wrong. Thanks in advance

I have a following select statement
$sql = "select users.rep_name, rep_table.rep_name, rep_table.rep_id, customer_table.* " .
"from customer_table, rep_table, users ".
" where users.rep_name=rep_table.rep_name and customer_table.rep_id=rep_table.rep_id and account_no like '".$_GET['keywords']."'";

when i enter account_no it should only filter information associated with that particular "rep_name" if matched other wise it should return nothing but it still return results.


in mysql it works:
mysql> select users.rep_name, rep_table.rep_name, rep_table.rep_id, customer_tab
le.* from customer_table, rep_table, users where users.rep_name=rep_table.rep_na
me and customer_table.rep_id=rep_table.rep_id and account_no=1564;
+---------------+---------------+--------+------------+-------------------------
-+-----------------+----------+-----------------+----------+-----------+--------
------+------------+--------+--------------+
| rep_name | rep_name | rep_id | ACCOUNT_NO | CUSTOMER_NAME
| ADDRESS1 | ADDRESS2 | ADDRESS3 | ADDRESS4 | POST_CODE | TELEPHO
NE_NO | RUN_NUMBER | REP_ID | CONTACT_NAME |
+---------------+---------------+--------+------------+-------------------------
-+-----------------+----------+-----------------+----------+-----------+--------
------+------------+--------+--------------+
| Alan Fishwick | Alan Fishwick | 3 | 1564 | Southend Bathroom Centre
| 187 London Road | NULL | Southend-On-Sea | Essex | SS1 1PW | 01702 4
33445 | 9 | 3 | Mark Daniels |
+---------------+---------------+--------+------------+-------------------------
-+-----------------+----------+-----------------+----------+-----------+--------
------+------------+--------+--------------+
1 row in set (0.00 sec)

OR

mysql> select users.rep_name, rep_table.rep_name, rep_table.rep_id, customer_tab
le.* from customer_table, rep_table, users where users.rep_name=rep_table.rep_na
me and customer_table.rep_id=rep_table.rep_id and account_no=109819;
Empty set (0.00 sec)





Share this post


Link to post
Share on other sites
I hope that person is fictional, otherwise he just had his personal details splattered all over the internet.

Try this:

[code]
$query = "SELECT users.rep_name, rep_table.rep_name, rep_table.rep_id, customer_table.* FROM customer_table, rep_table, users WHERE users.rep_name = rep_table.rep_name AND customer_table.rep_id = rep_table.rep_id AND account_no LIKE '$_GET[keywords]'";
[/code]

Share this post


Link to post
Share on other sites
$query = "select users.rep_name, rep_table.rep_name, rep_table.rep_id, customer_table.* from customer_table, rep_table, users where users.rep_name=rep_table.rep_name and customer_table.rep_id=rep_table.rep_id and account_no=1564";


cant see any reason for it not to work.
have you tried using it as above to make sure it works right using static data, and not variables.

it might be the variable giving you grief.

Share this post


Link to post
Share on other sites
Do you have an "or die" clause on the mysql_query() function call? If not do something like:
[code]<?php
$results = mysql_query($sql) or die('There was a problem in the query: ' . $sql . '<br>' . mysql_error());
?>[/code]

Does any error print after you do the above?

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.