Hey,
I'm making an edit/add option for different site sections on my site.
I have a mysql database with the following fields
id
name
reqfields
optfields
showonfp
showboxart
totallinks
polltype
disable
When adding something, you can choose a load op required fields and optional fields for the new section.
When all this is done, I add them all to one variable and dump them in the reqfields or optfields column.
They are placed in there like this:
type||Type,authid||Author,date||Date,title||Title,intro||Introduction,content||Review Article,gameplayscore||Gameplay Score,soundscore||Sound Score,Graphicsscore||Graphics score,lifespanscore||Lifespan Score,url1||Related Link 1,url2||Related Link 2,url3||Related Link 3
the fields are divided by a , and a ||.
The , checks how many fields are required or optional. And the || divides the input name from the description that goes with it.
Adding all goes fine, but editing is the problem. I want the form to check the fields that are required in the database, but I'm having quite a few problems with it.
Here's the code I use to explode and get all the data:
<?
$reqfieldsexp=explode(",",$row[reqfields]);
$count=count($reqfieldsexp);
for($i=0;$i<=$count;$i++) {
$exp=explode("||",$reqfieldsexp[$i]);
$reqname="$exp[0]";
$reqdesc="$exp[0]_desc";
$req_[$reqname]="1";
$req_[$reqdesc]="$exp[1]";
}
?>
First I explode it on the comma, and then I count it, so I can loop the values. In the for I explode it again, but now on the || to get the description for that field.
It all works great, except for the last two lines.
$reqname and $reqdesc have a good value, when I call them they are echo'ed something like:
type
type_desc
This is ok, since I need this for the later one.
But $req_[$reqname] doesn't return like $req_type.
So when I want to check the checkboxes, I use this code:
<input type=checkbox name=req_type value=1 <?if($req_type) { echo"checked"; } ?>
But it just doesn't work.
How can I fix this?
Thanks,
Menno