vendredi 6 juin 2014

Handling isset and select box in php html and for loop


Vote count:

0




Here is my code. This needs some optimization if you think the below code is bad and someone can really help me




  1. I'm using two if condition and two else condition. Is there anyway this can be fine-tuned.




  2. In the search box i need to retain the previous selected book name. i.e when the submit button is clicked the select box should display the result with the selected item in the select box. for ex: if in dropdown if i select "book1" and click the submit button, the result should be displayed along with the "book1" as default inside the select box. in my case, the search box is getting reset on each submit click.



    <?php
    if(isset($_POST['submit'])){
    $get_project_id = $_POST['project_name'];
    if($get_project_id == 1){
    ..display all the books(mysql query)..
    }else{
    ..display the particular book(mysql query)..
    }
    }
    else{
    ..if the search button is not clicked then display all the books(mysql query)..
    }
    ?>
    <form method="post" name="book_list">
    <select name="book_list" id="book_list">
    <option value="1">All Books</option>
    <?php while($row=mysql_fetch_array($result_books)){?>
    <option value="<?php echo $row['Project_Auto_Id'];?>">
    <?php echo $row['Book_Id']. " - ".$row['Book_Name'] ;?>
    </option>
    <?php }?>
    </select>
    <input type="submit" name="submit" class="btn btn-default pull-right" value="Search"/>
    </form>



Any help will be appreciable.


Than,ks Kimz



asked 36 secs ago






Aucun commentaire:

Enregistrer un commentaire