Jump to content


Photo

problem with php/mysql select statement


  • Please log in to reply
5 replies to this topic

#1 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 24 April 2006 - 10:17 AM

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)







#2 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 24 April 2006 - 11:17 AM

I hope that person is fictional, otherwise he just had his personal details splattered all over the internet.

Try this:

$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]'";

wisewood: proven fact, I am both wise, and wooden.

#3 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 24 April 2006 - 11:37 AM

nope it made no difference :(



#4 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 24 April 2006 - 12:40 PM

$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.
wisewood: proven fact, I am both wise, and wooden.

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 24 April 2006 - 01:57 PM

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

Does any error print after you do the above?

Ken

#6 miz_luvly@hotmail.com

miz_luvly@hotmail.com
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 26 April 2006 - 10:01 AM

I have managed to fix it

thanx





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users