Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax concatenate select and total record query
    text
    copied!<p>I've a php page where there is a ajax concatenate select and a div with the total number of records in the table tb1</p> <p>HTML</p> <pre><code>&lt;p&gt; &lt;select name="model" id="model"&gt; &lt;?php echo $myclass-&gt;selModel(); ?&gt; &lt;/select&gt; &lt;/p&gt; &lt;br /&gt; &lt;p&gt; &lt;select name="year" id="year"&gt; &lt;option value=""&gt;&amp;nbsp;&lt;/option&gt; &lt;/select&gt; &lt;/p&gt; &lt;p&gt; &lt;div id="total"&gt;&lt;?php echo $myclass-&gt;recordNum();?&gt;&lt;/div&gt; &lt;/p&gt; </code></pre> <p>JS</p> <pre><code>// VARS var wait = '&lt;option&gt;Waiting&lt;/option&gt;'; var select = '&lt;option value=""&gt;Select&lt;/option&gt;'; // CAT_1 // $("select#model").change(function(){ var model = $("select#model option:selected").prop("value"); $("select#year").html(wait); $.post("ajax-php/select-concat.php", {model:model}, function(data){ switch (data) { case select: $("select#year").html(""); return false; default: $("select#year").prop("disabled", false); $("select#year").html(data); return false; } }); }); </code></pre> <p>PHP - select-concat.php</p> <pre><code>if(isset($_POST['model'])) { echo $myclass-&gt;selYear(); die; } </code></pre> <p>MY PHP CLASS</p> <pre><code>public function selYear() { $result = $this-&gt;db-&gt;mysqli-&gt;query ("SELECT year FROM tb1 WHERE model='$_POST[model]"); $year = '&lt;option value=""&gt;Select&lt;/option&gt;'; while($row = $result-&gt;fetch_assoc()) { $year .= '&lt;option value="' . $row['year'] . '"'; $year .= '&gt;' . $row['year'] . '&lt;/option&gt;'; } return $year; } private function recordNum(){ $result = $this-&gt;db-&gt;mysqli-&gt;query ("SELECT * FROM tb1 WHERE something "); $numrec = $result-&gt;num_rows; return $numrec; } </code></pre> <p>My goal is to update the number of records with ajax every time I run a concatenate select. How could I do that? Thanks</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