Problem in fetching !!!

Discussion in 'PHP' started by pulikuttann, Mar 31, 2007.

  1. #1
    I am on the way of one accounting package using php.

    On my one page I want to fetch one of the attributes (full), of a table and display it as a select key.How can I do it.Now with this code I can only get the last value in that attribute.So plz help me.I want the complete values here.

     
    pulikuttann, Mar 31, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    you're loop is incorrect, like this :

    
    <form action="Managing.php" method="post">
    <p>&nbsp; </p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>
    <center>
    <select name="ondate">
    <?
    while($row=mysql_fetch_array($result))
    {
    ?>
    <option value="<?php print $row['Date'];?>"><?php print $row['Date'];?></option>
    <?php
    }
    ?>
    </select>
    <br /><p>
    <input type="submit" value="Manage" />
    </p>
    </form>
    
    PHP:
    I haven't checked the code, but the loop is wrong fix that first.....
     
    krakjoe, Mar 31, 2007 IP
  3. pulikuttann

    pulikuttann Banned

    Messages:
    1,839
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The loop works but I need to see all the dates under select button.Plz help !!!
     
    pulikuttann, Mar 31, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    the loop may well work, but as I said it is incorrect, when looping you only need to loop over html that you need more than once, so having all that html inside the while loop will not give the correct results no matter what.
     
    krakjoe, Mar 31, 2007 IP
  5. pulikuttann

    pulikuttann Banned

    Messages:
    1,839
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I can't get u friend.Plz help !!!
    Give a sample code to make all my fetched data inside the select
     
    pulikuttann, Mar 31, 2007 IP
  6. dp-user-1

    dp-user-1 Well-Known Member

    Messages:
    794
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #6
    You don't need to keep putting "!!!" in all your thread titles/posts...
     
    dp-user-1, Mar 31, 2007 IP
  7. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #7
    
    <?
    $con=mysql_connect("localhost","root","");
    if( !$con ) : mysql_error( ); exit; endif;
    
    mysql_select_db("billing");
    
    $result=mysql_query("SELECT Date FROM `bill`");
    ?>
    <form action="Managing.php" method="post">
    <p>&nbsp; </p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>
    <center>
    <select name="ondate">
    <?
    //fetching from database
    while( $row = mysql_fetch_assoc( $result ) )
    {
    ?>
    <option value="<?=$row['Date'] ?>"><?=$row['Date'] ?></option>
    <?
    }
    mysql_close($con);
    ?>
    </select>
    <br /><p>
    <input type="submit" value="Manage" />
    </p>
    </form> 
    
    PHP:
    Give that a whirl ....
     
    krakjoe, Mar 31, 2007 IP
  8. pulikuttann

    pulikuttann Banned

    Messages:
    1,839
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #8
    returns this error !!!
     
    pulikuttann, Mar 31, 2007 IP
  9. pulikuttann

    pulikuttann Banned

    Messages:
    1,839
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thankz friend.With certain small mod I have recovered from it.
     
    pulikuttann, Mar 31, 2007 IP
  10. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You were looping the whole select instead of the options :)
     
    manilodisan, Apr 1, 2007 IP