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 9 of 9
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Pulling Value from Table with a drop down

    Okay, so, here's the scenario.

    I have a form that is editing an item that is already in the database. The text fields fill in just fine with that info. However, the drop down menus don't retrieve that info, rather resorting to the defaults, which can be a problem if you don't remember what you originally had.

    Is there anyway to make the dropdown menus pull the info from the table and use that rather than resorting back to the default?

    I tried using this:

    Code:
    <tr><td width="20%">Bonus:</td><td><select name="bonus" value="{{bonus}}">
    <option value="Attack" {{bonus1select}}>Add to the attack power of weapon</option>
    <option value="Defense" {{bonus2select}}>Add to the defensive power of armor</option>
    <option value="None" {{bonus3select}}>No effect</option>
    </select><br /></td></tr>
    So, it's obvious the "value" portion not working. Any help would be great!!

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,420
    Thanks
    68
    Thanked 102 Times in 101 Posts
    Looks like the DK script, correct? If it is add a while loop with a select box in admin.php or if in the game, lib.php

    If it's not that script, then we can talk about what to do.
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It used to be, yeah. I've bastardized it to create a much more involved game, but there are parts of DK that have been swallowed and regurgitated into something different.

    And add a while loop where abouts in the coding?

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,420
    Thanks
    68
    Thanked 102 Times in 101 Posts
    I've used DK before so I know the structure. Sounds like your editing a user in the admin cpanel.

    Setting up a while loop drop down box would look like this.

    PHP Code:
    $query doquery("SELECT * FROM {{table}} WHERE id>'0'""users");
    $page .= '<select name="charname">';
    while (
    $row mysql_fetch_array($query)) {
    $page .= "<option value=\"".$row['charname']."\">".$row['charname']."</option> ";
    }
    $page .= '</select>'
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Okay. That's awesome then!

    Actually, I'm editing items, and there are multiple drop down menus.

    In the form section, (like what I have pasted), do I need to change anything to make this work?

    I pasted what you sent over but changed charname to type (since that is one of the drop down menus) and am trying it out now. How do I, though, make that populate the drop down menu?

    Here is the php on it, so far, before the form:

    PHP Code:
    function edititem($id) {
        
        if (isset(
    $_POST["submit"])) {
            
            
    extract($_POST);
            
    $errors 0;
            
    $errorlist "";
            if (
    $name == "") { $errors++; $errorlist .= "Name is required.<br />"; }
            if (
    $price == "") { $errors++; $errorlist .= "Price is required.<br />"; }
            if (!
    is_numeric($price)) { $errors++; $errorlist .= "Price must be a number.<br />"; }
            if (
    $type == "") { $errors++; $errorlist .= "Type is required.<br />"; }
            if (!
    is_numeric($value)) { $errors++; $errorlist .= "Value must be a number.<br />"; }
            
            if (
    $errors == 0) { 
             
    $query doquery("UPDATE `items` SET `name`='$name', `descript`='$descript', `price`='$price', `type`='$type', `bonus`='$bonus', `slot`='$slot', `target`='$target', `attr`='$attr', `value`='$value' WHERE `id`='$id'""items");
            
    $page .= '<select name="type">';
            while (
    $row mysql_fetch_array($query)) { 
            
    $page .= "<option value=\"".$row['type']."\">".$row['type']."</option> "

            
    $page .= '</select>';  
             
    admindisplay("Item updated.","Edit Items");
            } else {
                
    admindisplay("<b>Errors:</b><br /><div style=\"color:red;\">$errorlist</div><br />Please go back and try again.""Edit Items");
            }        
            
        } 
    Last edited by zelig; 11-22-2011 at 08:32 PM.

  • #6
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    Quote Originally Posted by zelig View Post
    Okay. That's awesome then!

    Actually, I'm editing items, and there are multiple drop down menus.

    In the form section, (like what I have pasted), do I need to change anything to make this work?

    I pasted what you sent over but changed charname to type (since that is one of the drop down menus) and am trying it out now. How do I, though, make that populate the drop down menu?

    Here is the php on it, so far, before the form:

    PHP Code:
    function edititem($id) {
        
        if (isset(
    $_POST["submit"])) {
            
            
    extract($_POST);
            
    $errors 0;
            
    $errorlist "";
            if (
    $name == "") { $errors++; $errorlist .= "Name is required.<br />"; }
            if (
    $price == "") { $errors++; $errorlist .= "Price is required.<br />"; }
            if (!
    is_numeric($price)) { $errors++; $errorlist .= "Price must be a number.<br />"; }
            if (
    $type == "") { $errors++; $errorlist .= "Type is required.<br />"; }
            if (!
    is_numeric($value)) { $errors++; $errorlist .= "Value must be a number.<br />"; }
            
            if (
    $errors == 0) { 
             
    $query doquery("UPDATE `items` SET `name`='$name', `descript`='$descript', `price`='$price', `type`='$type', `bonus`='$bonus', `slot`='$slot', `target`='$target', `attr`='$attr', `value`='$value' WHERE `id`='$id'""items");
            
    $page .= '<select name="type">';
            while (
    $row mysql_fetch_array($query)) { 
            
    $page .= "<option value=\"".$row['type']."\">".$row['type']."</option> "

            
    $page .= '</select>';  
             
    admindisplay("Item updated.","Edit Items");
            } else {
                
    admindisplay("<b>Errors:</b><br /><div style=\"color:red;\">$errorlist</div><br />Please go back and try again.""Edit Items");
            }        
            
        } 
    why do you have that select box in a while loop with a query that is updating the database..

  • Users who have thanked Adee for this post:

    zelig (11-22-2011)

  • #7
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, I guess I'm not entirely sure what is going on then. (long day at work)

    What you sent over was the actual select box? Would I put that into the form portion, and if so, would it then recognize what other options are available so if it needed changed/updated, that could happen?

  • #8
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Figured it out.

    Thanks!

  • #9
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,420
    Thanks
    68
    Thanked 102 Times in 101 Posts
    By the way the DK structure for items is using explode in an array. It's horrible, normalize the database and have every item inserted according to the player.

    Such as ID 1, Player ID: 93, ItemID 12, Amount: 3, etc.
    Been a sign maker for 7 years. My business:
    American Made Signs


  •  

    Posting Permissions

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