0

I need some help. I'm loading a .php file using jquery. the php is a mysql query that pulls all the cities from Alaska. The problem is that I wrote my query a certain way and it seems jquery changes it when it loads it.

state_alaska.php

include 'config.php';

include 'opendb.php';
$AK = mysql_query("SELECT id, city, state FROM city WHERE state ='AK' ORDER BY city ASC") or die(mysql_error()); 

while ( $row = mysql_fetch_array($AK) ) {
    $page = "1";
    echo  "<div class='city'><a href='catagories.php?state=".urlencode($row["state"]) ."&city=".urlencode($row["city"])." &page=".$page."'/>".$row["city"] . "</a></div>";
    }
include 'closedb.php';

Jquery load

    $('#ak').load("state_alaska.php");

Source code

<div id="ak" style="display: block; ">
    <div class="city">
        <a href="catagories.php?state=AK&amp;city=Anchorage&amp;page=1"></a>
        Anchorage
    </div>
    <div class="city">
        <a href="catagories.php?state=AK&amp;city=Bethel+&amp;page=1"></a>
        Bethel 
    </div>
    <div class="city">
        <a href="catagories.php?state=AK&amp;city=Fairbanks+&amp;page=1"></a>
        Fairbanks 
    </div>
    <div class="city">
        <a href="catagories.php?state=AK&amp;city=Homer+&amp;page=1"></a>
        Homer
    </div>
    <div class="city">
        <a href="catagories.php?state=AK&amp;city=Juneau&amp;page=1"></a>
        Juneau
    </div>
    <div class="city">
        <a href="catagories.php?state=AK&amp;city=Kenai+&amp;page=1"></a>
        Kenai 
    </div>
    <div class="city">
        <a href="catagories.php?state=AK&amp;city=Ketchikan+&amp;page=1"></a>
        Ketchikan 
    </div>
    <div class="city">
        <a href="catagories.php?state=AK&amp;city=Kodiak+&amp;page=1"></a>
        Kodiak 
    </div>
</div>

In the code I never asked it to display block or to close the </a>'s I dont know why its doing that.. can anyone help?

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by pritaeas
0

On line 8, remove the closing slash for the a tag, that's what messes it up. The line should be:

echo  "<div class='city'><a href='catagories.php?state=" . urlencode($row["state"]) . "&city=" . urlencode($row["city"]) . "&page=" . $page . "'>" . $row["city"] . "</a></div>";

or:

echo  "<div class='city'><a href='catagories.php?state=" . urlencode($row["state"]) . "&city=" . urlencode($row["city"]) . "&page=$page'>{$row['city']}</a></div>";

Edited by pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.