Anakin Posted March 12, 2006 Share Posted March 12, 2006 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!!!RegardsAnakin=============================================================<?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 https://forums.phpfreaks.com/topic/4722-error-message/ Share on other sites More sharing options...
azuka Posted March 12, 2006 Share Posted March 12, 2006 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 https://forums.phpfreaks.com/topic/4722-error-message/#findComment-16544 Share on other sites More sharing options...
keeB Posted March 12, 2006 Share Posted March 12, 2006 [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 https://forums.phpfreaks.com/topic/4722-error-message/#findComment-16581 Share on other sites More sharing options...
kenrbnsn Posted March 12, 2006 Share Posted March 12, 2006 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 https://forums.phpfreaks.com/topic/4722-error-message/#findComment-16669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.