Jump to content


Photo

Help Needed... *SOLVED*


  • Please log in to reply
4 replies to this topic

#1 Anakin

Anakin
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 01 October 2006 - 08:57 AM

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

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

?>
________________________________________________________

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

_________________________________________________________

#2 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 01 October 2006 - 09:04 AM

Try the following line for the sort by:

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

Which is line 14?

Thanks.



#3 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 01 October 2006 - 09:06 AM

wwfc_barmy_army's code should work, but I would sort it ascendingly.

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,167 posts

Posted 01 October 2006 - 09:14 AM

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.

<?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);


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 Anakin

Anakin
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 01 October 2006 - 01:46 PM

Thanks very much to everyone that responded.
With your guidance, I've managed to resolve the issue!!!

:)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users