Jump to content

Archived

This topic is now archived and is closed to further replies.

Anakin

Help Needed... *SOLVED*

Recommended Posts

Hi

Would someone please be able to shed some light on the following script.
I am trying to achieve 2 things.

(1) Correct error message.
(2) Also, return results in alphabetical ORDER.

Any help or suggestions would be appreciated.
Thanks!


_________________________________________________________

<?php

// Connect to the database.
include_once("config.php");
$country_id = $_GET[country_id];
$result = mysql_query("SELECT city_id, City FROM city WHERE country_id =".$country_id);

// Output XML document.
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<menu>';
echo '<menu-title label="menu">';
echo '<menu-item label="Select City ..." />';

[color=red]while($row=mysql_fetch_array($result)){[/color]
    $line = '<menu-item data="'.$row[city_id].'" label="'.$row[City].'"/>';
    echo $line;
}
echo '</menu-title>';
echo '</menu>';

?>
________________________________________________________

[color=red]<?xml version="1.0" encoding="UTF-8" ?>
- <menu>
- <menu-title label="menu">
  <menu-item label="Select City ..." />
  <br />
  <b>Warning</b>
  : mysql_fetch_array(): supplied argument is not a valid MySQL result resource in city.php</b>
  on line
  <b>14</b>
  <br />
  </menu-title>
  </menu>[/color]
_________________________________________________________

Share this post


Link to post
Share on other sites
Try the following line for the sort by:

[code]$result = mysql_query("SELECT city_id, City FROM city WHERE country_id = '$country_id' ORDER BY City DESC");[/code]

Which is line 14?

Thanks.

Share this post


Link to post
Share on other sites
wwfc_barmy_army's code should work, but I would sort it ascendingly.

Share this post


Link to post
Share on other sites
When calling queries, check for error messages. Also, if you specify the query in a string var then use that in the mysql_query() call you can also echo that out with the error message.

My guess here is that $country_id has no value.

[code]
<?php
// Connect to the database.
include_once("config.php");
$country_id = $_GET[country_id];
$sql = "SELECT city_id, City
        FROM city
        WHERE country_id ='$country_id'
        ORDER BY City";
$result = mysql_query($sql) or die (mysql_error().'<br>'.$sql);

[/code]

Share this post


Link to post
Share on other sites
Thanks very much to everyone that responded.
With your guidance, I've managed to resolve the issue!!!

:)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.