Jump to content

HTML and PHP tables


sylesia

Recommended Posts

Ok, I am making a table in HTML, but want to embed PHP into it so I can have, in essence, if else structures.  Working with a DB, I pull out a result and store it in $result.  For example, it might be $result = 'Hi' and the code I would want would be something like
<? if ($result = 'Hi') { ?>
<tr><th>Hello?<td><input  TYPE="checkbox" NAME="StrongDimensions[]" VALUE="Hi" CHECKED>
<? } else { ?>
<tr><th>Hello?<td><input  TYPE="checkbox" NAME="StrongDimensions[]" VALUE="Hi"
<? } ?>

only with 16 boxes 4 times over, that would equal well over 250 line of code to do that, so in essence, I would like for it to be more like...
<? if ($result = 'Hi') {
$check = 'CHECKED;
} else{
$check = '';
}
?>
<tr><th>Hello?<td><input  TYPE="checkbox" NAME="StrongDimensions[]" VALUE="Hi" <? print $check ?> >


so that it only needs one line where all the php can be a loop to do all the others in a more orderly fashion.  Now obviously the way I have it above does not work, else I would not ask it, but thats the general way I picture it working, any ideas?
Link to comment
https://forums.phpfreaks.com/topic/29435-html-and-php-tables/
Share on other sites

ok, so I can understand...

You want to do a single query with multiple results, and display the results based on the value???

if you know the possible values, you can do it in a loop, but if the values are different for each return, you can't loop them...

you can, however, do a series of queries in a loop...

I would need more info to help you
Link to comment
https://forums.phpfreaks.com/topic/29435-html-and-php-tables/#findComment-135092
Share on other sites

What it is might be a bit hard to explain, but here goes.

In my DB, I have a table and in the table one of the records holds an attribute called "Skills"  In skills, there is 2,4, or 6 letters corresponding to values previously submitted.  I retrieve those values without issue, but using those values, I want the radio buttons they correspond to to be checked.  For example, if one value was EM, than the check box who's value is value = "EM" becomes checked.  Each table, where the radio buttons are stored, has 16 radio buttons, of which, 1,2 or 3 will be selected, again depending on the values stored in the DB.
Link to comment
https://forums.phpfreaks.com/topic/29435-html-and-php-tables/#findComment-135099
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.