Forum Moderators: coopster

Message Too Old, No Replies

IF/AND not working for some reason? No error.

First and 2nd IF statements work, but third does not?

         

mylungsarempty

12:22 am on Jul 15, 2011 (gmt 0)

10+ Year Member



I've been looking at this trying things for a while... i just can't get it to work.

The first 2 if statements work fine, but when county and city are both in the URL, the 2nd if statement keeps being triggered, and I can't figure out why.. code looks ok?

mysql_select_db("d60763712", $con);

if (!isset($_GET['county']) AND !isset($_GET['city']))

{

echo "<h3>SELECT YOUR COUNTY:</h3>";

echo "<ul>";

$result = mysql_query("SELECT DISTINCT county FROM zip_code WHERE state_prefix = 'AR' ORDER BY county");

while($row = mysql_fetch_array($result))

{

$county = $row['county'];

echo "<li><i><a class='countylinks' href='?county=" . $county . "'>" . $county . " <span style='color: #898a8b'>COUNTY</i></span></a><br /></li>";

}

echo "</ul>";

}

if (isset($_GET['county']) AND !isset($_GET['city']))

{

echo "<h3>SELECT YOUR CITY:</h3>";

echo "<ul>";

$county = $_GET['county'];

$result = mysql_query("SELECT DISTINCT city, locationtext FROM zip_code WHERE state_prefix = 'AR' AND county = '$county' AND locationtext != '' ORDER BY city");

while($row = mysql_fetch_array($result))

{

$city = $row['city'];
$locationtext = $row['locationtext'];


echo "<li><i><a class='countylinks' href='?county=" . $county . "?city=" . $city . "'>" . $locationtext . "</a><br /></li>";

}

echo "</ul>";

}

if (isset($_GET['county']) AND isset($_GET['city']))

{

$county = $_GET['county'];
$city = $_GET['city'];

$result = mysql_query("SELECT DISTINCT FROM zip_code WHERE state_prefix = 'AR' AND county = '$county' AND city = '$city'");

while($row = mysql_fetch_array($result))

{

$city = $row['city'];
$locationtext = $row['locationtext'];
$zip_code = $row['zip_code'];

echo "Information about " . $locationtext . " " . $zip_code . "...";

}


}

mysql_close($con);

?>

mylungsarempty

12:38 am on Jul 15, 2011 (gmt 0)

10+ Year Member



Nevermind. I figured it out. it's the ampersand. simple mistake.

g1smd

12:41 am on Jul 15, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Forgetting the original question for a moment, there's a huge logic error in the code flow.

If there is nothing in the database for the requested URL, the script currently returns the template text with empty variable values and the page returns "200 OK" status. This is dangerous as it can lead to Infinite Duplicate Content issues.

You should do all of your database queries before sending the DOCTYPE and <html> tags. In that case when there is no record in the database you can then send HEADER('HTTP/1.1 404 Not Found'); and an appropriate error text in html.

Back to your question, re-arrange the IF statements:

IF ISSET county
{

IF ISSET city
{
do this - city and county are both set
}
ELSE
{
do this - county is set, but city is not
}

}
ELSE
{
do this - county is not set, who cares if city is or not
}

Get the data from the database, and load it into a variable.

If the database returns no data send the 404 page. If the database returns data, return the content page.

mylungsarempty

5:51 am on Jul 15, 2011 (gmt 0)

10+ Year Member



Good information. Thanks for the help -- I have another question... if I include a .php file from another subdomain, can it not read the $_GET variables? i have code that works fine until you include it from different subdomain... seems like it should work just the same if its same code though? Any knowledge on this? Thank you very much.

g1smd

7:21 am on Jul 15, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The 'include' function should include a file from the same filesystem, referenced using server paths and files.
It should not include a URL. That is, the 'include' statement should not include a protocol or domain name.