Jump to content


Error Message

  • Please log in to reply
3 replies to this topic

#1 Anakin

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 12 March 2006 - 01:00 AM


Can someone please assist with the following code.

(1) I get the following error when I run the script.
(2) I also need to have the results output in alphabetical order (ORDER BY).

Much appreciated for assistance!!!



<?xml version="1.0" encoding="UTF-8" ?>
- <menu>
- <menu-title label="menu">
<menu-item label="Select City ..." />
<br />
: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line

<br />


// This line connects to the database.

global $connection;

$country_id = $_GET[country_id];

$query = "SELECT city_id, City FROM city WHERE country_id = ".$country_id;

$result = mysql_query($query,$connection);

// And now we need to output an XML document.
// We use the names of columns as <row> properties.

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

$line = '<menu-item data="'.$row[city_id].'" label="'.$row[City].'"/>';
echo $line;
echo '</menu-title>';
echo '</menu>';


#2 azuka

  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts
  • LocationNigeria

Posted 12 March 2006 - 01:21 AM

The most obvious problem seems to be your naming structure. You have a table called city with a column city. Try changing your query to:

$query = "SELECT city_id, city.City FROM city WHERE country_id = '". $country_id . "'";

Given enough eyeballs all bugs are shallow. My Website

#3 keeB

  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 12 March 2006 - 06:01 AM

// This line connects to the database.

global $connection;

$country_id = $_GET[country_id]; 


$result = mysql_query($query,$connection);

the problem is there. $connection wont have a value because it seem's you're (re)declaring it to have no value.

if inside of config.php you have $connection = mysql_connect(); then $connection will be a usable variable WITHOUT the global declaration...

I hope this helps.

Come visit my site to see my latest projects

#4 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 12 March 2006 - 02:28 PM

No, the statement
<?php global connection; ?>
doesn't assign a value, it just tells PHP that the variable was used (created) outside the function and to use that variable instead of a local variable. In this instance, it is meanless and should be remoed anyway.

Change this line
<?php $result = mysql_query($query,$connection); ?>
<?php $result = mysql_query($query) or die('Problem with the query: ' . $query . '<br />' . mysql_error()); ?>

And change your query to
<?php $query = "SELECT city_id, City FROM city WHERE country_id = '" . $country_id . "'"; ?.

This should help you debug your problem.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users