Jump to content

Error Message


Anakin

Recommended Posts

Hi,

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!!!

Regards
Anakin

=============================================================

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

=============================================================
<?php

// This line connects to the database.
include_once("config.php");

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 ..." />';

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

?>
Link to comment
Share on other sites

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:

[code]
$query = "SELECT city_id, city.City FROM city WHERE country_id = '". $country_id . "'";
[/code]
Link to comment
Share on other sites

[code]// This line connects to the database.
include_once("config.php");

global $connection;

$country_id = $_GET[country_id];

[i].....[/i]

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

[/code]

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 [i]$connection = mysql_connect();[/i] then $connection will be a usable variable WITHOUT the global declaration...

I hope this helps.
Link to comment
Share on other sites

No, the statement
[code]<?php global connection; ?>[/code]
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
[code]<?php $result = mysql_query($query,$connection); ?>[/code]
to
[code]<?php $result = mysql_query($query) or die('Problem with the query: ' . $query . '<br />' . mysql_error()); ?>[/code]

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

This should help you debug your problem.

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.