Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23
  1. #11

    try this one, i think sa closing and opening php tags nimo bro and some syntax error

    Code:
    <?php
    //Connect to MySQL:
    $db_connection = mysql_connect ("localhost","root","");
    
    //Select the database
    mysql_select_db("tutorial");
    
    //I have the following SQL statement and execution:
    $get_list = "SELECT * FROM employee";
    $get_list_result = mysql_query($get_list) or die (mysql_error());
    ?>
    //Then I want to display the value from database in the drop down list with the code below:
    <html>
    <body>
    <td><select name="sel_id">
    <?php 
    while ($recs = mysql_fetch_array($get_list_result)){
    $id = $recs['AREA_ID'];
    $display_list = $recs['RESP_AREA'];
    ?>
    <option value="<?php echo $id; ?>"><?php echo $display_list; ?></option> 
    <?php
    }// end while
    ?>
    </select>
    </td>
    </body>
    </html>

  2. #12
    @krissy: i've tried your codes. naa ang select but walay sulod. akong db is naa man siyay sulod. 3 rows.

  3. #13
    @krissy: or pwede pud another way na mas sayon to uderstand....

  4. #14
    nganu wala man sulod? try to check your fields daw.

    or try a foreach loop instead of a while loop. Im not good at native php coding, im used to codeigniter framework kay mas dali...hehehe

  5. #15
    PHP Code:
    <?php
    //Connect to MySQL:
    $db_connection mysql_connect ("localhost","root","");

    //Select the database
    mysql_select_db("world");

    //I have the following SQL statement and execution:
    $get_list "select * from CITY where district='Central Visayas';";
    $get_list_result mysql_query($get_list) or die (mysql_error());

    //Then I want to display the value from database in the drop down list with the code below:

    ?>
    <html>
    <body>
    <td><select name="sel_id">
    <?php 
    while ($recs mysql_fetch_array($get_list_result)){

    //$id = $recs['id'];
    //$display_list = $recs['name'];
    //remove these variables - why use another when you can directly use the $recs

    ?>
    <option value="<?php echo $recs['ID']; ?>"><?php echo $recs['Name']; ?></option> 
    <?php
    }// end while
    ?>
    </select>
    </td>
    </body>
    </html>
    I used your PHP code in my DB, and it worked with a little bit of tweaking the code. Be very careful with the column names of your table, you need to refer to them correctly. In your case, $recs['AREA_ID'] and $recs['RESP_AREA'] are they declared uppercase in your table? If not, then check your definition, that may be the source of the blank items in the select list.
    Last edited by ChaosOrb; 01-20-2011 at 03:46 AM.

  6. #16
    wa ku kasabut sa PHP ay.. sa HTML raku kasabut..

    naa lagi program ipa run para basahun ang PHP..

  7. #17
    My approach would be this way...


    Code:
    <td>
    <select id="employee_id">
    <?php //START OF PHP TAG
    #.... considering you have already connected to your database
    
    $res = mysql_query("select id, name from mydatabase.mytable_name"); //replace the following queries with your defined mysql table
    
    while(list($id,$name) = mysql_fetch_array($res)) {
         echo "<option value=\"".$id.\"">".$name."</option>";     
    }
    ?> //END OF PHP TAG
    </select>
    </td>
    Last edited by psyche54; 01-21-2011 at 08:44 AM.

  8. #18
    Quote Originally Posted by Crimson_Viper View Post
    wa ku kasabut sa PHP ay.. sa HTML raku kasabut..

    naa lagi program ipa run para basahun ang PHP..
    na ako bro kay nag praktis with my own ra jud ni. dako kaau nako pasalamat aning mga masters nga nag laag dre sa istorya kay makat.on tag ahat. hehehehe

    naa bai thread dre sa istorya na maka ask tag about php or kana pud para sa mga beginners?

    please post if naa kay mo apil apil ko. hehehehe

  9. #19
    Quote Originally Posted by psyche54 View Post
    My approach would be this way...


    Code:
    <td>
    <select id="employee_id">
    <?php //START OF PHP TAG
    #.... considering you have already connected to your database
    
    $res = mysql_query("select id, name from mydatabase.mytable_name"); //replace the following queries with your defined mysql table
    
    while(list($id,$name) = mysql_fetch_array($res)) {
         echo "<option value=\"".$id.\"">".mysql_real_escape_string($name)."</option>";     
    }
    ?> //END OF PHP TAG
    </select>
    </td>
    Dili naman cguro kailangan ang mysql_real_escape_string pag mag retrieve ka data from database gawas nalang cguro kung mag store ka data to database.

  10. #20
    Quote Originally Posted by prokops View Post
    Dili naman cguro kailangan ang mysql_real_escape_string pag mag retrieve ka data from database gawas nalang cguro kung mag store ka data to database.
    yeah you are right sis... tnx for that.. I haven't noticed that one... Just copied it from one of my insert string... I corrected it anyway

  11.    Advertisement

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

 
  1. vb 6 to database date from to from table how?
    By ventura in forum Programming
    Replies: 5
    Last Post: 11-23-2007, 02:40 PM
  2. HOW TO ADD RECORD to database from ASP using jscript
    By hybrid_X in forum Programming
    Replies: 4
    Last Post: 05-22-2007, 04:56 PM
  3. JAVASCRIPT: how to object value from window.open()
    By hybrid_X in forum Programming
    Replies: 0
    Last Post: 04-09-2007, 01:45 PM
  4. Replies: 1
    Last Post: 10-04-2006, 09:18 AM
  5. What can beat this all-in-one cellphone from BIRD@ only 12k Php?
    By ftray in forum Gizmos & Gadgets (Old)
    Replies: 4
    Last Post: 11-07-2005, 04:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top