Hey guys!
so, I have some code that creates an array. when I array_values the array, it displays all the data correctly, but when I do a while loop to display them in a table, it doesn't see the array data. here's the code. (I know there are HTML issues, I'm just working out the variable data now..)
$x=0;
while ($x < $citynum) {
$city_array[$x] = mysql_result($city_query_result,$x,"user_city");
$x++;
}
$city_result = array_unique($city_array);
print_r(array_values($city_result));
echo $city_result[2];
$count = count($city_result);
// echo $count;
$x=0;
while ($x < $count) {
$current_city = $city_result[$x];
$city_query = "SELECT city FROM users WHERE city = '$current_city'";
$city_query_result = mysql_query($city_query);
$citynum = mysql_num_rows($city_query_result);
echo "<TR>TD>$current_city ($citynum)</TD></TR>";
$x++;
}
}
Here is my output:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN" "http://www.w3.org/TR/html4/loose.dtd">
Array
(
[0] => Ann Arbor
[1] => Austin
[2] => Brooklyn
[3] => Chicago
[4] => Columbus
[5] => Detroit
[6] => New York
[7] => San Francisco
[8] => Seattle
[9] => Urbana
)
PHP Notice: Undefined offset: 2 in /var/www/html/scripts/browse-by-location.php on line 19
<TR>TD>Ann Arbor (1)</TD></TR><TR>TD>Austin (9)</TD></TR>PHP Notice: Undefined offset: 2 in /var/www/html/knerd/scripts/browse-by-location.php on line 25
<TR>TD> (0)</TD></TR>PHP Notice: Undefined offset: 3 in /var/www/html/scripts/browse-by-location.php on line 25
<TR>TD> (0)</TD></TR>PHP Notice: Undefined offset: 4 in /var/www/html/scripts/browse-by-location.php on line 25
<TR>TD> (0)</TD></TR>PHP Notice: Undefined offset: 5 in /var/www/html/scripts/browse-by-location.php on line 25
<TR>TD> (0)</TD></TR>PHP Notice: Undefined offset: 6 in /var/www/html/scripts/browse-by-location.php on line 25
<TR>TD> (0)</TD></TR>PHP Notice: Undefined offset: 7 in /var/www/html/scripts/browse-by-location.php on line 25
<TR>TD> (0)</TD></TR>PHP Notice: Undefined offset: 8 in /var/www/html/scripts/browse-by-location.php on line 25
<TR>TD> (0)</TD></TR>PHP Notice: Undefined offset: 9 in /var/www/html/scripts/browse-by-location.php on line 25
This is driving me insane. you can see that city_result[2]=Brooklyn, but even when I echo city_result[2], it gives me Undefined offset...
Any ideas why this is happening? Thanks so much!!