Problem with generating the php code.

I´m trying using php to generate a set of “{URL.callback}” to use in javascript. By using database. Here is my code:
[php]
$sql="select * from tb_search where keywords LIKE ‘$bb%’ ORDER BY keywords ASC LIMIT 0, 15 ";

 $result=mysql_db_query($dbname,$sql);

 echo $_GET["callback"] . "({ t:\"$t\", r:[";
while ( $rs=mysql_fetch_array($result))    {
	$keywords=$rs[keywords];

     echo "" ."\"$keywords\"".","." ";
}

echo"] })";

[/php]

Everything seemed to be correct except the (,) in the end (after “example3”) that I want to get rid. because it´s not correct and can not be use with that.

HERE IS THE FINAL CODE I GOT:
({ t:"", r:[“example1”, “example2”, “example3”,] })


The question is: How to generate it correctly ? How to get rid the last (,) ?

Please help me
Alex.

Try this:
[php]$arr = array();
while ( $rs=mysql_fetch_array($result)) {
$arr[] = $rs[‘keywords’];
}
if(count($arr)) echo $_GET[“callback”] . “({ t:”$t", r:["".implode(’", “’, $arr).”"] })";[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service