Jump to content

Recommended Posts

I am trying to control the items shown by selecting them by active = 0. I can get it to work. Any help would be appreciated.

<?php
		try
		{
		$sql = "SELECT company.co_name,
		company.active,
                co_info.customer_no,
                co_info.password,
		co_address,
                co_city,
                co_state,
                co_zip,
                host,
                ftp_name,
                ftp_password FROM company LEFT JOIN co_info ON company.id = co_info.id WHERE company.active = '0' ";
            
		$result = $dbh->query($sql);

Link to comment
https://forums.phpfreaks.com/topic/297785-selecting-only-those-with-active-0/
Share on other sites

Add a test on the query result to be sure it is True and not False. Also - your query selects some fields without a table qualifier. Are those fieldnames unique? Also - why would you want to retrieve the password? If this is a general query and not a logon query, why do you want to expose the password?

what is the data type of the active column? what are some of the values in it? and is there any chance that you imported that data into that column from a csv file or copy/pasted into a form field or you have an error in your code inserting the data and you could have some white-space characters (either a space or a tab) in the column in front of the data so that when the 'apparent/visible' value is converted to a number for the comparison, all the values end up being a zero, which results in a TRUE WHERE clause for every row?

  • Like 1

The first thing to try, per mac's point is to specify this, assuming that active is an integer type:

 

 

WHERE active = 0

 

If you specify '0' you are asking mysql to cast the value from an integer to a string for string comparison, which could help explain your odd result.

 

With that said, I think we need some confidence that you aren't confused about the nature of your schema and data, which frequently is the reason people have the issues you seem to be having, due to assumptions they made about their own database which turn out to be erroneous.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.