Query Help
am 03.11.2007 02:53:50 von jcage
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
Re: Query Help
am 03.11.2007 03:12:42 von Jerry Stuckle
jcage@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@attglobal.net
==================
Re: Query Help
am 03.11.2007 03:12:42 von Jerry Stuckle
jcage@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@attglobal.net
==================
Re: Query Help
am 03.11.2007 04:50:37 von Chris Gorospe
jcage@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.
Re: Query Help
am 03.11.2007 04:50:37 von Chris Gorospe
jcage@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.
Re: Query Help
am 03.11.2007 05:39:26 von jcage
On Nov 2, 8:50 pm, Chris Gorospe wrote:
> jc...@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
Re: Query Help
am 03.11.2007 05:39:26 von jcage
On Nov 2, 8:50 pm, Chris Gorospe wrote:
> jc...@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
Re: Query Help
am 03.11.2007 05:50:13 von Chris Gorospe
jcage@lycos.com wrote:
> On Nov 2, 8:50 pm, Chris Gorospe wrote:
>> jc...@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
>
Re: Query Help
am 03.11.2007 05:50:13 von Chris Gorospe
jcage@lycos.com wrote:
> On Nov 2, 8:50 pm, Chris Gorospe wrote:
>> jc...@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
>
Re: Query Help
am 03.11.2007 05:52:37 von Chris Gorospe
jcage@lycos.com wrote:
> On Nov 2, 8:50 pm, Chris Gorospe wrote:
>> jc...@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.
Re: Query Help
am 03.11.2007 05:52:37 von Chris Gorospe
jcage@lycos.com wrote:
> On Nov 2, 8:50 pm, Chris Gorospe wrote:
>> jc...@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.
Re: Query Help
am 03.11.2007 12:44:47 von jcage
On Nov 2, 9:52 pm, Chris Gorospe wrote:
> jc...@lycos.com wrote:
> > On Nov 2, 8:50 pm, Chris Gorospe wrote:
> >> jc...@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. :-)
Re: Query Help
am 03.11.2007 12:44:47 von jcage
On Nov 2, 9:52 pm, Chris Gorospe wrote:
> jc...@lycos.com wrote:
> > On Nov 2, 8:50 pm, Chris Gorospe wrote:
> >> jc...@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. :-)
Re: Query Help
am 03.11.2007 20:29:17 von unknown
Post removed (X-No-Archive: yes)
Re: Query Help
am 04.11.2007 02:26:06 von Jerry Stuckle
Tom wrote:
> On Fri, 02 Nov 2007 21:12:42 -0500, Jerry Stuckle wrote...
>> jcage@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@attglobal.net
==================
Re: Query Help
am 08.11.2007 07:28:34 von jcage
On Nov 2, 8:52 pm, Chris Gorospe 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);
Re: Query Help
am 08.11.2007 07:28:34 von jcage
On Nov 2, 8:52 pm, Chris Gorospe 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);
Re: Query Help
am 08.11.2007 14:25:38 von Jerry Stuckle
jcage@lycos.com wrote:
> On Nov 2, 8:52 pm, Chris Gorospe 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@attglobal.net
==================
Re: Query Help
am 08.11.2007 14:25:38 von Jerry Stuckle
jcage@lycos.com wrote:
> On Nov 2, 8:52 pm, Chris Gorospe 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@attglobal.net
==================
Re: Query Help
am 08.11.2007 15:09:21 von jcage
On Nov 8, 5:25 am, Jerry Stuckle wrote:
> jc...@lycos.com wrote:
> > On Nov 2, 8:52 pm, Chris Gorospe 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...@attglobal.net
> ==================
will do. thanks for the tip.
Re: Query Help
am 08.11.2007 15:09:21 von jcage
On Nov 8, 5:25 am, Jerry Stuckle wrote:
> jc...@lycos.com wrote:
> > On Nov 2, 8:52 pm, Chris Gorospe 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...@attglobal.net
> ==================
will do. thanks for the tip.
Re: Query Help
am 08.11.2007 15:13:58 von jcage
$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);
Re: Query Help
am 08.11.2007 15:13:58 von jcage
$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);
Re: Query Help
am 08.11.2007 16:12:16 von Captain Paralytic
On 8 Nov, 14:13, jc...@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.
Re: Query Help
am 08.11.2007 16:12:16 von Captain Paralytic
On 8 Nov, 14:13, jc...@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.
Re: Query Help
am 08.11.2007 16:34:05 von Steve
"Captain Paralytic" wrote in message
news:1194534736.193031.304830@q5g2000prf.googlegroups.com...
> On 8 Nov, 14:13, jc...@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.
Re: Query Help
am 08.11.2007 16:34:05 von Steve
"Captain Paralytic" wrote in message
news:1194534736.193031.304830@q5g2000prf.googlegroups.com...
> On 8 Nov, 14:13, jc...@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.
Re: Query Help
am 08.11.2007 20:02:39 von darko
On Nov 8, 4:34 pm, "Steve" wrote:
> "Captain Paralytic" wrote in message
>
> news:1194534736.193031.304830@q5g2000prf.googlegroups.com...
>
>
>
> > On 8 Nov, 14:13, jc...@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
Re: Query Help
am 08.11.2007 20:02:39 von darko
On Nov 8, 4:34 pm, "Steve" wrote:
> "Captain Paralytic" wrote in message
>
> news:1194534736.193031.304830@q5g2000prf.googlegroups.com...
>
>
>
> > On 8 Nov, 14:13, jc...@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
Re: Query Help
am 08.11.2007 20:43:14 von Steve
"Darko" wrote in message
news:1194548559.891114.33150@v23g2000prn.googlegroups.com...
> On Nov 8, 4:34 pm, "Steve" wrote:
>> "Captain Paralytic" wrote in message
>>
>> news:1194534736.193031.304830@q5g2000prf.googlegroups.com...
>>
>>
>>
>> > On 8 Nov, 14:13, jc...@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.
Re: Query Help
am 08.11.2007 20:43:14 von Steve
"Darko" wrote in message
news:1194548559.891114.33150@v23g2000prn.googlegroups.com...
> On Nov 8, 4:34 pm, "Steve" wrote:
>> "Captain Paralytic" wrote in message
>>
>> news:1194534736.193031.304830@q5g2000prf.googlegroups.com...
>>
>>
>>
>> > On 8 Nov, 14:13, jc...@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.
Re: Query Help
am 08.11.2007 21:45:08 von Paul Lautman
Steve wrote:
> "Captain Paralytic" wrote in message
> news:1194534736.193031.304830@q5g2000prf.googlegroups.com...
>> On 8 Nov, 14:13, jc...@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!
Re: Query Help
am 08.11.2007 21:45:08 von Paul Lautman
Steve wrote:
> "Captain Paralytic" wrote in message
> news:1194534736.193031.304830@q5g2000prf.googlegroups.com...
>> On 8 Nov, 14:13, jc...@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!
Re: Query Help
am 08.11.2007 22:40:10 von Steve
"Paul Lautman" wrote in message
news:5phaqhFrfrejU1@mid.individual.net...
> Steve wrote:
>> "Captain Paralytic" wrote in message
>> news:1194534736.193031.304830@q5g2000prf.googlegroups.com...
>>> On 8 Nov, 14:13, jc...@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.
:)
Re: Query Help
am 08.11.2007 22:40:10 von Steve
"Paul Lautman" wrote in message
news:5phaqhFrfrejU1@mid.individual.net...
> Steve wrote:
>> "Captain Paralytic" wrote in message
>> news:1194534736.193031.304830@q5g2000prf.googlegroups.com...
>>> On 8 Nov, 14:13, jc...@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.
:)
Re: Query Help
am 08.11.2007 23:14:32 von zac.carey
On 8 Nov, 20:45, "Paul Lautman" wrote:
> Steve wrote:
> > "Captain Paralytic" wrote in message
> >news:1194534736.193031.304830@q5g2000prf.googlegroups.com.. .
> >> On 8 Nov, 14:13, jc...@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 ;-)
Re: Query Help
am 08.11.2007 23:14:32 von zac.carey
On 8 Nov, 20:45, "Paul Lautman" wrote:
> Steve wrote:
> > "Captain Paralytic" wrote in message
> >news:1194534736.193031.304830@q5g2000prf.googlegroups.com.. .
> >> On 8 Nov, 14:13, jc...@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 ;-)
Re: Query Help
am 08.11.2007 23:21:57 von Steve
"strawberry" wrote in message
news:1194560072.097968.186940@s15g2000prm.googlegroups.com.. .
> On 8 Nov, 20:45, "Paul Lautman" wrote:
>> Steve wrote:
>> > "Captain Paralytic" wrote in message
>> >news:1194534736.193031.304830@q5g2000prf.googlegroups.com.. .
>> >> On 8 Nov, 14:13, jc...@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.
Re: Query Help
am 08.11.2007 23:21:57 von Steve
"strawberry" wrote in message
news:1194560072.097968.186940@s15g2000prm.googlegroups.com.. .
> On 8 Nov, 20:45, "Paul Lautman" wrote:
>> Steve wrote:
>> > "Captain Paralytic" wrote in message
>> >news:1194534736.193031.304830@q5g2000prf.googlegroups.com.. .
>> >> On 8 Nov, 14:13, jc...@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.
Re: Query Help
am 09.11.2007 11:13:08 von Captain Paralytic
On 8 Nov, 21:40, "Steve" 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.
Re: Query Help
am 09.11.2007 11:13:08 von Captain Paralytic
On 8 Nov, 21:40, "Steve" 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.
Re: Query Help
am 09.11.2007 15:08:57 von Steve
"Captain Paralytic" wrote in message
news:1194603188.838479.254790@k79g2000hse.googlegroups.com.. .
> On 8 Nov, 21:40, "Steve" 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.
hmmm. so i was in a thread dealing with a particular subject and posted a
reply to a previous post within the thread, dude. did you want to make a
dashing, stand-out point here.
> | 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.
actually, usenet is a venue and takes *no* action in attaching messages to
others...dude. perhaps you should have a look at the nntp protocol and learn
how it all works. either way, your bit ot an attempt at insults is lost in
translation since it went to intellect - the irony meter just went of the
scale as soon as you tried to talk about things you obviously have *no* idea
work.
as for my exact point, it's usenet. people do what they like. the internet
and all it's venues are supremely facist-free at this point. bitching about
how people behave on the internet is a moot point at best.
next time, try harder...dude.
Re: Query Help
am 09.11.2007 15:08:57 von Steve
"Captain Paralytic" wrote in message
news:1194603188.838479.254790@k79g2000hse.googlegroups.com.. .
> On 8 Nov, 21:40, "Steve" 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.
hmmm. so i was in a thread dealing with a particular subject and posted a
reply to a previous post within the thread, dude. did you want to make a
dashing, stand-out point here.
> | 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.
actually, usenet is a venue and takes *no* action in attaching messages to
others...dude. perhaps you should have a look at the nntp protocol and learn
how it all works. either way, your bit ot an attempt at insults is lost in
translation since it went to intellect - the irony meter just went of the
scale as soon as you tried to talk about things you obviously have *no* idea
work.
as for my exact point, it's usenet. people do what they like. the internet
and all it's venues are supremely facist-free at this point. bitching about
how people behave on the internet is a moot point at best.
next time, try harder...dude.
Re: Query Help
am 09.11.2007 15:57:56 von jcage
On Nov 9, 6:08 am, "Steve" wrote:
> "Captain Paralytic" wrote in message
>
> news:1194603188.838479.254790@k79g2000hse.googlegroups.com.. .
>
> > On 8 Nov, 21:40, "Steve" 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.
>
> hmmm. so i was in a thread dealing with a particular subject and posted a
> reply to a previous post within the thread, dude. did you want to make a
> dashing, stand-out point here.
>
> > | 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.
>
> actually, usenet is a venue and takes *no* action in attaching messages to
> others...dude. perhaps you should have a look at the nntp protocol and learn
> how it all works. either way, your bit ot an attempt at insults is lost in
> translation since it went to intellect - the irony meter just went of the
> scale as soon as you tried to talk about things you obviously have *no* idea
> work.
>
> as for my exact point, it's usenet. people do what they like. the internet
> and all it's venues are supremely facist-free at this point. bitching about
> how people behave on the internet is a moot point at best.
>
> next time, try harder...dude.
Thanks for your help guys. Appreciate it very much.
john cage
Re: Query Help
am 09.11.2007 15:57:56 von jcage
On Nov 9, 6:08 am, "Steve" wrote:
> "Captain Paralytic" wrote in message
>
> news:1194603188.838479.254790@k79g2000hse.googlegroups.com.. .
>
> > On 8 Nov, 21:40, "Steve" 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.
>
> hmmm. so i was in a thread dealing with a particular subject and posted a
> reply to a previous post within the thread, dude. did you want to make a
> dashing, stand-out point here.
>
> > | 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.
>
> actually, usenet is a venue and takes *no* action in attaching messages to
> others...dude. perhaps you should have a look at the nntp protocol and learn
> how it all works. either way, your bit ot an attempt at insults is lost in
> translation since it went to intellect - the irony meter just went of the
> scale as soon as you tried to talk about things you obviously have *no* idea
> work.
>
> as for my exact point, it's usenet. people do what they like. the internet
> and all it's venues are supremely facist-free at this point. bitching about
> how people behave on the internet is a moot point at best.
>
> next time, try harder...dude.
Thanks for your help guys. Appreciate it very much.
john cage
Re: Query Help
am 09.11.2007 17:09:47 von Captain Paralytic
On 9 Nov, 14:08, "Steve" wrote:
> hmmm. so i was in a thread dealing with a particular subject and posted a
> reply to a previous post within the thread, dude. did you want to make a
> dashing, stand-out point here.
And you posted the reply attached to the wrong previous post
> people do what they like
People like you obviously do. Others have more sense.
> the irony meter just went of the
> scale as soon as you tried to talk about things you obviously have *no* idea
> work.
Now that's ironic coming from you!
Re: Query Help
am 09.11.2007 17:09:47 von Captain Paralytic
On 9 Nov, 14:08, "Steve" wrote:
> hmmm. so i was in a thread dealing with a particular subject and posted a
> reply to a previous post within the thread, dude. did you want to make a
> dashing, stand-out point here.
And you posted the reply attached to the wrong previous post
> people do what they like
People like you obviously do. Others have more sense.
> the irony meter just went of the
> scale as soon as you tried to talk about things you obviously have *no* idea
> work.
Now that's ironic coming from you!
Re: Query Help
am 09.11.2007 17:53:27 von Steve
"Captain Paralytic" wrote in message
news:1194624587.319538.252680@v2g2000hsf.googlegroups.com...
> On 9 Nov, 14:08, "Steve" wrote:
>> hmmm. so i was in a thread dealing with a particular subject and posted a
>> reply to a previous post within the thread, dude. did you want to make a
>> dashing, stand-out point here.
>
> And you posted the reply attached to the wrong previous post
'wrong'? no, i responded to the one i intended to respond to.
>> people do what they like
> People like you obviously do. Others have more sense.
'people like me'? you mean those who aren't so bent up about fictious or
preceived rules? and the ones with more sense, those who enjoy the binding
that holds to tightly bundled sticks together. (based on your iq, i doubt
you even get to what that refers.)
>> the irony meter just went of the
>> scale as soon as you tried to talk about things you obviously have *no*
>> idea
>> work.
> Now that's ironic coming from you!
really? here's a clue. when hurling insults that actually hit a target, it
is best to provide examples...like when you say things like usenet does this
or that when it actually doesn't. see, that's so well delivered that the
hilarity is just a side-line bene. the meat of the comment was to show you
have no idea about what you're trying to discuss.
on that note, please inform us all of what irony i specifically provide. if
you don't, we call that a red-herring coupled with ad-homonym - a diversion
from your previous embarrassment. :)
Re: Query Help
am 09.11.2007 17:53:27 von Steve
"Captain Paralytic" wrote in message
news:1194624587.319538.252680@v2g2000hsf.googlegroups.com...
> On 9 Nov, 14:08, "Steve" wrote:
>> hmmm. so i was in a thread dealing with a particular subject and posted a
>> reply to a previous post within the thread, dude. did you want to make a
>> dashing, stand-out point here.
>
> And you posted the reply attached to the wrong previous post
'wrong'? no, i responded to the one i intended to respond to.
>> people do what they like
> People like you obviously do. Others have more sense.
'people like me'? you mean those who aren't so bent up about fictious or
preceived rules? and the ones with more sense, those who enjoy the binding
that holds to tightly bundled sticks together. (based on your iq, i doubt
you even get to what that refers.)
>> the irony meter just went of the
>> scale as soon as you tried to talk about things you obviously have *no*
>> idea
>> work.
> Now that's ironic coming from you!
really? here's a clue. when hurling insults that actually hit a target, it
is best to provide examples...like when you say things like usenet does this
or that when it actually doesn't. see, that's so well delivered that the
hilarity is just a side-line bene. the meat of the comment was to show you
have no idea about what you're trying to discuss.
on that note, please inform us all of what irony i specifically provide. if
you don't, we call that a red-herring coupled with ad-homonym - a diversion
from your previous embarrassment. :)
Re: Query Help
am 10.11.2007 05:19:16 von Wings
jcage@lycos.com wrote:
> On Nov 9, 6:08 am, "Steve" wrote:
> > "Captain Paralytic" wrote in message
> >
> > news:1194603188.838479.254790@k79g2000hse.googlegroups.com.. .
> >
> > > On 8 Nov, 21:40, "Steve" 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.
> >
> > hmmm. so i was in a thread dealing with a particular subject and posted a
> > reply to a previous post within the thread, dude. did you want to make a
> > dashing, stand-out point here.
> >
> > > | 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.
> >
> > actually, usenet is a venue and takes *no* action in attaching messages to
> > others...dude. perhaps you should have a look at the nntp protocol and learn
> > how it all works. either way, your bit ot an attempt at insults is lost in
> > translation since it went to intellect - the irony meter just went of the
> > scale as soon as you tried to talk about things you obviously have *no* idea
> > work.
> >
> > as for my exact point, it's usenet. people do what they like. the internet
> > and all it's venues are supremely facist-free at this point. bitching about
> > how people behave on the internet is a moot point at best.
> >
> > next time, try harder...dude.
>
> Thanks for your help guys. Appreciate it very much.
> john cage
>
Hahaha.