Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    167
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Select option to display all the row data

    Hi,

    I have table for the user login where where there is field with the username.


    now in an form I am trying to created a select field which should show all these user names...

    I have try to use while loop but I am not success....


    Any suggestions to the same ??


    regards,
    nani

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,095
    Thanks
    11
    Thanked 101 Times in 99 Posts
    really need more info to help assuming mysql you might end up with something like this...
    PHP Code:
    <?php
    $q
    =mysql_query("SELECT $username_field,$username_id FROM $user_table");
    while(
    $r=mysql_fetch_assoc($q)){
           
    $ops[]="<option value=\"{$r[$username_id]}\">{$r[$username_field]}</option>";

    ?>
    ...in your form...
    <select name="user"><?php echo explode($ops);?></select>
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • Users who have thanked firepages for this post:

    nani_nisha06 (11-12-2012)

  • #3
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    167
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by firepages View Post
    really need more info to help assuming mysql you might end up with something like this...
    PHP Code:
    <?php
    $q
    =mysql_query("SELECT $username_field,$username_id FROM $user_table");
    while(
    $r=mysql_fetch_assoc($q)){
           
    $ops[]="<option value=\"{$r[$username_id]}\">{$r[$username_field]}</option>";

    ?>
    ...in your form...
    <select name="user"><?php echo explode($ops);?></select>
    ?>
    Firepages,

    Although i have customized another 20% on the above code it worked like a charm.

    Thanks

    Regards,
    nani

  • #4
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    167
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by nani_nisha06 View Post
    Firepages,

    Although i have customized another 20% on the above code it worked like a charm.

    Thanks

    Regards,
    nani
    But i am worried about the notice it still displaying with the expected output?


    Notice: Undefined variable: item in C:\xampp\htdocs\MYM\index.php on line 41

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by nani_nisha06 View Post
    But i am worried about the notice it still displaying with the expected output?


    Notice: Undefined variable: item in C:\xampp\htdocs\MYM\index.php on line 41
    Is 'item' related to either of these property names?
    Looks to me that it won't have anything to do with this block of code. This is part of the joy when it comes to using unknown data with things that should be hard coded structures (such as SQL). You simply need to use isset checks to see if it exists before attempting to read from the array (whichever this error represents).

  • #6
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    167
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    Is 'item' related to either of these property names?
    Looks to me that it won't have anything to do with this block of code. This is part of the joy when it comes to using unknown data with things that should be hard coded structures (such as SQL). You simply need to use isset checks to see if it exists before attempting to read from the array (whichever this error represents).
    Thanks Fou-Lu,

    Now I have closed this issue by declaring null to the item variable...

    Regards,
    Nani

  • #7
    New Coder
    Join Date
    Apr 2010
    Posts
    55
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Turning off PHP notice is fine. These are not really errors and you are likely to have a few of them unless you are very careful and correct.

    This should help:
    error_reporting(E_ALL ^ E_NOTICE);

    http://php.net/manual/en/function.error-reporting.php
    Hosting Reviews and Discounts: Bluehost Coupon and Hostmonster Coupon

  • #8
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    167
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by alemcherry View Post
    Turning off PHP notice is fine. These are not really errors and you are likely to have a few of them unless you are very careful and correct.

    This should help:
    error_reporting(E_ALL ^ E_NOTICE);

    http://php.net/manual/en/function.error-reporting.php
    Thanks alemcherry,


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •