Note that there are some explanatory texts on larger screens.

plurals
  1. POphp drop down list
    primarykey
    data
    text
    <p>i’m new to codeigniter and i’m working on a project. i have to create a dynamic drop down menu with values from my database, when a selection is made in the drop down as soon as you click on the submit button a new page has to occur where all the cities associated with the province selected in the drop menu appear, the cities are also in my database .My database consists of an id field, province field and a cities field.The drop menu is fine but cant seem to make the cities appear in the next page. your help will be highly appreciated ok here's my code</p> <p>this is from my view file which displays my drop menu this side is ok</p> <pre><code>&lt;? function writeCities($id) { $con = mysql_connect("localhost","root",""); if (!$con) die('Could not connect: ' . mysql_error()); mysql_select_db("msansi", $con); $query = "SELECT cities FROM provinces WHERE id ="; $query .= $id; $result = mysql_query($query); $row = mysql_fetch_array($result); echo $row[0]; } function populateDropBox() { $con = mysql_connect("localhost","root",""); if (!$con) die('Could not connect: ' . mysql_error()); mysql_select_db("msansi", $con); $result = mysql_query("SELECT id,title,cities FROM provinces"); while($row = mysql_fetch_array($result)) { echo "&lt;option value=$row[0]&gt;" . $row['title']."&lt;/option&gt;"; } } ?&gt; </code></pre> <hr> <pre><code>&lt;form name="myform" action="http://localhost/CodeIgniter_1.7.3/index.php/ndivhuho/submit" method="post"&gt; &lt;select name = "province" onChange="onChangeDropBox();"/&gt; &lt;? populateDropBox(); ?&gt; &lt;input type="submit" value="submit"; /&gt; &lt;/form&gt; </code></pre> <p>and here's my other view file which is supposed to display the cities in a text area</p> <pre><code>&lt;? function writeCities($id) { $con = mysql_connect("localhost","root",""); if (!$con) die('Could not connect: ' . mysql_error()); mysql_select_db("msansi", $con); $query = "SELECT cities FROM provinces WHERE id ="; $query .= $id; $result = mysql_query($query); $row = mysql_fetch_array($result); echo $row[0]; } ?&gt; </code></pre> <hr> <pre><code> &lt;script type="text/javascript"&gt; function onChangeDropBox() { var selected =0; selected = document.myform.province.value; var t = "&lt;? writeCities(1);?&gt;"; document.myform.textArea.value = t; } &lt;/script&gt; &lt;form name=myform&gt; &lt;textarea name="citites" readonly="true";&gt;&lt;/textarea&gt; &lt;/form&gt; </code></pre> <p>i'm sure theres something i need to do in my controller which i don't know of thanxx in advance!!! </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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