[thelist] mysql_query + php
Jon Haworth
jhaworth at witanjardine.co.uk
Tue Feb 25 08:39:51 CST 2003
Hi Andrew,
> can anone say why this doesn't work?
>
> $result=mysql_query("$DBName","SELECT City, CityID
> FROM city ORDER BY City");
You should pass the query as the first parameter:
$result = mysql_query("SELECT City, CityID FROM city ORDER BY City");
I don't think you need the other parameter unless you have two database
connections open at once and you want to distinguish between them.
Also, if you don't mind an additional comment that'll save you some pain
later: rather than referring to the rows by number:
> echo "<option value=\"$row[1]\"> $row[0] </option>";
refer to them by name, like this:
echo $row["CityID"];
This will save you a couple of hours of debugging when you change the query
to select different fields :-)
Cheers
Jon
More information about the thelist
mailing list