Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.