简体   繁体   中英

Search through a table column

I have a table called modules, and a table column (varchar) called "type", in which I input data from 4 radio buttons (either select, text, boolean or numeric). Now I want to edit this data, let's say if the certain row in the table has the type column boolean, I want to do something. If it has Numeric, I want to do something else, etc. How do I search through the data and write it out? And I don't want to group them - I don't want all the "text ones" to be together, I want to write them out with the increasing ID.

My table looks like this:

ID=1 type=text, ID=2 type=boolean, ID=3 type=select, ID=4 type=numeric,... 

Now I want to write it out in html. Lets just say I want to make it like this: loop through, check what the "type" in the first one is, and write it out.

I have a primary key, it's the ID and it's auto increment.

Users use radio buttons to select which type a parameter is. So I am displaying all these parameters in html. if it's a text type, I want to display a text field, if it's a boolean I want to display 2 radio buttons (YES/NO), if it's numeric I want to display a text field, and if it's select I want to display a select box. I'm very new to php and I don't know how else to explain it.

The part where users select which type it is is done, and I am updating my table modules...I don't know now how to check what the "type" in every row is, so I can write them out differently.

Do this :

$select = mysql_query("select * from modules order by ID asc") or die(mysql_error());
while($row = mysql_fetch_array($select))
{
    if($row['type']=="text")    
    {
        echo '<input type="text" name="text_field_name_'.$row['ID'].'" id="text_field_name_'.$row['ID'].'" value="Text Field">';
    }
    else if($row['type']=="numeric")    
    {
        echo '<input type="text" name="numeric_field_name_'.$row['ID'].'" id="numeric_field_name_'.$row['ID'].'" value="Numeric Field">';
    }
    else if($row['type']=="boolean")    
    {
        echo '<input type="radio" name="boolean_field_name_'.$row['ID'].'" id="boolean_field_name_'.$row['ID'].'" value="Yes">Yes&nbsp;
          <input type="radio" name="boolean_field_name_'.$row['ID'].'" id="boolean_field_name_'.$row['ID'].'" value="No">No';
    }
    else if($row['type']=="select") 
    {
        echo '<select name="combo_field_name_'.$row['ID'].'" id="combo_field_name_'.$row['ID'].'">
          <option>-----Select-----</option>
    </select>';
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM