Jump to content

Help with a variable number of and names of $_REQUEST variables


cooldude832

Recommended Posts

i don't have php but here is the form

$i=0;
echo "<table><form method='post' action='update_ads.php'>\n<input type='hidden' name='submitted' value='yes'/>\n";
while( $row= mysql_fetch_array($results))		{
		echo "<tr><td>".$row['Adtitle']." Created on:".$row['CDate']." </td>\n";
		echo "<td><select name=\"".$row['ID']."\">\n";
		if($row['Priceshow'] == "1")
		{
			echo "<option value=\"1\" selected=\"selected\">Show Price</option>\n";
		}
		else
		{
			echo "<option value=\"1\">Show Price</option>\n";
		}
		if($row['Priceshow'] == "-1")
		{
			echo "<option value=\"-1\" selected=\"selected\">Make an Offer</option>\n";
		}
		else
		{
			echo "<option value=\"-1\">Make an Offer</option>\n";
		}
		if($row['Priceshow'] == "-2")
		{
			echo "<option value=\"-2\" selected=\"selected\">Sold</option>\n";
		}
		else
		{
			echo "<option value=\"-2\">Sold!</option>\n";
		}
		echo "<option value=\"-3\">Delete Ad</option>\n";
		echo "</select></td></tr>\n";
		}

	echo "<tr><td colspan='2'><input type='submit' value='Update Ads'\></form></td></tr></table>\n";
}

i tried something and i think i got it:

$numberofads = count($_REQUEST);
$i = 0;
foreach($_REQUEST as $value)
{
$request[$i] = current($_REQUEST);
$key[$i] = key($_REQUEST);
echo $i." ".$key[$i]." ".$request[$i]."<br/>";
next($_REQUEST);
}

my method works for me this is my complete code:


$numberofads = count($_REQUEST)-1;
$i = 0;
foreach($_REQUEST as $value)
{
$request[$i] = current($_REQUEST);
$key[$i] = key($_REQUEST);
next($_REQUEST);
$i++;
}
$j = 1;
$table = "horse_ads";
while ($j < $numberofads)
{
	$result = mysql_query("UPDATE $table SET Showprice='$request[$j]'	WHERE ID = '$key[$j]'") or die(mysql_error());
	$j++;
}

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.