Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating variable names and reasing values

Status
Not open for further replies.

daybase

Technical User
Joined
Dec 13, 2002
Messages
115
Location
GB
NEW TO ALL THIS SO PLEASE BE PATIENT!
I have a script which creates an input form based on a table of area names to display area name and check box (this replaces an existing html form to give flexibility over use of areas which can be added or removed without re-writing form).

$area=$row["area"];
$findarea=$row["findarea"];
echo '<tr>';
echo'<TD vAlign=top height=20><p align=left><font size=&quot;2&quot; face=&quot;Times New Roman&quot;>';
echo'<INPUT type=checkbox value=ON name=&quot;';
echo strtoupper($findarea);
echo'&quot;>';
echo $area;
echo'</td>';


Form passes variables to another php script eg: $manchester (value passed ON).

The second script creates a query based on the values of the various variables

if($manchester==&quot;ON&quot;){
$findarea.=&quot; or harea='manchester'&quot;;
}
if($stockport==&quot;ON&quot;){
$findarea.=&quot; or harea='Stockport'&quot;;
}

I currently update this script when I know new areas have been added to the table but now I want to use the same table to generate this script based on the selected records. I was planning to use text routines to declare a variable called $scharea by adding a &quot;$&quot;to the area name so record &quot;$&quot; plus value Manchester gives &quot;$manchester&quot; but can't see how to use that created variable to do the above. Can anybody understand what I mean? If so please help.

Still very new to this so please keep it simple and give me an example which I can play with please %-)
 
Or you could name each checkbox &quot;places[]&quot;. eg:
Code:
echo '<tr>';
echo '<TD vAlign=top height=20><p align=left><font size=&quot;2&quot; face=&quot;Times New Roman&quot;>';
echo'<INPUT type=checkbox value=&quot;$area&quot; name=&quot;places[]&quot;';
echo $area;
echo'</td>';

Then in php you will have an array called $places[] with all the names of the places that have been checked. All you have to do is run a php script like:
Code:
<?php
for($i=0; $i<count($places); $i++)
{
	$findarea .= &quot; or harea='$places[$i]'&quot;;
}
echo &quot;<br>$findarea\n&quot;;
?>

Using this method you can expand the number of checkboxes as much as you want and the php will always cope with it.
 
Lots there to work on - thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top