hi guys, I was wondering if you could help me. I'm trying to create a report on my website through mysql and php. So I'm at the part where I have to pull in the parameters they want for the select statement. I'm using a dropdown box for this and trying to pass them into the next page. However, I'm naming each parameter individually by the table and field name as:

<?php
 echo "<select id='txtParam_" . $table['table'] . "." . $row['Field'] . "'>
<option>=</option>
<option>Like</option>
</select>";
?>

So when the form sends them to the next page it can pull each variable, eg = or Like, individually. The only problem is getting the correct table and field. I'm a bit of a rookie at all of this, so I'm not sure if I have to call the right field and table again or if the names will automatically pass. Just seems that everything I try is giving a blank array. I hope I've explained it right, I'm that good at it. All suggestions or opinions are much appreciated.

Elle x

peter_budo commented: Nice to see new member using code tags from beginning. Well done! +16

I think you should use the 'name' attribute instead of the id attribute to name your controls. This is used in the POST or GET to the next page. Do not use the txtParam_ prefix on it, because your sql cannot handle it.

echo "<select name='" . $table['table'] . "." . $row['Field'] . "'><option>=</option><option>Like</option></select>";

If you need a more elaborate example, let me know here. I have no access to php at work anymore. Maybe you can show your handling code (if you have it).

But I need a unique name for each parameter as the fields themselves would be called $table.$field no?

Maybe I'm calling them in the next file wrong, I'm trying to use

$arrField = explode(",",$_POST['field']);
	$arrTable = explode(",",$_POST['table']);
	$Param = $_POST[$arrTable.$arrField];
	
	foreach ($arrField as $field){
		foreach ($arrTable as $table){
			echo $Param;
		}
	}

I think I'm mixing up the arrays. There's an array of tables and fields so with one table and one field chosen, a parameter is created. The value of that comes from the <select>. I hope this makes sense, I'm very confused.

I'm just looking now, I don't think table and field pass as variables do they? If they are $table and $field in the first html page, passing to the second would they be eg table1 and table2 constants or will they hold onto their variable name?

Depends. They're not passed automatically. You can pass them as a hidden input field, or put them in a session.

Ok, here's what's happening now.

From two previous files, I have the tables and fields displayed on the html page in the variables which is working correctly.

Then I have the <select> for the parameters as this:

echo "<select name='" . $table['table'] . "." . $row['Field'] . "'>
<option>Like</option>
.
.
.
</select>
<td><input type='hidden' name='table'> " . $table['table'] . "</input>
<input type='hidden' name='field'> " . $row['Field'] . "</input></td>"

Finally the form is sent to the file with this:

$arrField = explode(",",$_POST['Field']);
	$arrTable = explode(",",$_POST['table']);
	foreach ($arrField as $field){
		foreach ($arrTable as $table){
	   $Param = $_POST["$table.$field"];
	   echo $Param;
	   }
	  }

a hidden input field is defined as

echo "<input type='hidden' name='Field' value='" . $row['Field'] . "' />";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.