0

Hi there me again, sry for the many questions but only way to learn for me is to try (even if I cant succeed)
Please feel free to ask any questions of me if I'm not being clear :)

What i'm trying to do is basically a auto-select or I guess it might be considered a chain select.
The player would select their UPPER armor from the form and the other dropmenus would change to the same series automatically. I'm not sure if this would be easier accomplished in another manner but I was kinda looking at something like This.

Only tough part is the menus are all populated by a database query.

Here is the part of the form that would be effected by this.

<form method="post" action="player_h_insert_2.php">
<table>
    <tr>
        <th>Upper Body  </th>
        <td><select size="1" name="Mainuppertype">
            <option value="" selected>Select Your Main Class Upper Armor</option>
<?php
include('../../lib/connections/connect-mysql.php');

$sql3="SELECT upper FROM armor Order by grade asc, upper asc";
$results = mysqli_query($dbcon,$sql3) or die();

while($row = mysqli_fetch_array($results)) {

      echo '<option value="'.$row['upper'].'">'.htmlspecialchars($row['upper']).'</option>'; 
  }                         
?>
            </select>
        </td>
    </tr>
    <tr>
        <th>Lower Body</th>
        <td><select size="1" name="Mainlowertype">
            <option value="" selected>Select Your Main Class Lower Armor</option>
<?php
include('../../lib/connections/connect-mysql.php');

$sql3="SELECT lower FROM armor Order by grade asc, lower asc";
$results = mysqli_query($dbcon,$sql3) or die();

while($row = mysqli_fetch_array($results)) {

      echo '<option value="'.$row['lower'].'">'.htmlspecialchars($row['lower']).'</option>'; 
  }                         
?>          
            </select>
        </td>
    </tr>
    <tr>
        <th>Helm</th>
        <td><select size="1" name="Mainheadtype">
            <option value="" selected>Select Your Main Class Helmet Armor</option>
<?php
include('../../lib/connections/connect-mysql.php');

$sql3="SELECT head FROM armor Order by grade asc, head asc";
$results = mysqli_query($dbcon,$sql3) or die();

while($row = mysqli_fetch_array($results)) {

      echo '<option value="'.$row['head'].'">'.htmlspecialchars($row['head']).'</option>'; 
  }                         
?>
            </select>
        </td>
    </tr>
    <tr>
        <th>Hands</th>
        <td><select size="1" name="Mainhandtype">
            <option value="" selected>Select Your Main Class Glove Armor</option>
<?php
include('../../lib/connections/connect-mysql.php');

$sql3="SELECT hands FROM armor Order by grade asc, hands asc";
$results = mysqli_query($dbcon,$sql3) or die();

while($row = mysqli_fetch_array($results)) {

      echo '<option value="'.$row['hands'].'">'.htmlspecialchars($row['hands']).'</option>'; 
  }                         
?>
            </select>
        </td>
    </tr>
    <tr>
        <th>Feet</th>
        <td><select size="1" name="Mainfoottype">
            <option value="" selected>Select Your Main Class Boot Armor</option>
<?php
include('../../lib/connections/connect-mysql.php');

$sql3="SELECT feet FROM armor Order by grade asc, feet asc";
$results = mysqli_query($dbcon,$sql3) or die();

while($row = mysqli_fetch_array($results)) {

      echo '<option value="'.$row['feet'].'">'.htmlspecialchars($row['feet']).'</option>'; 
  }                         
?>
            </select>
        </td>
    </tr>
</table>
<input type="submit" value="Insert Info"></p>
<input type="hidden" name="submitted" value="true" />
</form>

So what i'm hoping to do is... if for example the player were to select 'Eternal Breastplate' from the first menu (upper) the others would fill with the matching set pieces (Eternal gaiters, eternal gauntlets etc.)

In the database the corresponding pieces to the set share the same record if this makes it any helpful

If there may be some easier way to do this that I cant find or that you know of please indulge me a link <3

thankyou so very much for your time and help in advance once again

2
Contributors
3
Replies
19
Views
3 Years
Discussion Span
Last Post by urtrivedi
0

I have my own library function to fill combo box

    function fillcombo($dblink,$cmbname,$width,$query,$keycolname,$desccolname,$defaultvalue="",$initialtext="",$othertags="")
    {

        $elementstring="";
        $elementstring ="\n<SELECT id={$cmbname} style='WIDTH: {$width}px' size=1 name={$cmbname} {$othertags}>";

        if (trim($initialtext)!="")
        {
              $elementstring .=  "\n<OPTION value=''";
            if (trim($defaultvalue)=="")
                $elementstring .= " selected";
            $elementstring .=">---{$initialtext}---</OPTION>";
         }           

         $results = mysqli_query($dblink,$query)or die("Query Failed..<hr>" . mysqli_error());
         if ($results)
         {
            while($row = mysqli_fetch_array( $results))
            {

                 $elementstring .= "\n";
                    $elementstring .=  "<OPTION value='".$row[$keycolname]."' title=\"".$row[$desccolname]."\" ";
                    if (trim($row[$keycolname])==$defaultvalue)
                       $elementstring .= " selected";
                    $elementstring .=">{$row[$desccolname]}</OPTION>";
            }
         }
         $elementstring .="\n</SELECT>";



            return $elementstring;


    }

It can be called like given below

echo fillcombo($dblink,"cmbcountry","200px","select id, desc from table","id","desc","25","select value"," style='attribute:value'"));
0

@ urtrivedi
do you have a working sample of this so I can see how it looks its just a lil confusing for me just on reading the code
thnx

0

This is fulll working code,

If you have library file copy above function in that file

Or copy in the page you want to use directly

then call it in your html

Set mysql connection in variable $dblink before following code

<table>
<tr>
<td> Country </td>

<td> <?php 
echo fillcombo($dblink,"cmbcountry","200px","select id, desc from table","id","desc","25","select value"," style='attribute:value'")); 
?>
  </td>

</tr>
</table>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.