Jump to content

going crazy over "implode"


dtyson2000

Recommended Posts

Hi Folks...

I'm going nuts with this implode function. I just need to list a distinct group of cities pulled from a database as a comma separated list with no comma after the last city. So I have been playing with this and the best I can do is get it to list each city name twice. Can you see something that I'm missing?

while ($row= mysql_fetch_array($result)){
$city=mysql_result($result,$i,"city");
echo implode(', ', $row);
$i++;
}

Thanks, in advance!
Link to comment
https://forums.phpfreaks.com/topic/15413-going-crazy-over-implode/
Share on other sites

Use [i]mysql_fetch_assoc()[/i] or [i]mysql_fetch_array($result,MYSQL_ASSOC)[/i]

To elaborate:
[b]mysql_fetch_array [/b] ( resource result [, [u][i]int result_type[/i][/u]] )

[i]result_type[/i]
The type of array that is to be fetched. It's a constant and can take the following values: MYSQL_ASSOC, MYSQL_NUM, [u]and the default value of MYSQL_BOTH[/u].

Leaving "result_type" will return values twice; once with numeric, once with associative keys.

Archived

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

×
×
  • Create New...

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.