Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning mysql values to fill a javascript dropbox

Status
Not open for further replies.

hpicken

Technical User
Apr 12, 2001
142
AU
I'm trying to return data from a Mysql db to fill a javascript dropbox on a php page.

I can get the data fine, and I can fill the list ok.
Basically I need to create an array like thus.

var pages = new makeArray("Select a ship on this page",
"Aguilar (1824)",
"Andromeda (1823)",
"Australasia (1855)",
"Atlanta (1866)",
"America (1855)",
"Admiral Cockburn (1827)",
"Aurora Australis (1862)"
);

I'm using the following code...

var pages = new makeArray("Select a ship on this page",
<?php
$getlist = mysql_query(&quot;SELECT * FROM imgships WHERE ship like '$currsltr%' ORDER BY shipsort&quot;,$db);
while ($row = mysql_fetch_array($getlist)) {
$lship = $row[&quot;ship&quot;];
echo &quot;\&quot;$lship\&quot;&quot;;
echo &quot;,\n&quot;;
}
echo &quot;);\n&quot;;
?>

The trouble is that the last ship variable shouldn't include the comma on the end. (As per the list above).

Anyone have any ideas on how I can leave the comma off the last returned entry.
 
var pages = new makeArray(&quot;Select a ship on this page&quot;,

<?php
$getlist = mysql_query(&quot;SELECT * FROM imgships WHERE ship like '$currsltr%' ORDER BY shipsort&quot;,$db);
$lngCount = mysql_num_rows($getlist);
$lngCurrent = 1
while ($row = mysql_fetch_array($getlist)) {
$lship = $row[&quot;ship&quot;];
echo &quot;\&quot;$lship\&quot;&quot;;
if ($lngCurrent != $lngCount) {
// hide if current is max number
echo &quot;,\n&quot;;
}
$lngCurrent ++
}
echo &quot;);\n&quot;;
?>

You may have to alter the order of the counter call.. but, this gives you an idea... HTH Scott Cybak
scott@athree.com
 
Thanks, I figured I'd have to use a counter but couldn't get my head around it. Too much coffee probably.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top