>Iíve been fooling around with a LOOP which should show one or more text
>string stored in separate rows in a DB. The trick would we to separate
>them with commas (,) when thereís another string to show or end it with
>a period (.) if no other row is found according to the SELECT criteria.
>This is what I have so far:
>
>for ($m=0; $m<$num_rows2; $m++)
>{
>$row2 = mysql_fetch_array($result2);
>
>echo $row2[devlanguage];
>
>if ($m < $num_rows2)
>{
>echo ", ";
>}
>else
>{
>echo ".";
>}
>}
>
>The problem is that the LOOP stops as itís told to do, keeping the ELSE
>statement from doing itís work, resulting in comma separated string as
>it should, but also add an extra comma at the end of it instead of a
>period. What approach should I use?

This is a case where doing echo as you go is not so good, because you can't
take it back :-)

$output = '';
while (list($devlanguage) = mysql_fetch_row($result2)){
  $output .= "$devlanguage, ";
}
# Strip off final comma:
$output = substr($output, 0, -2);
$output .= ".";
echo $output;

--
Like Music?  http://l-i-e.com/artists.htm


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to