Re: Re: Database Problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jun 17, 2012 at 5:55 PM, Ethan Rosenberg <ethros@xxxxxxxxxxxxx> wrote:
> At 04:21 PM 6/17/2012, Jim Giner wrote:
>
>> "Ethan Rosenberg" <ethros@xxxxxxxxxxxxx> wrote in message
>> news:0M5S00MGD2BH7C60@xxxxxxxxxxxxxxxxxxxxxx...
>> > At 03:30 PM 6/17/2012, Jim Giner wrote:
>> >>"Ethan Rosenberg" <ethros@xxxxxxxxxxxxx> wrote in message
>> >>news:0M5R005QYZRNMC40@xxxxxxxxxxxxxxxxxxxxxx...
>> >> > Dear List -
>> >> >
>> >>
>> >> >
>> >> > The same query in a PHP program will only give me results for MedRec
>> >> > 10003
>> >> >
>> >>
>> >>why the "where 1" clause?  Do you know what that is for?
>> > =================
>> > Dear Jim
>> >
>> > Thanks
>> >
>> > As I understand, to enable me to concatenate phases to construct a
>> > query.
>> >
>> > The query does work in MySQL fro the terminal.
>> >
>> > Ethan
>> >
>>
>> I don't think so.  All it does is return one record.  The where clause
>> defines what you want returned.  A '1' returns one record, the first one.
>> #10003
>>
>> I wonder why you think "where 1" enables concatenation??  A query (IN
>> SIMPLE
>> TERMS PEOPLE) is simply a SELECT ion of fields from a group of tables,with
>> a
>> WHERE clause to define the criteria to limit the rows, and an ORDER BY to
>> sort the result set.  More complex queries can include GROUP BY when you
>> are
>> including summary operators such as SUM(fldname) or MAX(fldname), or a
>> JOIN
>> clause, or a host of other clauses that make sql so powerful.  In your
>> case
>> I think you copied a sample query that (they always seem to be displayed
>> with a 'where 1' clause) and left the "1" on it.  To summarzie:
>>
>> SELECT a.fld1, a.fld2,b.fld1 from table1 as a, table2 as b WHERE a.key
>> >100
>> and a.key = b.key ORDER BY a.fld1
>>
>> I"m no expert, but hopefully this makes it a little less complex for you.
>
> ================
>
> This is a suggestion I received from this list -
> +++++++++++++++++++++
>>>
>>> $query = "select * from Intake3 where ";
>>
>>
>> Maybe I missed it, but you need to have a 1 after the where part in your
>> select.  So...
>>
>> $query = "SELECT * FROM Intake3 WHERE 1 ";
>
> ++++++++++++++++++++++++++++
>
> I must stress that the query works from the terminal, and fails in the PHP
> code.
>
> My question is why?????
>
> Ethan

First off, all "where 1" does is make the statement always true. If
you don't believe that, try this query:

SELECT * FROM Intake3 WHERE 1;

in mysql and contrast with:

SELECT * FROM Intake3;

you should see identical results.

Secondly, you need to look at where you are gathering the return from
the query. You show:

$result = mysqli_query($cxn,$query);

but you aren't showing us what you do with $result, as in where you
fetch the rows and process them. I'm dubious that the query is in fact
only returning one record. But you can check by echoing
mysqli_num_rows($result). (I think; I never use the procedural
version, opting to use the object version instead.)

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux