query does not show any record

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

query does not show any record

Post 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
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: query does not show any record

Post 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)?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Re: query does not show any record

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: query does not show any record

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Re: query does not show any record

Post 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.
Post Reply