|
Posted by Hans 'pritaeas' Pollaerts on 09/15/06 08:36
"Jeff Gardner" <user@example.tld> wrote in message
news:FNrOg.2076$IA.204@newssvr11.news.prodigy.com...
> Greetings:
>
> I am attempting to get conditional output based on POSTed form data.
> If the posted value is either the key or value of an array, $x=key and
> $q=foo. elseif it is neither key nor value(I tried || too) , $q=bar.
> Even though $x is properly assigned the new value, $q always ends up
> being bar. Abstractions aside, here's the code: (note ## comments
> added to this post)
>
> <snip>
> $search = $_POST[search];
> $sort = $_POST[sortby];
> $states = array(
> "AL" => "Alabama",
> "AK" => "Alaska",
> "AZ" => "Arizona",
> ...
> );
> ##echo $search here outputs the POSTed input
> foreach ($states as $key => $value)
>
> if ($search == $value || $search == $key) {
> $search = $key;
> ##echo $search here outputs the new value, when applicable
> $q = "
> SELECT
> organization.*, contacts.*
> FROM organization
> LEFT JOIN contacts
> ON organization.org_id = contacts.org_id
> OR organization.org_id = 0
> WHERE organization.state
> = '$search'
> OR contacts.state
> = '$search'
> ORDER BY '$sort' ASC";
>
> } elseif ($search != $value && $search != $key) { ##I tried || here too.
> ##echo $search here outputs the new value too, when applicable
> $q = "
> SELECT
> CONCAT(contacts.firstname,' ',contacts.lastname) AS fullname,
> organization.*, contacts.*
> FROM organization
> LEFT JOIN contacts
> ON organization.org_id = contacts.org_id
> OR organization.org_id = 0
> WHERE organization.state
> LIKE '%$search%'
> OR organization.orgname
> LIKE '%$search%'
> OR contacts.state
> LIKE '%$search%'
> OR contacts.lastname
> LIKE '%$search%'
> OR contacts.firstname
> LIKE '%$search%'
> ORDER BY '$sort' ASC";
> }
>
> $result = mysql_query($q)
> or die('Query Failed: ' . mysql_error());
> </snip>
>
> Where is this evaluation breaking down and why? Thanks in advance.
> --
>
> Regards,
>
> Jeff Gardner
Instead of the elseif you could just use else. Why check again, it's either
a state value, or something else.
Hans
Navigation:
[Reply to this message]
|