Query Help

I have four fields, "name", "date", "task", and "title" - and am
trying to PHP code where if I click 'All', all rows for 'Bob' followed
by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
would be displayed alphabetically (by name), with all of Bob's rows
grouped together and then all of Jim's and then all of Joe's, etc
(versus the way they may reside in the MySQL table).

My query works well for individual names and also for 'All' but it
would look and be easier to read if I could group the rows by name and
maybe list alphabetically. My 'All' code portion currently looks like
this:

$query =
"SELECT *
FROM $table
WHERE 1 = 1 ";
if($name != "All") $query .= "and name = '".$name."'";

$result = mysql_query($query);


thanks for any help...
John
jcage [ Sa, 03 November 2007 02:53 ] [ ID #1861659 ]

Re: Query Help

jcage [at] lycos.com wrote:
> I have four fields, "name", "date", "task", and "title" - and am
> trying to PHP code where if I click 'All', all rows for 'Bob' followed
> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
> would be displayed alphabetically (by name), with all of Bob's rows
> grouped together and then all of Jim's and then all of Joe's, etc
> (versus the way they may reside in the MySQL table).
>
> My query works well for individual names and also for 'All' but it
> would look and be easier to read if I could group the rows by name and
> maybe list alphabetically. My 'All' code portion currently looks like
> this:
>
> $query =
> "SELECT *
> FROM $table
> WHERE 1 = 1 ";
> if($name != "All") $query .= "and name = '".$name."'";
>
> $result = mysql_query($query);
>
>
> thanks for any help...
> John
>
>

You're asking about SQL, not PHP. Try comp.databases.mysql.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Sa, 03 November 2007 03:12 ] [ ID #1861660 ]

Re: Query Help

jcage [at] lycos.com wrote:
> I have four fields, "name", "date", "task", and "title" - and am
> trying to PHP code where if I click 'All', all rows for 'Bob' followed
> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
> would be displayed alphabetically (by name), with all of Bob's rows
> grouped together and then all of Jim's and then all of Joe's, etc
> (versus the way they may reside in the MySQL table).
>
> My query works well for individual names and also for 'All' but it
> would look and be easier to read if I could group the rows by name and
> maybe list alphabetically. My 'All' code portion currently looks like
> this:
>
> $query =
> "SELECT *
> FROM $table
> WHERE 1 = 1 ";
> if($name != "All") $query .= "and name = '".$name."'";
>
> $result = mysql_query($query);
>
>
> thanks for any help...
> John
>
You're probably going to want to use one of the "joins". 'LEFT JOIN',
'INNER JOIN', etc. Then 'ORDER BY name DESC'. This will give you your
results in alphabetical order.
Chris Gorospe [ Sa, 03 November 2007 04:50 ] [ ID #1861661 ]

Re: Query Help

On Nov 2, 8:50 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
> jc... [at] lycos.com wrote:
> > I have four fields, "name", "date", "task", and "title" - and am
> > trying to PHP code where if I click 'All', all rows for 'Bob' followed
> > by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
> > would be displayed alphabetically (by name), with all of Bob's rows
> > grouped together and then all of Jim's and then all of Joe's, etc
> > (versus the way they may reside in the MySQL table).
>
> > My query works well for individual names and also for 'All' but it
> > would look and be easier to read if I could group the rows by name and
> > maybe list alphabetically. My 'All' code portion currently looks like
> > this:
>
> > $query =
> > "SELECT *
> > FROM $table
> > WHERE 1 = 1 ";
> > if($name != "All") $query .= "and name = '".$name."'";
>
> > $result = mysql_query($query);
>
> > thanks for any help...
> > John
>
> You're probably going to want to use one of the "joins". 'LEFT JOIN',
> 'INNER JOIN', etc. Then 'ORDER BY name DESC'. This will give you your
> results in alphabetical order.

Any examples on how to integrate 'join' code for something like this
in PHP? Thanks
jcage [ Sa, 03 November 2007 05:39 ] [ ID #1861662 ]

Re: Query Help

jcage [at] lycos.com wrote:
> On Nov 2, 8:50 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
>> jc... [at] lycos.com wrote:
>>> I have four fields, "name", "date", "task", and "title" - and am
>>> trying to PHP code where if I click 'All', all rows for 'Bob' followed
>>> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
>>> would be displayed alphabetically (by name), with all of Bob's rows
>>> grouped together and then all of Jim's and then all of Joe's, etc
>>> (versus the way they may reside in the MySQL table).
>>> My query works well for individual names and also for 'All' but it
>>> would look and be easier to read if I could group the rows by name and
>>> maybe list alphabetically. My 'All' code portion currently looks like
>>> this:
>>> $query =
>>> "SELECT *
>>> FROM $table
>>> WHERE 1 = 1 ";
>>> if($name != "All") $query .= "and name = '".$name."'";
>>> $result = mysql_query($query);
>>> thanks for any help...
>>> John
>> You're probably going to want to use one of the "joins". 'LEFT JOIN',
>> 'INNER JOIN', etc. Then 'ORDER BY name DESC'. This will give you your
>> results in alphabetical order.
>
> Any examples on how to integrate 'join' code for something like this
> in PHP? Thanks
>
Chris Gorospe [ Sa, 03 November 2007 05:50 ] [ ID #1861663 ]

Re: Query Help

jcage [at] lycos.com wrote:
> On Nov 2, 8:50 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
>> jc... [at] lycos.com wrote:
>>> I have four fields, "name", "date", "task", and "title" - and am
>>> trying to PHP code where if I click 'All', all rows for 'Bob' followed
>>> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
>>> would be displayed alphabetically (by name), with all of Bob's rows
>>> grouped together and then all of Jim's and then all of Joe's, etc
>>> (versus the way they may reside in the MySQL table).
>>> My query works well for individual names and also for 'All' but it
>>> would look and be easier to read if I could group the rows by name and
>>> maybe list alphabetically. My 'All' code portion currently looks like
>>> this:
>>> $query =
>>> "SELECT *
>>> FROM $table
>>> WHERE 1 = 1 ";
>>> if($name != "All") $query .= "and name = '".$name."'";
>>> $result = mysql_query($query);
>>> thanks for any help...
>>> John
>> You're probably going to want to use one of the "joins". 'LEFT JOIN',
>> 'INNER JOIN', etc. Then 'ORDER BY name DESC'. This will give you your
>> results in alphabetical order.
>
> Any examples on how to integrate 'join' code for something like this
> in PHP? Thanks
>
Actually, you don't even need to use JOIN. I was under the impression
these people were in different tables.

Just use the 'ORDER BY name DESC' with your 'select *', and that should
get you want you're looking for.
Chris Gorospe [ Sa, 03 November 2007 05:52 ] [ ID #1861664 ]

Re: Query Help

On Nov 2, 9:52 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
> jc... [at] lycos.com wrote:
> > On Nov 2, 8:50 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
> >> jc... [at] lycos.com wrote:
> >>> I have four fields, "name", "date", "task", and "title" - and am
> >>> trying to PHP code where if I click 'All', all rows for 'Bob' followed
> >>> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
> >>> would be displayed alphabetically (by name), with all of Bob's rows
> >>> grouped together and then all of Jim's and then all of Joe's, etc
> >>> (versus the way they may reside in the MySQL table).
> >>> My query works well for individual names and also for 'All' but it
> >>> would look and be easier to read if I could group the rows by name and
> >>> maybe list alphabetically. My 'All' code portion currently looks like
> >>> this:
> >>> $query =
> >>> "SELECT *
> >>> FROM $table
> >>> WHERE 1 = 1 ";
> >>> if($name != "All") $query .= "and name = '".$name."'";
> >>> $result = mysql_query($query);
> >>> thanks for any help...
> >>> John
> >> You're probably going to want to use one of the "joins". 'LEFT JOIN',
> >> 'INNER JOIN', etc. Then 'ORDER BY name DESC'. This will give you your
> >> results in alphabetical order.
>
> > Any examples on how to integrate 'join' code for something like this
> > in PHP? Thanks
>
> Actually, you don't even need to use JOIN. I was under the impression
> these people were in different tables.
>
> Just use the 'ORDER BY name DESC' with your 'select *', and that should
> get you want you're looking for.

Hey, that's it... Thank You Sir... Appreciate the help very much. :-)
jcage [ Sa, 03 November 2007 12:44 ] [ ID #1861665 ]

Re: Query Help

Post removed (X-No-Archive: yes)
Notifier Deamon [ Sa, 03 November 2007 20:29 ] [ ID #1861670 ]

Re: Query Help

jcage [at] lycos.com wrote:
> I have four fields, "name", "date", "task", and "title" - and am
> trying to PHP code where if I click 'All', all rows for 'Bob' followed
> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
> would be displayed alphabetically (by name), with all of Bob's rows
> grouped together and then all of Jim's and then all of Joe's, etc
> (versus the way they may reside in the MySQL table).
>
> My query works well for individual names and also for 'All' but it
> would look and be easier to read if I could group the rows by name and
> maybe list alphabetically. My 'All' code portion currently looks like
> this:
>
> $query =
> "SELECT *
> FROM $table
> WHERE 1 = 1 ";
> if($name != "All") $query .= "and name = '".$name."'";
>
> $result = mysql_query($query);
>
>
> thanks for any help...
> John
>
>

You're asking about SQL, not PHP. Try comp.databases.mysql.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Sa, 03 November 2007 03:12 ] [ ID #1861682 ]

Re: Query Help

jcage [at] lycos.com wrote:
> I have four fields, "name", "date", "task", and "title" - and am
> trying to PHP code where if I click 'All', all rows for 'Bob' followed
> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
> would be displayed alphabetically (by name), with all of Bob's rows
> grouped together and then all of Jim's and then all of Joe's, etc
> (versus the way they may reside in the MySQL table).
>
> My query works well for individual names and also for 'All' but it
> would look and be easier to read if I could group the rows by name and
> maybe list alphabetically. My 'All' code portion currently looks like
> this:
>
> $query =
> "SELECT *
> FROM $table
> WHERE 1 = 1 ";
> if($name != "All") $query .= "and name = '".$name."'";
>
> $result = mysql_query($query);
>
>
> thanks for any help...
> John
>
You're probably going to want to use one of the "joins". 'LEFT JOIN',
'INNER JOIN', etc. Then 'ORDER BY name DESC'. This will give you your
results in alphabetical order.
Chris Gorospe [ Sa, 03 November 2007 04:50 ] [ ID #1861684 ]

Re: Query Help

On Nov 2, 8:50 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
> jc... [at] lycos.com wrote:
> > I have four fields, "name", "date", "task", and "title" - and am
> > trying to PHP code where if I click 'All', all rows for 'Bob' followed
> > by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
> > would be displayed alphabetically (by name), with all of Bob's rows
> > grouped together and then all of Jim's and then all of Joe's, etc
> > (versus the way they may reside in the MySQL table).
>
> > My query works well for individual names and also for 'All' but it
> > would look and be easier to read if I could group the rows by name and
> > maybe list alphabetically. My 'All' code portion currently looks like
> > this:
>
> > $query =
> > "SELECT *
> > FROM $table
> > WHERE 1 = 1 ";
> > if($name != "All") $query .= "and name = '".$name."'";
>
> > $result = mysql_query($query);
>
> > thanks for any help...
> > John
>
> You're probably going to want to use one of the "joins". 'LEFT JOIN',
> 'INNER JOIN', etc. Then 'ORDER BY name DESC'. This will give you your
> results in alphabetical order.

Any examples on how to integrate 'join' code for something like this
in PHP? Thanks
jcage [ Sa, 03 November 2007 05:39 ] [ ID #1861685 ]

Re: Query Help

jcage [at] lycos.com wrote:
> On Nov 2, 8:50 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
>> jc... [at] lycos.com wrote:
>>> I have four fields, "name", "date", "task", and "title" - and am
>>> trying to PHP code where if I click 'All', all rows for 'Bob' followed
>>> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
>>> would be displayed alphabetically (by name), with all of Bob's rows
>>> grouped together and then all of Jim's and then all of Joe's, etc
>>> (versus the way they may reside in the MySQL table).
>>> My query works well for individual names and also for 'All' but it
>>> would look and be easier to read if I could group the rows by name and
>>> maybe list alphabetically. My 'All' code portion currently looks like
>>> this:
>>> $query =
>>> "SELECT *
>>> FROM $table
>>> WHERE 1 = 1 ";
>>> if($name != "All") $query .= "and name = '".$name."'";
>>> $result = mysql_query($query);
>>> thanks for any help...
>>> John
>> You're probably going to want to use one of the "joins". 'LEFT JOIN',
>> 'INNER JOIN', etc. Then 'ORDER BY name DESC'. This will give you your
>> results in alphabetical order.
>
> Any examples on how to integrate 'join' code for something like this
> in PHP? Thanks
>
Chris Gorospe [ Sa, 03 November 2007 05:50 ] [ ID #1861686 ]

Re: Query Help

jcage [at] lycos.com wrote:
> On Nov 2, 8:50 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
>> jc... [at] lycos.com wrote:
>>> I have four fields, "name", "date", "task", and "title" - and am
>>> trying to PHP code where if I click 'All', all rows for 'Bob' followed
>>> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
>>> would be displayed alphabetically (by name), with all of Bob's rows
>>> grouped together and then all of Jim's and then all of Joe's, etc
>>> (versus the way they may reside in the MySQL table).
>>> My query works well for individual names and also for 'All' but it
>>> would look and be easier to read if I could group the rows by name and
>>> maybe list alphabetically. My 'All' code portion currently looks like
>>> this:
>>> $query =
>>> "SELECT *
>>> FROM $table
>>> WHERE 1 = 1 ";
>>> if($name != "All") $query .= "and name = '".$name."'";
>>> $result = mysql_query($query);
>>> thanks for any help...
>>> John
>> You're probably going to want to use one of the "joins". 'LEFT JOIN',
>> 'INNER JOIN', etc. Then 'ORDER BY name DESC'. This will give you your
>> results in alphabetical order.
>
> Any examples on how to integrate 'join' code for something like this
> in PHP? Thanks
>
Actually, you don't even need to use JOIN. I was under the impression
these people were in different tables.

Just use the 'ORDER BY name DESC' with your 'select *', and that should
get you want you're looking for.
Chris Gorospe [ Sa, 03 November 2007 05:52 ] [ ID #1861687 ]

Re: Query Help

On Nov 2, 9:52 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
> jc... [at] lycos.com wrote:
> > On Nov 2, 8:50 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
> >> jc... [at] lycos.com wrote:
> >>> I have four fields, "name", "date", "task", and "title" - and am
> >>> trying to PHP code where if I click 'All', all rows for 'Bob' followed
> >>> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
> >>> would be displayed alphabetically (by name), with all of Bob's rows
> >>> grouped together and then all of Jim's and then all of Joe's, etc
> >>> (versus the way they may reside in the MySQL table).
> >>> My query works well for individual names and also for 'All' but it
> >>> would look and be easier to read if I could group the rows by name and
> >>> maybe list alphabetically. My 'All' code portion currently looks like
> >>> this:
> >>> $query =
> >>> "SELECT *
> >>> FROM $table
> >>> WHERE 1 = 1 ";
> >>> if($name != "All") $query .= "and name = '".$name."'";
> >>> $result = mysql_query($query);
> >>> thanks for any help...
> >>> John
> >> You're probably going to want to use one of the "joins". 'LEFT JOIN',
> >> 'INNER JOIN', etc. Then 'ORDER BY name DESC'. This will give you your
> >> results in alphabetical order.
>
> > Any examples on how to integrate 'join' code for something like this
> > in PHP? Thanks
>
> Actually, you don't even need to use JOIN. I was under the impression
> these people were in different tables.
>
> Just use the 'ORDER BY name DESC' with your 'select *', and that should
> get you want you're looking for.

Hey, that's it... Thank You Sir... Appreciate the help very much. :-)
jcage [ Sa, 03 November 2007 12:44 ] [ ID #1861697 ]

Re: Query Help

Tom wrote:
> On Fri, 02 Nov 2007 21:12:42 -0500, Jerry Stuckle wrote...
>> jcage [at] lycos.com wrote:
>>> I have four fields, "name", "date", "task", and "title" - and am
>>> trying to PHP code where if I click 'All', all rows for 'Bob' followed
>>> by all rows in a MySQL datebase for 'Jim' and then all rows for 'Joe'
>>> would be displayed alphabetically (by name), with all of Bob's rows
>>> grouped together and then all of Jim's and then all of Joe's, etc
>>> (versus the way they may reside in the MySQL table).
>>>
>>> My query works well for individual names and also for 'All' but it
>>> would look and be easier to read if I could group the rows by name and
>>> maybe list alphabetically. My 'All' code portion currently looks like
>>> this:
>>>
>>> $query =
>>> "SELECT *
>>> FROM $table
>>> WHERE 1 = 1 ";
>>> if($name != "All") $query .= "and name = '".$name."'";
>>>
>>> $result = mysql_query($query);
>>>
>>>
>>> thanks for any help...
>>> John
>>>
>>>
>> You're asking about SQL, not PHP. Try comp.databases.mysql.
>>
>
>
> I get alt.php.sql on my newsgroup list, and that's helpful for SQL related
> questions too.
>
>
> Tom

But comp.databases.mysql is much better than alt.php.sql for MySQL
questions. The problem is no database implements the SQL standards 100%
or the same way. comp.databases.mysql has MySQL specific info - which,
in this case, is 100% independent of the language being used to access
MySQL, but 100% dependent on MySQL.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ So, 04 November 2007 02:26 ] [ ID #1862146 ]

Re: Query Help

On Nov 2, 8:52 pm, Chris Gorospe <ch... [at] ekast.com> wrote:

> Just use the 'ORDER BY name DESC' with your 'select *', and that should
> get you want you're looking for.
----------------------------------------

$query = "SELECT DISTINCT names
FROM $table
Order by names";
$result = mysql_query($query);

So.... :-)

In the above code, 'Order by' works very well when not used in
conjunction with other queryable items but how about when used in a
query where other possible choices are included? How do I use 'Order
by' in the query below where it will only act on 'names' when "All" is
selected and otherwise, not really be active during the query as in
the code below? Any thoughts? TIA


$query = "SELECT *
FROM $table
WHERE 1 = 1 ";
if($year != "All") $query .= "and year = '".$year."'";
if($status != "All") $query .= "and status = '".$status."'";
if($names != "All") $query .= "and names = '".$names."'";
$result = mysql_query($query);
jcage [ Do, 08 November 2007 07:28 ] [ ID #1865858 ]

Re: Query Help

jcage [at] lycos.com wrote:
> On Nov 2, 8:52 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
>
>> Just use the 'ORDER BY name DESC' with your 'select *', and that should
>> get you want you're looking for.
> ----------------------------------------
>
> $query = "SELECT DISTINCT names
> FROM $table
> Order by names";
> $result = mysql_query($query);
>
> So.... :-)
>
> In the above code, 'Order by' works very well when not used in
> conjunction with other queryable items but how about when used in a
> query where other possible choices are included? How do I use 'Order
> by' in the query below where it will only act on 'names' when "All" is
> selected and otherwise, not really be active during the query as in
> the code below? Any thoughts? TIA
>
>
> $query = "SELECT *
> FROM $table
> WHERE 1 = 1 ";
> if($year != "All") $query .= "and year = '".$year."'";
> if($status != "All") $query .= "and status = '".$status."'";
> if($names != "All") $query .= "and names = '".$names."'";
> $result = mysql_query($query);
>
>

This isn't a PHP question.

Try comp.database.mysql when asking mysql questions. That's where the
SQL experts hang out.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Do, 08 November 2007 14:25 ] [ ID #1865863 ]

Re: Query Help

On Nov 8, 5:25 am, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> jc... [at] lycos.com wrote:
> > On Nov 2, 8:52 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
>
> >> Just use the 'ORDER BY name DESC' with your 'select *', and that should
> >> get you want you're looking for.
> > ----------------------------------------
>
> > $query = "SELECT DISTINCT names
> > FROM $table
> > Order by names";
> > $result = mysql_query($query);
>
> > So.... :-)
>
> > In the above code, 'Order by' works very well when not used in
> > conjunction with other queryable items but how about when used in a
> > query where other possible choices are included? How do I use 'Order
> > by' in the query below where it will only act on 'names' when "All" is
> > selected and otherwise, not really be active during the query as in
> > the code below? Any thoughts? TIA
>
> > $query = "SELECT *
> > FROM $table
> > WHERE 1 = 1 ";
> > if($year != "All") $query .= "and year = '".$year."'";
> > if($status != "All") $query .= "and status = '".$status."'";
> > if($names != "All") $query .= "and names = '".$names."'";
> > $result = mysql_query($query);
>
> This isn't a PHP question.
>
> Try comp.database.mysql when asking mysql questions. That's where the
> SQL experts hang out.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> ==================

will do. thanks for the tip.
jcage [ Do, 08 November 2007 15:09 ] [ ID #1865865 ]

Re: Query Help

$query = "SELECT DISTINCT names
FROM $table
Order by names";
$result = mysql_query($query);

In the code above, 'Order by' works very well when not used in
conjunction with other query-able items but how about when used in a
query where other possible choices are included? How do I use 'Order
by' in the query below where it will only act on 'names' when "All"
is
selected and otherwise, not really be active during the query as in
the code below? I'm using PHP to access MySQL. Thanks

$query = "SELECT *
FROM $table
WHERE 1 = 1 ";
if($year != "All") $query .= "and year = '".$year."'";
if($status != "All") $query .= "and status = '".
$status."'";
if($names != "All") $query .= "and names = '".$names."'";
$result = mysql_query($query);
jcage [ Do, 08 November 2007 15:13 ] [ ID #1865866 ]

Re: Query Help

On 8 Nov, 14:13, jc... [at] lycos.com wrote:
> $query = "SELECT DISTINCT names
> FROM $table
> Order by names";
> $result = mysql_query($query);
>
> In the code above, 'Order by' works very well when not used in
> conjunction with other query-able items but how about when used in a
> query where other possible choices are included? How do I use 'Order
> by' in the query below where it will only act on 'names' when "All"
> is
> selected and otherwise, not really be active during the query as in
> the code below? I'm using PHP to access MySQL. Thanks
>
> $query = "SELECT *
> FROM $table
> WHERE 1 = 1 ";
> if($year != "All") $query .= "and year = '".$year."'";
> if($status != "All") $query .= "and status = '".
> $status."'";
> if($names != "All") $query .= "and names = '".$names."'";
> $result = mysql_query($query);

ORDER BY names

the whole WHERE clause is superfluous in this query.
Captain Paralytic [ Do, 08 November 2007 16:12 ] [ ID #1865867 ]

Re: Query Help

"Captain Paralytic" <paul_lautman [at] yahoo.com> wrote in message
news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com...
> On 8 Nov, 14:13, jc... [at] lycos.com wrote:
>> $query = "SELECT DISTINCT names
>> FROM $table
>> Order by names";
>> $result = mysql_query($query);
>>
>> In the code above, 'Order by' works very well when not used in
>> conjunction with other query-able items but how about when used in a
>> query where other possible choices are included? How do I use 'Order
>> by' in the query below where it will only act on 'names' when "All"
>> is
>> selected and otherwise, not really be active during the query as in
>> the code below? I'm using PHP to access MySQL. Thanks
>>
>> $query = "SELECT *
>> FROM $table
>> WHERE 1 = 1 ";
>> if($year != "All") $query .= "and year = '".$year."'";
>> if($status != "All") $query .= "and status = '".
>> $status."'";
>> if($names != "All") $query .= "and names = '".$names."'";
>> $result = mysql_query($query);
>
> ORDER BY names

just a note about legibility here...

$sql[] = "
SELECT *
FROM " . $table . "
WHERE 1 = 1
";
if ($year != 'ALL')
{
$sql[] = " AND year = '" . $year . "'";
}
if ($status != 'ALL')
{
$sql[] = " AND status = '" . $status. "'";
}
if ($names != 'ALL')
{
$sql[] = " AND names = '" . $names. "'";
}
$sql = implode("\r\n", $sql);

that avoide the problem of forgetting to put a space between the if'd
conditions/criterion. note, i put the spaces before 'and' simply so that
when i go to debug the current sql being run, it echos nice and formatted in
the browser.
Steve [ Do, 08 November 2007 16:34 ] [ ID #1865868 ]

Re: Query Help

On Nov 8, 4:34 pm, "Steve" <no.... [at] example.com> wrote:
> "Captain Paralytic" <paul_laut... [at] yahoo.com> wrote in message
>
> news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com...
>
>
>
> > On 8 Nov, 14:13, jc... [at] lycos.com wrote:
> >> $query = "SELECT DISTINCT names
> >> FROM $table
> >> Order by names";
> >> $result = mysql_query($query);
>
> >> In the code above, 'Order by' works very well when not used in
> >> conjunction with other query-able items but how about when used in a
> >> query where other possible choices are included? How do I use 'Order
> >> by' in the query below where it will only act on 'names' when "All"
> >> is
> >> selected and otherwise, not really be active during the query as in
> >> the code below? I'm using PHP to access MySQL. Thanks
>
> >> $query = "SELECT *
> >> FROM $table
> >> WHERE 1 = 1 ";
> >> if($year != "All") $query .= "and year = '".$year."'";
> >> if($status != "All") $query .= "and status = '".
> >> $status."'";
> >> if($names != "All") $query .= "and names = '".$names."'";
> >> $result = mysql_query($query);
>
> > ORDER BY names
>
> just a note about legibility here...
>
> $sql[] = "
> SELECT *
> FROM " . $table . "
> WHERE 1 = 1
> ";
> if ($year != 'ALL')
> {
> $sql[] = " AND year = '" . $year . "'";}
>
> if ($status != 'ALL')
> {
> $sql[] = " AND status = '" . $status. "'";}
>
> if ($names != 'ALL')
> {
> $sql[] = " AND names = '" . $names. "'";}
>
> $sql = implode("\r\n", $sql);
>
> that avoide the problem of forgetting to put a space between the if'd
> conditions/criterion. note, i put the spaces before 'and' simply so that
> when i go to debug the current sql being run, it echos nice and formatted in
> the browser.

You and your formatting again :D You won't give up until you educate
all newbies to
proper formatting, eh? :)

Cheers
darko [ Do, 08 November 2007 20:02 ] [ ID #1865870 ]

Re: Query Help

"Darko" <darko.maksimovic [at] gmail.com> wrote in message
news:1194548559.891114.33150 [at] v23g2000prn.googlegroups.com...
> On Nov 8, 4:34 pm, "Steve" <no.... [at] example.com> wrote:
>> "Captain Paralytic" <paul_laut... [at] yahoo.com> wrote in message
>>
>> news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com...
>>
>>
>>
>> > On 8 Nov, 14:13, jc... [at] lycos.com wrote:
>> >> $query = "SELECT DISTINCT names
>> >> FROM $table
>> >> Order by names";
>> >> $result = mysql_query($query);
>>
>> >> In the code above, 'Order by' works very well when not used in
>> >> conjunction with other query-able items but how about when used in a
>> >> query where other possible choices are included? How do I use 'Order
>> >> by' in the query below where it will only act on 'names' when "All"
>> >> is
>> >> selected and otherwise, not really be active during the query as in
>> >> the code below? I'm using PHP to access MySQL. Thanks
>>
>> >> $query = "SELECT *
>> >> FROM $table
>> >> WHERE 1 = 1 ";
>> >> if($year != "All") $query .= "and year = '".$year."'";
>> >> if($status != "All") $query .= "and status = '".
>> >> $status."'";
>> >> if($names != "All") $query .= "and names = '".$names."'";
>> >> $result = mysql_query($query);
>>
>> > ORDER BY names
>>
>> just a note about legibility here...
>>
>> $sql[] = "
>> SELECT *
>> FROM " . $table . "
>> WHERE 1 = 1
>> ";
>> if ($year != 'ALL')
>> {
>> $sql[] = " AND year = '" . $year . "'";}
>>
>> if ($status != 'ALL')
>> {
>> $sql[] = " AND status = '" . $status. "'";}
>>
>> if ($names != 'ALL')
>> {
>> $sql[] = " AND names = '" . $names. "'";}
>>
>> $sql = implode("\r\n", $sql);
>>
>> that avoide the problem of forgetting to put a space between the if'd
>> conditions/criterion. note, i put the spaces before 'and' simply so that
>> when i go to debug the current sql being run, it echos nice and formatted
>> in
>> the browser.
>
> You and your formatting again :D You won't give up until you educate
> all newbies to
> proper formatting, eh? :)

he, he, he, he!

well, actually the formatting is just a bonus. some db's, even though they
strip out spaces themselves when parsing, will caugh up errors if the
clauses run together...which happens the way the op wrote it...where 1=1and
year='2007'and status=... building $sql as an array and then imploding it
back on itself avoids the problem and also makes for more clearly defined if
() cases.

but, i'm still chuckling. that was good.
Steve [ Do, 08 November 2007 20:43 ] [ ID #1865873 ]

Re: Query Help

Steve wrote:
> "Captain Paralytic" <paul_lautman [at] yahoo.com> wrote in message
> news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com...
>> On 8 Nov, 14:13, jc... [at] lycos.com wrote:
>>> $query = "SELECT DISTINCT names
>>> FROM $table
>>> Order by names";
>>> $result = mysql_query($query);
>>>
>>> In the code above, 'Order by' works very well when not used in
>>> conjunction with other query-able items but how about when used in
>>> a query where other possible choices are included? How do I use
>>> 'Order by' in the query below where it will only act on 'names'
>>> when "All" is
>>> selected and otherwise, not really be active during the query as in
>>> the code below? I'm using PHP to access MySQL. Thanks
>>>
>>> $query = "SELECT *
>>> FROM $table
>>> WHERE 1 = 1 ";
>>> if($year != "All") $query .= "and year = '".$year."'";
>>> if($status != "All") $query .= "and status = '".
>>> $status."'";
>>> if($names != "All") $query .= "and names = '".$names."'";
>>> $result = mysql_query($query);
>>
>> ORDER BY names
>
> just a note about legibility here...
>
> $sql[] = "
> SELECT *
> FROM " . $table . "
> WHERE 1 = 1
> ";
> if ($year != 'ALL')
> {
> $sql[] = " AND year = '" . $year . "'";
> }
> if ($status != 'ALL')
> {
> $sql[] = " AND status = '" . $status. "'";
> }
> if ($names != 'ALL')
> {
> $sql[] = " AND names = '" . $names. "'";
> }
> $sql = implode("\r\n", $sql);
>
> that avoide the problem of forgetting to put a space between the if'd
> conditions/criterion. note, i put the spaces before 'and' simply so
> that when i go to debug the current sql being run, it echos nice and
> formatted in the browser.

Please learn to post replies to the correct post. I do not need advise on
formatting, the OP may do!
Paul Lautman [ Do, 08 November 2007 21:45 ] [ ID #1865875 ]

Re: Query Help

"Paul Lautman" <paul.lautman [at] btinternet.com> wrote in message
news:5phaqhFrfrejU1 [at] mid.individual.net...
> Steve wrote:
>> "Captain Paralytic" <paul_lautman [at] yahoo.com> wrote in message
>> news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com...
>>> On 8 Nov, 14:13, jc... [at] lycos.com wrote:
>>>> $query = "SELECT DISTINCT names
>>>> FROM $table
>>>> Order by names";
>>>> $result = mysql_query($query);
>>>>
>>>> In the code above, 'Order by' works very well when not used in
>>>> conjunction with other query-able items but how about when used in
>>>> a query where other possible choices are included? How do I use
>>>> 'Order by' in the query below where it will only act on 'names'
>>>> when "All" is
>>>> selected and otherwise, not really be active during the query as in
>>>> the code below? I'm using PHP to access MySQL. Thanks
>>>>
>>>> $query = "SELECT *
>>>> FROM $table
>>>> WHERE 1 = 1 ";
>>>> if($year != "All") $query .= "and year = '".$year."'";
>>>> if($status != "All") $query .= "and status = '".
>>>> $status."'";
>>>> if($names != "All") $query .= "and names = '".$names."'";
>>>> $result = mysql_query($query);
>>>
>>> ORDER BY names
>>
>> just a note about legibility here...
>>
>> $sql[] = "
>> SELECT *
>> FROM " . $table . "
>> WHERE 1 = 1
>> ";
>> if ($year != 'ALL')
>> {
>> $sql[] = " AND year = '" . $year . "'";
>> }
>> if ($status != 'ALL')
>> {
>> $sql[] = " AND status = '" . $status. "'";
>> }
>> if ($names != 'ALL')
>> {
>> $sql[] = " AND names = '" . $names. "'";
>> }
>> $sql = implode("\r\n", $sql);
>>
>> that avoide the problem of forgetting to put a space between the if'd
>> conditions/criterion. note, i put the spaces before 'and' simply so
>> that when i go to debug the current sql being run, it echos nice and
>> formatted in the browser.
>
> Please learn to post replies to the correct post. I do not need advise on
> formatting, the OP may do!

first of all, it's a thread, dude. second, it's usenet. like it, or lump it.
:)
Steve [ Do, 08 November 2007 22:40 ] [ ID #1865877 ]

Re: Query Help

On 8 Nov, 20:45, "Paul Lautman" <paul.laut... [at] btinternet.com> wrote:
> Steve wrote:
> > "Captain Paralytic" <paul_laut... [at] yahoo.com> wrote in message
> >news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com.. .
> >> On 8 Nov, 14:13, jc... [at] lycos.com wrote:
> >>> $query = "SELECT DISTINCT names
> >>> FROM $table
> >>> Order by names";
> >>> $result = mysql_query($query);
>
> >>> In the code above, 'Order by' works very well when not used in
> >>> conjunction with other query-able items but how about when used in
> >>> a query where other possible choices are included? How do I use
> >>> 'Order by' in the query below where it will only act on 'names'
> >>> when "All" is
> >>> selected and otherwise, not really be active during the query as in
> >>> the code below? I'm using PHP to access MySQL. Thanks
>
> >>> $query = "SELECT *
> >>> FROM $table
> >>> WHERE 1 = 1 ";
> >>> if($year != "All") $query .= "and year = '".$year."'";
> >>> if($status != "All") $query .= "and status = '".
> >>> $status."'";
> >>> if($names != "All") $query .= "and names = '".$names."'";
> >>> $result = mysql_query($query);
>
> >> ORDER BY names
>
> > just a note about legibility here...
>
> > $sql[] = "
> > SELECT *
> > FROM " . $table . "
> > WHERE 1 = 1
> > ";
> > if ($year != 'ALL')
> > {
> > $sql[] = " AND year = '" . $year . "'";
> > }
> > if ($status != 'ALL')
> > {
> > $sql[] = " AND status = '" . $status. "'";
> > }
> > if ($names != 'ALL')
> > {
> > $sql[] = " AND names = '" . $names. "'";
> > }
> > $sql = implode("\r\n", $sql);
>
> > that avoide the problem of forgetting to put a space between the if'd
> > conditions/criterion. note, i put the spaces before 'and' simply so
> > that when i go to debug the current sql being run, it echos nice and
> > formatted in the browser.
>
> Please learn to post replies to the correct post. I do not need advise on
> formatting, the OP may do!

Definitely not, but some advice on spelling (and punctuation) wouldn't
go amiss. He he he ;-)
zac.carey [ Do, 08 November 2007 23:14 ] [ ID #1865879 ]

Re: Query Help

"strawberry" <zac.carey [at] gmail.com> wrote in message
news:1194560072.097968.186940 [at] s15g2000prm.googlegroups.com.. .
> On 8 Nov, 20:45, "Paul Lautman" <paul.laut... [at] btinternet.com> wrote:
>> Steve wrote:
>> > "Captain Paralytic" <paul_laut... [at] yahoo.com> wrote in message
>> >news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com.. .
>> >> On 8 Nov, 14:13, jc... [at] lycos.com wrote:
>> >>> $query = "SELECT DISTINCT names
>> >>> FROM $table
>> >>> Order by names";
>> >>> $result = mysql_query($query);
>>
>> >>> In the code above, 'Order by' works very well when not used in
>> >>> conjunction with other query-able items but how about when used in
>> >>> a query where other possible choices are included? How do I use
>> >>> 'Order by' in the query below where it will only act on 'names'
>> >>> when "All" is
>> >>> selected and otherwise, not really be active during the query as in
>> >>> the code below? I'm using PHP to access MySQL. Thanks
>>
>> >>> $query = "SELECT *
>> >>> FROM $table
>> >>> WHERE 1 = 1 ";
>> >>> if($year != "All") $query .= "and year = '".$year."'";
>> >>> if($status != "All") $query .= "and status = '".
>> >>> $status."'";
>> >>> if($names != "All") $query .= "and names = '".$names."'";
>> >>> $result = mysql_query($query);
>>
>> >> ORDER BY names
>>
>> > just a note about legibility here...
>>
>> > $sql[] = "
>> > SELECT *
>> > FROM " . $table . "
>> > WHERE 1 = 1
>> > ";
>> > if ($year != 'ALL')
>> > {
>> > $sql[] = " AND year = '" . $year . "'";
>> > }
>> > if ($status != 'ALL')
>> > {
>> > $sql[] = " AND status = '" . $status. "'";
>> > }
>> > if ($names != 'ALL')
>> > {
>> > $sql[] = " AND names = '" . $names. "'";
>> > }
>> > $sql = implode("\r\n", $sql);
>>
>> > that avoide the problem of forgetting to put a space between the if'd
>> > conditions/criterion. note, i put the spaces before 'and' simply so
>> > that when i go to debug the current sql being run, it echos nice and
>> > formatted in the browser.
>>
>> Please learn to post replies to the correct post. I do not need advise on
>> formatting, the OP may do!
>
> Definitely not, but some advice on spelling (and punctuation) wouldn't
> go amiss. He he he ;-)

sorry, if you look at my posts, they're splintered with errors on all
counts. :) hell, i even leave out words altogether sometimes...damn fingers
just can't keep up.
Steve [ Do, 08 November 2007 23:21 ] [ ID #1865880 ]

Re: Query Help

On Nov 2, 8:52 pm, Chris Gorospe <ch... [at] ekast.com> wrote:

> Just use the 'ORDER BY name DESC' with your 'select *', and that should
> get you want you're looking for.
----------------------------------------

$query = "SELECT DISTINCT names
FROM $table
Order by names";
$result = mysql_query($query);

So.... :-)

In the above code, 'Order by' works very well when not used in
conjunction with other queryable items but how about when used in a
query where other possible choices are included? How do I use 'Order
by' in the query below where it will only act on 'names' when "All" is
selected and otherwise, not really be active during the query as in
the code below? Any thoughts? TIA


$query = "SELECT *
FROM $table
WHERE 1 = 1 ";
if($year != "All") $query .= "and year = '".$year."'";
if($status != "All") $query .= "and status = '".$status."'";
if($names != "All") $query .= "and names = '".$names."'";
$result = mysql_query($query);
jcage [ Do, 08 November 2007 07:28 ] [ ID #1865901 ]

Re: Query Help

jcage [at] lycos.com wrote:
> On Nov 2, 8:52 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
>
>> Just use the 'ORDER BY name DESC' with your 'select *', and that should
>> get you want you're looking for.
> ----------------------------------------
>
> $query = "SELECT DISTINCT names
> FROM $table
> Order by names";
> $result = mysql_query($query);
>
> So.... :-)
>
> In the above code, 'Order by' works very well when not used in
> conjunction with other queryable items but how about when used in a
> query where other possible choices are included? How do I use 'Order
> by' in the query below where it will only act on 'names' when "All" is
> selected and otherwise, not really be active during the query as in
> the code below? Any thoughts? TIA
>
>
> $query = "SELECT *
> FROM $table
> WHERE 1 = 1 ";
> if($year != "All") $query .= "and year = '".$year."'";
> if($status != "All") $query .= "and status = '".$status."'";
> if($names != "All") $query .= "and names = '".$names."'";
> $result = mysql_query($query);
>
>

This isn't a PHP question.

Try comp.database.mysql when asking mysql questions. That's where the
SQL experts hang out.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Do, 08 November 2007 14:25 ] [ ID #1865912 ]

Re: Query Help

On Nov 8, 5:25 am, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> jc... [at] lycos.com wrote:
> > On Nov 2, 8:52 pm, Chris Gorospe <ch... [at] ekast.com> wrote:
>
> >> Just use the 'ORDER BY name DESC' with your 'select *', and that should
> >> get you want you're looking for.
> > ----------------------------------------
>
> > $query = "SELECT DISTINCT names
> > FROM $table
> > Order by names";
> > $result = mysql_query($query);
>
> > So.... :-)
>
> > In the above code, 'Order by' works very well when not used in
> > conjunction with other queryable items but how about when used in a
> > query where other possible choices are included? How do I use 'Order
> > by' in the query below where it will only act on 'names' when "All" is
> > selected and otherwise, not really be active during the query as in
> > the code below? Any thoughts? TIA
>
> > $query = "SELECT *
> > FROM $table
> > WHERE 1 = 1 ";
> > if($year != "All") $query .= "and year = '".$year."'";
> > if($status != "All") $query .= "and status = '".$status."'";
> > if($names != "All") $query .= "and names = '".$names."'";
> > $result = mysql_query($query);
>
> This isn't a PHP question.
>
> Try comp.database.mysql when asking mysql questions. That's where the
> SQL experts hang out.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> ==================

will do. thanks for the tip.
jcage [ Do, 08 November 2007 15:09 ] [ ID #1865920 ]

Re: Query Help

$query = "SELECT DISTINCT names
FROM $table
Order by names";
$result = mysql_query($query);

In the code above, 'Order by' works very well when not used in
conjunction with other query-able items but how about when used in a
query where other possible choices are included? How do I use 'Order
by' in the query below where it will only act on 'names' when "All"
is
selected and otherwise, not really be active during the query as in
the code below? I'm using PHP to access MySQL. Thanks

$query = "SELECT *
FROM $table
WHERE 1 = 1 ";
if($year != "All") $query .= "and year = '".$year."'";
if($status != "All") $query .= "and status = '".
$status."'";
if($names != "All") $query .= "and names = '".$names."'";
$result = mysql_query($query);
jcage [ Do, 08 November 2007 15:13 ] [ ID #1865921 ]

Re: Query Help

On 8 Nov, 14:13, jc... [at] lycos.com wrote:
> $query = "SELECT DISTINCT names
> FROM $table
> Order by names";
> $result = mysql_query($query);
>
> In the code above, 'Order by' works very well when not used in
> conjunction with other query-able items but how about when used in a
> query where other possible choices are included? How do I use 'Order
> by' in the query below where it will only act on 'names' when "All"
> is
> selected and otherwise, not really be active during the query as in
> the code below? I'm using PHP to access MySQL. Thanks
>
> $query = "SELECT *
> FROM $table
> WHERE 1 = 1 ";
> if($year != "All") $query .= "and year = '".$year."'";
> if($status != "All") $query .= "and status = '".
> $status."'";
> if($names != "All") $query .= "and names = '".$names."'";
> $result = mysql_query($query);

ORDER BY names

the whole WHERE clause is superfluous in this query.
Captain Paralytic [ Do, 08 November 2007 16:12 ] [ ID #1865930 ]

Re: Query Help

"Captain Paralytic" <paul_lautman [at] yahoo.com> wrote in message
news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com...
> On 8 Nov, 14:13, jc... [at] lycos.com wrote:
>> $query = "SELECT DISTINCT names
>> FROM $table
>> Order by names";
>> $result = mysql_query($query);
>>
>> In the code above, 'Order by' works very well when not used in
>> conjunction with other query-able items but how about when used in a
>> query where other possible choices are included? How do I use 'Order
>> by' in the query below where it will only act on 'names' when "All"
>> is
>> selected and otherwise, not really be active during the query as in
>> the code below? I'm using PHP to access MySQL. Thanks
>>
>> $query = "SELECT *
>> FROM $table
>> WHERE 1 = 1 ";
>> if($year != "All") $query .= "and year = '".$year."'";
>> if($status != "All") $query .= "and status = '".
>> $status."'";
>> if($names != "All") $query .= "and names = '".$names."'";
>> $result = mysql_query($query);
>
> ORDER BY names

just a note about legibility here...

$sql[] = "
SELECT *
FROM " . $table . "
WHERE 1 = 1
";
if ($year != 'ALL')
{
$sql[] = " AND year = '" . $year . "'";
}
if ($status != 'ALL')
{
$sql[] = " AND status = '" . $status. "'";
}
if ($names != 'ALL')
{
$sql[] = " AND names = '" . $names. "'";
}
$sql = implode("\r\n", $sql);

that avoide the problem of forgetting to put a space between the if'd
conditions/criterion. note, i put the spaces before 'and' simply so that
when i go to debug the current sql being run, it echos nice and formatted in
the browser.
Steve [ Do, 08 November 2007 16:34 ] [ ID #1865933 ]

Re: Query Help

On Nov 8, 4:34 pm, "Steve" <no.... [at] example.com> wrote:
> "Captain Paralytic" <paul_laut... [at] yahoo.com> wrote in message
>
> news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com...
>
>
>
> > On 8 Nov, 14:13, jc... [at] lycos.com wrote:
> >> $query = "SELECT DISTINCT names
> >> FROM $table
> >> Order by names";
> >> $result = mysql_query($query);
>
> >> In the code above, 'Order by' works very well when not used in
> >> conjunction with other query-able items but how about when used in a
> >> query where other possible choices are included? How do I use 'Order
> >> by' in the query below where it will only act on 'names' when "All"
> >> is
> >> selected and otherwise, not really be active during the query as in
> >> the code below? I'm using PHP to access MySQL. Thanks
>
> >> $query = "SELECT *
> >> FROM $table
> >> WHERE 1 = 1 ";
> >> if($year != "All") $query .= "and year = '".$year."'";
> >> if($status != "All") $query .= "and status = '".
> >> $status."'";
> >> if($names != "All") $query .= "and names = '".$names."'";
> >> $result = mysql_query($query);
>
> > ORDER BY names
>
> just a note about legibility here...
>
> $sql[] = "
> SELECT *
> FROM " . $table . "
> WHERE 1 = 1
> ";
> if ($year != 'ALL')
> {
> $sql[] = " AND year = '" . $year . "'";}
>
> if ($status != 'ALL')
> {
> $sql[] = " AND status = '" . $status. "'";}
>
> if ($names != 'ALL')
> {
> $sql[] = " AND names = '" . $names. "'";}
>
> $sql = implode("\r\n", $sql);
>
> that avoide the problem of forgetting to put a space between the if'd
> conditions/criterion. note, i put the spaces before 'and' simply so that
> when i go to debug the current sql being run, it echos nice and formatted in
> the browser.

You and your formatting again :D You won't give up until you educate
all newbies to
proper formatting, eh? :)

Cheers
darko [ Do, 08 November 2007 20:02 ] [ ID #1865951 ]

Re: Query Help

"Darko" <darko.maksimovic [at] gmail.com> wrote in message
news:1194548559.891114.33150 [at] v23g2000prn.googlegroups.com...
> On Nov 8, 4:34 pm, "Steve" <no.... [at] example.com> wrote:
>> "Captain Paralytic" <paul_laut... [at] yahoo.com> wrote in message
>>
>> news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com...
>>
>>
>>
>> > On 8 Nov, 14:13, jc... [at] lycos.com wrote:
>> >> $query = "SELECT DISTINCT names
>> >> FROM $table
>> >> Order by names";
>> >> $result = mysql_query($query);
>>
>> >> In the code above, 'Order by' works very well when not used in
>> >> conjunction with other query-able items but how about when used in a
>> >> query where other possible choices are included? How do I use 'Order
>> >> by' in the query below where it will only act on 'names' when "All"
>> >> is
>> >> selected and otherwise, not really be active during the query as in
>> >> the code below? I'm using PHP to access MySQL. Thanks
>>
>> >> $query = "SELECT *
>> >> FROM $table
>> >> WHERE 1 = 1 ";
>> >> if($year != "All") $query .= "and year = '".$year."'";
>> >> if($status != "All") $query .= "and status = '".
>> >> $status."'";
>> >> if($names != "All") $query .= "and names = '".$names."'";
>> >> $result = mysql_query($query);
>>
>> > ORDER BY names
>>
>> just a note about legibility here...
>>
>> $sql[] = "
>> SELECT *
>> FROM " . $table . "
>> WHERE 1 = 1
>> ";
>> if ($year != 'ALL')
>> {
>> $sql[] = " AND year = '" . $year . "'";}
>>
>> if ($status != 'ALL')
>> {
>> $sql[] = " AND status = '" . $status. "'";}
>>
>> if ($names != 'ALL')
>> {
>> $sql[] = " AND names = '" . $names. "'";}
>>
>> $sql = implode("\r\n", $sql);
>>
>> that avoide the problem of forgetting to put a space between the if'd
>> conditions/criterion. note, i put the spaces before 'and' simply so that
>> when i go to debug the current sql being run, it echos nice and formatted
>> in
>> the browser.
>
> You and your formatting again :D You won't give up until you educate
> all newbies to
> proper formatting, eh? :)

he, he, he, he!

well, actually the formatting is just a bonus. some db's, even though they
strip out spaces themselves when parsing, will caugh up errors if the
clauses run together...which happens the way the op wrote it...where 1=1and
year='2007'and status=... building $sql as an array and then imploding it
back on itself avoids the problem and also makes for more clearly defined if
() cases.

but, i'm still chuckling. that was good.
Steve [ Do, 08 November 2007 20:43 ] [ ID #1865960 ]

Re: Query Help

Steve wrote:
> "Captain Paralytic" <paul_lautman [at] yahoo.com> wrote in message
> news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com...
>> On 8 Nov, 14:13, jc... [at] lycos.com wrote:
>>> $query = "SELECT DISTINCT names
>>> FROM $table
>>> Order by names";
>>> $result = mysql_query($query);
>>>
>>> In the code above, 'Order by' works very well when not used in
>>> conjunction with other query-able items but how about when used in
>>> a query where other possible choices are included? How do I use
>>> 'Order by' in the query below where it will only act on 'names'
>>> when "All" is
>>> selected and otherwise, not really be active during the query as in
>>> the code below? I'm using PHP to access MySQL. Thanks
>>>
>>> $query = "SELECT *
>>> FROM $table
>>> WHERE 1 = 1 ";
>>> if($year != "All") $query .= "and year = '".$year."'";
>>> if($status != "All") $query .= "and status = '".
>>> $status."'";
>>> if($names != "All") $query .= "and names = '".$names."'";
>>> $result = mysql_query($query);
>>
>> ORDER BY names
>
> just a note about legibility here...
>
> $sql[] = "
> SELECT *
> FROM " . $table . "
> WHERE 1 = 1
> ";
> if ($year != 'ALL')
> {
> $sql[] = " AND year = '" . $year . "'";
> }
> if ($status != 'ALL')
> {
> $sql[] = " AND status = '" . $status. "'";
> }
> if ($names != 'ALL')
> {
> $sql[] = " AND names = '" . $names. "'";
> }
> $sql = implode("\r\n", $sql);
>
> that avoide the problem of forgetting to put a space between the if'd
> conditions/criterion. note, i put the spaces before 'and' simply so
> that when i go to debug the current sql being run, it echos nice and
> formatted in the browser.

Please learn to post replies to the correct post. I do not need advise on
formatting, the OP may do!
Paul Lautman [ Do, 08 November 2007 21:45 ] [ ID #1865975 ]

Re: Query Help

"Paul Lautman" <paul.lautman [at] btinternet.com> wrote in message
news:5phaqhFrfrejU1 [at] mid.individual.net...
> Steve wrote:
>> "Captain Paralytic" <paul_lautman [at] yahoo.com> wrote in message
>> news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com...
>>> On 8 Nov, 14:13, jc... [at] lycos.com wrote:
>>>> $query = "SELECT DISTINCT names
>>>> FROM $table
>>>> Order by names";
>>>> $result = mysql_query($query);
>>>>
>>>> In the code above, 'Order by' works very well when not used in
>>>> conjunction with other query-able items but how about when used in
>>>> a query where other possible choices are included? How do I use
>>>> 'Order by' in the query below where it will only act on 'names'
>>>> when "All" is
>>>> selected and otherwise, not really be active during the query as in
>>>> the code below? I'm using PHP to access MySQL. Thanks
>>>>
>>>> $query = "SELECT *
>>>> FROM $table
>>>> WHERE 1 = 1 ";
>>>> if($year != "All") $query .= "and year = '".$year."'";
>>>> if($status != "All") $query .= "and status = '".
>>>> $status."'";
>>>> if($names != "All") $query .= "and names = '".$names."'";
>>>> $result = mysql_query($query);
>>>
>>> ORDER BY names
>>
>> just a note about legibility here...
>>
>> $sql[] = "
>> SELECT *
>> FROM " . $table . "
>> WHERE 1 = 1
>> ";
>> if ($year != 'ALL')
>> {
>> $sql[] = " AND year = '" . $year . "'";
>> }
>> if ($status != 'ALL')
>> {
>> $sql[] = " AND status = '" . $status. "'";
>> }
>> if ($names != 'ALL')
>> {
>> $sql[] = " AND names = '" . $names. "'";
>> }
>> $sql = implode("\r\n", $sql);
>>
>> that avoide the problem of forgetting to put a space between the if'd
>> conditions/criterion. note, i put the spaces before 'and' simply so
>> that when i go to debug the current sql being run, it echos nice and
>> formatted in the browser.
>
> Please learn to post replies to the correct post. I do not need advise on
> formatting, the OP may do!

first of all, it's a thread, dude. second, it's usenet. like it, or lump it.
:)
Steve [ Do, 08 November 2007 22:40 ] [ ID #1865982 ]

Re: Query Help

On 8 Nov, 20:45, "Paul Lautman" <paul.laut... [at] btinternet.com> wrote:
> Steve wrote:
> > "Captain Paralytic" <paul_laut... [at] yahoo.com> wrote in message
> >news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com.. .
> >> On 8 Nov, 14:13, jc... [at] lycos.com wrote:
> >>> $query = "SELECT DISTINCT names
> >>> FROM $table
> >>> Order by names";
> >>> $result = mysql_query($query);
>
> >>> In the code above, 'Order by' works very well when not used in
> >>> conjunction with other query-able items but how about when used in
> >>> a query where other possible choices are included? How do I use
> >>> 'Order by' in the query below where it will only act on 'names'
> >>> when "All" is
> >>> selected and otherwise, not really be active during the query as in
> >>> the code below? I'm using PHP to access MySQL. Thanks
>
> >>> $query = "SELECT *
> >>> FROM $table
> >>> WHERE 1 = 1 ";
> >>> if($year != "All") $query .= "and year = '".$year."'";
> >>> if($status != "All") $query .= "and status = '".
> >>> $status."'";
> >>> if($names != "All") $query .= "and names = '".$names."'";
> >>> $result = mysql_query($query);
>
> >> ORDER BY names
>
> > just a note about legibility here...
>
> > $sql[] = "
> > SELECT *
> > FROM " . $table . "
> > WHERE 1 = 1
> > ";
> > if ($year != 'ALL')
> > {
> > $sql[] = " AND year = '" . $year . "'";
> > }
> > if ($status != 'ALL')
> > {
> > $sql[] = " AND status = '" . $status. "'";
> > }
> > if ($names != 'ALL')
> > {
> > $sql[] = " AND names = '" . $names. "'";
> > }
> > $sql = implode("\r\n", $sql);
>
> > that avoide the problem of forgetting to put a space between the if'd
> > conditions/criterion. note, i put the spaces before 'and' simply so
> > that when i go to debug the current sql being run, it echos nice and
> > formatted in the browser.
>
> Please learn to post replies to the correct post. I do not need advise on
> formatting, the OP may do!

Definitely not, but some advice on spelling (and punctuation) wouldn't
go amiss. He he he ;-)
zac.carey [ Do, 08 November 2007 23:14 ] [ ID #1865990 ]

Re: Query Help

"strawberry" <zac.carey [at] gmail.com> wrote in message
news:1194560072.097968.186940 [at] s15g2000prm.googlegroups.com.. .
> On 8 Nov, 20:45, "Paul Lautman" <paul.laut... [at] btinternet.com> wrote:
>> Steve wrote:
>> > "Captain Paralytic" <paul_laut... [at] yahoo.com> wrote in message
>> >news:1194534736.193031.304830 [at] q5g2000prf.googlegroups.com.. .
>> >> On 8 Nov, 14:13, jc... [at] lycos.com wrote:
>> >>> $query = "SELECT DISTINCT names
>> >>> FROM $table
>> >>> Order by names";
>> >>> $result = mysql_query($query);
>>
>> >>> In the code above, 'Order by' works very well when not used in
>> >>> conjunction with other query-able items but how about when used in
>> >>> a query where other possible choices are included? How do I use
>> >>> 'Order by' in the query below where it will only act on 'names'
>> >>> when "All" is
>> >>> selected and otherwise, not really be active during the query as in
>> >>> the code below? I'm using PHP to access MySQL. Thanks
>>
>> >>> $query = "SELECT *
>> >>> FROM $table
>> >>> WHERE 1 = 1 ";
>> >>> if($year != "All") $query .= "and year = '".$year."'";
>> >>> if($status != "All") $query .= "and status = '".
>> >>> $status."'";
>> >>> if($names != "All") $query .= "and names = '".$names."'";
>> >>> $result = mysql_query($query);
>>
>> >> ORDER BY names
>>
>> > just a note about legibility here...
>>
>> > $sql[] = "
>> > SELECT *
>> > FROM " . $table . "
>> > WHERE 1 = 1
>> > ";
>> > if ($year != 'ALL')
>> > {
>> > $sql[] = " AND year = '" . $year . "'";
>> > }
>> > if ($status != 'ALL')
>> > {
>> > $sql[] = " AND status = '" . $status. "'";
>> > }
>> > if ($names != 'ALL')
>> > {
>> > $sql[] = " AND names = '" . $names. "'";
>> > }
>> > $sql = implode("\r\n", $sql);
>>
>> > that avoide the problem of forgetting to put a space between the if'd
>> > conditions/criterion. note, i put the spaces before 'and' simply so
>> > that when i go to debug the current sql being run, it echos nice and
>> > formatted in the browser.
>>
>> Please learn to post replies to the correct post. I do not need advise on
>> formatting, the OP may do!
>
> Definitely not, but some advice on spelling (and punctuation) wouldn't
> go amiss. He he he ;-)

sorry, if you look at my posts, they're splintered with errors on all
counts. :) hell, i even leave out words altogether sometimes...damn fingers
just can't keep up.
Steve [ Do, 08 November 2007 23:21 ] [ ID #1865993 ]

Re: Query Help

On 8 Nov, 21:40, "Steve" <no.... [at] example.com> wrote:
| first of all, it's a thread, dude.
Err no. A thread is a linked collection of posts on a particular
subject. When you post a reply you do so to a previous post within a
thread, dude.

| second, it's usenet. like it, or lump it.
It is not usenet's fault. Usenet is quite capable of attaching
responses correctly. What is needed is a bit of intelligence on the
part of the user, dude.
Captain Paralytic [ Fr, 09 November 2007 11:13 ] [ ID #1866794 ]
PHP » alt.php » Query Help

Vorheriges Thema: Error 'this.$event[...].keys' is
Nächstes Thema: related pages ...