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
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
==================
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.
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
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
>
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.
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. :-)
Re: Query Help
Post removed (X-No-Archive: yes)
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
==================
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.
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
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
>
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.
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. :-)
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
==================
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);
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
==================
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.
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);
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.
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.
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
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.
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!
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.
:)
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 ;-)
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.
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);
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
==================
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.
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);
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.
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.
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
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.
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!
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.
:)
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 ;-)
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.
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.