Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to explode a string before return it with ajax to a select/option dynamic
    primarykey
    data
    text
    <p>So, i got a pretty bad database that i CAN'T transform.</p> <p>The string is 5numbers like: 180,2345,123,5643,23534</p> <p>I need to put those numbers(need to explode somehow) in a select option like this:</p> <pre><code>&lt;select name="hotel" id="hotel" class="fieldbackend"&gt; &lt;option value="403"&gt;403&lt;/option&gt; &lt;option value="880"&gt;880&lt;/option&gt; &lt;option value="983"&gt;983&lt;/option&gt; &lt;option value="648"&gt;648&lt;/option&gt; &lt;/select&gt; </code></pre> <p>Presently i got this result:</p> <pre><code>&lt;select name="hotel" id="hotel" class="fieldbackend"&gt; &lt;option value="undefined"&gt;undefined&lt;/option&gt; &lt;option value="undefined"&gt;undefined&lt;/option&gt; &lt;option value="undefined"&gt;undefined&lt;/option&gt; &lt;option value="undefined"&gt;undefined&lt;/option&gt; &lt;option value="403,880,983,648"&gt;403,880,983,648&lt;/option&gt; &lt;/select&gt; </code></pre> <p>There is my source code:</p> <pre><code>&lt;select class="fieldbackend" id="destination" name="destination"&gt; &lt;option value=""&gt;-- Destination --&lt;/option&gt; &lt;/select&gt; &lt;select class="fieldbackend" id="hotel" name="hotel"&gt; &lt;option value=""&gt;-- Hôtel --&lt;/option&gt; &lt;/select&gt; </code></pre> <p>There is my JS:</p> <pre><code>$(function(){ $('#destination').change(function(){ $.getJSON('/dev/select2.php', {'destination': $(this).val()}, function(data) { var items = ''; $.each(data, function(key, val) { items += '&lt;option value="' + val['deHotels'] + '"&gt;' + val['deHotels'] + '&lt;/option&gt;'; }); $('#hotel').html(items); }); }); }) </code></pre> <p>Finaly there is my php code:</p> <pre><code>$requete = "SELECT DISTINCT deHotels FROM sirev_Dests WHERE deDestName = '". $_GET['destination'] ."' ORDER BY deDestName"; $connect = mysql_connect("&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;","&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;","&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;"); mysql_select_db("&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;", $connect); $res = mysql_query($requete) or die(mysql_error()); while ($row = mysql_fetch_assoc($res, true)) { $items = explode(',',$row['deHotels']); array_push($items, $row); } die(json_encode($items)); </code></pre> <p>There is a screen of the result: <a href="http://nsa29.casimages.com/img/2012/06/01/120601072406136633.jpg" rel="nofollow">http://nsa29.casimages.com/img/2012/06/01/120601072406136633.jpg</a></p> <p>Sorry for my english, im from quebec city.</p> <p>Any one can help me to figure it out?</p>
    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. 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