Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of generating the JSON yourself use <a href="http://www.php.net/manual/en/function.json-encode.php" rel="nofollow"><code>json_encode</code></a> to do the heavy lifting for you.</p> <pre><code>$keywords = array (); while ( $rs=mysql_fetch_array($result)) { $keywords[] = $rs['keywords']; } echo json_encode ($keywords); </code></pre> <p><strong>Preferred solution</strong></p> <p>Though if you plan on using <code>json_encode</code> append $keywords to your other set of data and use <code>json_encode</code> on the whole structure.</p> <pre><code>$json_data = array ( 't' =&gt; '', 'r' =&gt; array () ); while ( $rs=mysql_fetch_array($result)) { $json_data['r'][] = $rs['keywords']; } echo "(".json_encode ($json_data).")"; </code></pre> <hr> <p>If you'd like to do it yourself there are a few (rather clean) options available, see the snippets below.</p> <hr> <p>Append all retrieved keywords to an array and use <a href="http://se.php.net/manual/en/function.join.php" rel="nofollow"><code>join</code></a> with ',' as delimiter to form a string after your while loop   $keyword_array = array (); </p> <pre><code>while ($rs=mysql_fetch_array($result)) { $keywords=$rs[keywords]; $keyword_array = "\"$keywords\""; } echo join (', ', $keywords); </code></pre> <hr> <p>Use <a href="http://se.php.net/manual/en/function.mysql-num-rows.php" rel="nofollow"><code>mysql_num_rows</code></a> before your while loop to get the number of rows in <code>$result</code>, and don't append a <code>,</code> when you are processing the last element.</p> <pre><code>$n_rows = mysql_num_rows ($result); for ($i =1; $rs = mysql_fetch_array ($result); ++$i) { $keywords=$rs[keywords]; echo "\"$keywords\""; if ($i != $n_rows) echo ", "; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload