Page 1 of 1

query does not show any record

Posted: Wed Dec 22, 2010 11:40 pm
by shafiq2626
Hi
I have multiple records in my table.
I want to detect all of them but not Administrator.
I use query below but this is not showing any result

Code: Select all

$rol='Administrator';
$sql = $this->MMdbobj->query("SELECT * FROM tbl_branchusers where branch_id=$_SESSION[branchid] and role!='".$rol."'");
		
Please check and response with thanks

Re: query does not show any record

Posted: Thu Dec 23, 2010 12:07 am
by social_experiment

Code: Select all

<?php $sql = $this->MMdbobj->query("SELECT * FROM tbl_branchusers where branch_id='". $_SESSION[branchid]. "' AND role!='".$rol."'"); ?>
What happens if you change the query so that it looks like the one above and do you receive any error messages (from your current query)?

Re: query does not show any record

Posted: Thu Dec 23, 2010 12:13 am
by shafiq2626
thanks for response
No any error display only empty query.
If i changed second condition then show all result.
I dont know what happen.

Re: query does not show any record

Posted: Thu Dec 23, 2010 12:54 am
by social_experiment

Code: Select all

<?php $_SESSION[branchid] ?>
I just noticed your session variable has no quotation marks, it should be $_SESSION['branchid']
Add the following to the end of your query

Code: Select all

<?php $sql = $this->MMdbobj->query("SELECT * FROM tbl_branchusers where branch_id='". $_SESSION[branchid]. "' AND role!='".$rol."'") or die(mysql_error()); ?>
If there is an error it should display

Re: query does not show any record

Posted: Thu Dec 23, 2010 1:29 am
by shafiq2626
Thanks
Its working now very well to write session with quote and also i removed die function then this worked.
So anyway thanks a lot to help.