Jump to content

Archived

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

Anakin

Error Message

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>';

?>

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
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

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.