Note that there are some explanatory texts on larger screens.

plurals
  1. POEcho data from database in each times get
    text
    copied!<p>I send three times values <code>1</code> &amp; <code>2</code> &amp; <code>3</code> by <code>jquery.serialize()</code> for <code>$hotel_id</code> in PHP, now i want get in the each times from send, data linked with <code>$hotel_id</code>(like: <code>1</code> or <code>2</code> or <code>3</code>) from database. but in the following code i just get data that linked to last <code>$hotel_id</code>(<code>3</code>).</p> <p>I want as:</p> <blockquote> <p><strong>First</strong>: get data linked with <code>1</code> and echo they in <code>json_encode</code><br> <strong>Second</strong>: (next 2) get data linked with <code>2</code> and echo they in <code>json_encode</code><br> <strong>Third</strong>: (next 3)get data linked with <code>3</code> and echo they in <code>json_encode</code><br>...</p> </blockquote> <p>This is output <code>serialize()</code> from jQuery code:</p> <pre><code>hotel_id=1&amp;hotel_id=2&amp;hotel_id=3 </code></pre> <p>This is my php code:</p> <pre><code>$hotel_id = $this-&gt;input-&gt;post('hotel_id'); $query_r = $this-&gt;db-&gt;query("SELECT * FROM hotel_submits WHERE id LIKE '$hotel_id' ORDER BY id desc"); $data = array(); foreach ($query_r-&gt;result() as $row) { $data_s = json_decode($row-&gt;service, true); $data_rp = json_decode($row-&gt;address, true); $data[] = array( 'name' =&gt; $row-&gt;name, 'star_type' =&gt; $row-&gt;star . '-' . $row-&gt;type, 'site' =&gt; $row-&gt;site, 'service' =&gt; $data_s, 'address' =&gt; $row-&gt;address ); } echo json_encode($data); </code></pre> <p>How do i do?</p>
 

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