arjay_comsci Posted August 27, 2009 Share Posted August 27, 2009 function FillList ($sql, $selected=0) { $row = array(); $cnt = 0; $this->query_fill=new Query ($sql, $this->conn); $result=$this->query_fill->subExecute(); while ($row = mysql_fetch_row($result)) { $id = $row[0]; $name = $row[1]; $cnt += 1; if ($selected == $id) { echo "<OPTION value=$id selected>$name</OPTION>"; } else { echo "<OPTION value=$id>$name</OPTION>"; } } $this->query_fill->Free(); return $cnt; Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 27, 2009 Share Posted August 27, 2009 1. use code tags. 2. post a question with any code posted. otherwise, my guess on how to use it is: FillList ($sql, $selected); but that's about as useful as your question. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted August 27, 2009 Share Posted August 27, 2009 $sql = 'SELECT id,name from users'; $selected = 2; echo FillList ($sql, $selected); Quote Link to comment Share on other sites More sharing options...
arjay_comsci Posted August 28, 2009 Author Share Posted August 28, 2009 hi mark,,I really appreciate your effort to my problem..but i want to detail my problem to you.. this is My MysqlClass.php-- there are so many many functions on it but I only include the Function for combo box. // FillList will echo to the page the selected records as options for a selection box // The 1st field selected should be the id and the 2nd should be the description function FillList ($sql, $selected=0) { $row = array(); $cnt = 0; $this->query_fill=new Query ($sql, $this->conn); $result=$this->query_fill->subExecute(); while ($row = mysql_fetch_row($result)) { $id = $row[0]; $name = $row[1]; $cnt += 1; if ($selected == $id) { echo "<OPTION value=$id selected>$name</OPTION>"; } else { echo "<OPTION value=$id>$name</OPTION>"; } } $this->query_fill->Free(); return $cnt; } // ReturnList does the same thing as FillList except that it returns the list // as a string insted of echoing to the page. function ReturnList ($sql, $selected=0) { $row = array(); $cnt = 0; $this->query_return_list=new Query ($sql, $this->conn); $result=$this->query_return_list->subExecute(); while ($row = mysql_fetch_array($result)) { $id = $row[0]; $name = $row[1]; $cnt += 1; if ($selected == $id) { $data .= "<OPTION value=$id selected>$name</OPTION>"; } else { $data .= "<OPTION value=$id>$name</OPTION>"; } } $this->query_return_list->Free(); return $data; } I want to implemetn this to my weeklyevent.php and this is my originasl code without using the function FilList <?php $query="SELECT firstname,id FROM people"; $result = mysql_query ($query); echo "<select name=people id='people' value=''>Location ID</option>"; while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[id]>$nt[id]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> Please help me! Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted August 28, 2009 Share Posted August 28, 2009 Why have two copies of the function, one of which echoes, the other that returns the data? Get rid of the FillList() function completely, just use ReturnList. $query="SELECT id,firstname FROM people"; echo '<select name="people" id="people">'; echo ReturnList($query); echo "</select>"; Quote Link to comment Share on other sites More sharing options...
arjay_comsci Posted September 1, 2009 Author Share Posted September 1, 2009 yeah,,I did used the ReturnList function and it works..thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.