473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

php mysql query returning empty set

4
the following query is returning an empty set and i am not sure why:

if (($OutputPower == '75') || ($OutputPower == 'N/A'))
{
sql = Select * from $Tname1 WHERE 1".(($OutputPower != 'N/A') ? "AND `Output Power` = '$OutputPower'" : "" );

so essentially it includes Output Power in the query as long as the user did not enter N/A.

it works fine if i just have:
sql = Select * from $Tname1 WHERE 1 AND `Output Power` = '$OutputPower'";

but this only considers the case when user enters 75 W.

any thoughts are appreciated
Apr 9 '07 #1
8 6327
Motoma
3,237 Expert 2GB
If $OutputPower is N/A you will get an empty set.

the following query is returning an empty set and i am not sure why:

if (($OutputPower == '75') || ($OutputPower == 'N/A'))
{
sql = Select * from $Tname1 WHERE 1".(($OutputPower != 'N/A') ? "AND `Output Power` = '$OutputPower'" : "" );

so essentially it includes Output Power in the query as long as the user did not enter N/A.

it works fine if i just have:
sql = Select * from $Tname1 WHERE 1 AND `Output Power` = '$OutputPower'";

but this only considers the case when user enters 75 W.

any thoughts are appreciated
Apr 9 '07 #2
subu
4
If $OutputPower is N/A you will get an empty set.
not quite...following is the query when OutputPower == N/A:

sql = "SELECT * FROM $tname1 WHERE 1"

when i run this query directly on the database through phpMyAdmin, it returns all the rows, which is what should be happening....
Apr 10 '07 #3
ak1dnar
1,584 Expert 1GB
[PHP]Select * from $Tname1 WHERE `Output Power` = '$OutputPower'[/PHP]
Apr 10 '07 #4
Motoma
3,237 Expert 2GB
What exactly are you trying to accomplish with this query?
Apr 10 '07 #5
subu
4
its a web form with a sequence of questions (output power being one of them)....if the user chooses a certain value (eg:0-25 W), then i include it in my query and filter the results based on 0-25 W...if user chooses N/A, then i return all results...the following code works:
if ((($OutputPower == '0-25 W') ||($OutputPower == '25-50 W'))
{
$sql = "SELECT * FROM $tname1 WHERE `Output Power` = '$OutputPower'" .(($ICSupply != 'N/A') ? "AND `IC Supply` = '$ICSupply'" : "" ).(($HVStartup != 'N/A') ? "AND `HV Startup` = '$HVStartup'" : "" );

where IC Supply and HV Startup are other features which are either included or excluded from the query depending on user input....but i am considering the case when the user enters N/A for all questions, in which case the query would end up being:
$sql = "SELECT * FROM $tname1 WHERE 1"

this should work but is not...
Apr 10 '07 #6
Motoma
3,237 Expert 2GB
Your best bet would be to echo your SQL statement before you perform the query.
Apr 10 '07 #7
subu
4
thanks for the help
Apr 10 '07 #8
Motoma
3,237 Expert 2GB
thanks for the help
Anytime. Sorry I couldn't be of more use.
Apr 10 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: YoBro | last post by:
Hi, I am stuck and cannot think my way out of this small problem. I am coding in PHP but trying to write a MySql query. I have db that stores vehicles. I am trying to SELECT vehicles where...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
4
by: Federico | last post by:
Hi everybody, I'm evaluating the possibility of using MySQL 5.0 as a database backend for an application we are doing and I'd like to have hardware requirements rough estimates and/or real world...
7
by: eholz1 | last post by:
Hello PHP group, Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0 running on Linux (Redhat Fedora Core 6). All that works fine. I would like to be able to "call" a stored...
8
by: The Natural Philosopher | last post by:
This is so weird. What I am trying to do is to upload files and stuff them in a mysql database. Everything works except the file content is zero. using the load_file command from mysql...
0
by: exclaim | last post by:
Apologies if this is not the right forum. I have an application written originally to work with MySQL which now has to be extended to work with MSSQL also. I have modified all my database calls...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.