how to perform query based on listbox

Discussion in 'PHP' started by kharearch, Jan 26, 2008.

  1. #1
    I have following fields on the form

    Bank, Personal loan, Home Loan, Education loan

    Listbox, text box, text box, text box


    On pressing bank list box I want to show matching record from loan table. How can I do this. Can I attach some event to listbox. All the fields are on the same form
     
    kharearch, Jan 26, 2008 IP
  2. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #2
    It's very simple. Try to learn some basic PHP online tutorials at http://www.w3schools.com/

    Here is the code. No need for any 'event'.
    
    echo '<select>';
    $res = mysql_query('SELECT loan_id, loan_name from loan_table'); // add your query here
    	if($res){
    		while($row = mysql_fetch_array($res)){
    			echo "\t\t<option value=\"" .$row[0] ."\"";
    			if ($row[0] == $sel) echo " Selected";
    			echo ">" .$row[1] ."</option>\n";
    		}
    	}
    echo '</select>';
    
    PHP:
     
    greatlogix, Jan 26, 2008 IP
  3. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think it's more to this;

    echo '<select>';
    $res = mysql_query('SELECT loan_id, loan_name from loan_table'); // add your query here
        if($res){
            while($row = mysql_fetch_array($res)){
                echo "\t\t<option value=\"" .$row[0] ."\"";
                if ($row[0] == $sel) echo "selected=\"selected\"";
                echo ">" .$row[1] ."</option>\n";
            }
        }
    echo '</select>';
    PHP:
     
    fairuz.ismail, Jan 26, 2008 IP