cooldude832 Posted June 5, 2007 Share Posted June 5, 2007 I have a form that will be submitted to a processing page, but the names of the inputs and the number of them are dynamic. Is there a way I can see all the passed $_REQUEST variables? is it an array I can work with and if so any tips? Link to comment https://forums.phpfreaks.com/topic/54213-help-with-a-variable-number-of-and-names-of-_request-variables/ Share on other sites More sharing options...
redarrow Posted June 5, 2007 Share Posted June 5, 2007 post your code ok. Link to comment https://forums.phpfreaks.com/topic/54213-help-with-a-variable-number-of-and-names-of-_request-variables/#findComment-268036 Share on other sites More sharing options...
cooldude832 Posted June 5, 2007 Author Share Posted June 5, 2007 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"; } Link to comment https://forums.phpfreaks.com/topic/54213-help-with-a-variable-number-of-and-names-of-_request-variables/#findComment-268040 Share on other sites More sharing options...
cooldude832 Posted June 5, 2007 Author Share Posted June 5, 2007 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); } Link to comment https://forums.phpfreaks.com/topic/54213-help-with-a-variable-number-of-and-names-of-_request-variables/#findComment-268047 Share on other sites More sharing options...
dough boy Posted June 5, 2007 Share Posted June 5, 2007 Easier way: foreach($_REQUEST as $key => $value) { echo 'Key: '.$key.' --> '.$value.'<br />'; } Link to comment https://forums.phpfreaks.com/topic/54213-help-with-a-variable-number-of-and-names-of-_request-variables/#findComment-268049 Share on other sites More sharing options...
cooldude832 Posted June 5, 2007 Author Share Posted June 5, 2007 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++; } Link to comment https://forums.phpfreaks.com/topic/54213-help-with-a-variable-number-of-and-names-of-_request-variables/#findComment-268052 Share on other sites More sharing options...
dough boy Posted June 5, 2007 Share Posted June 5, 2007 No problem. I like to use the least amount of code for the job, but as long as it gets the job done then I guess it is good. Link to comment https://forums.phpfreaks.com/topic/54213-help-with-a-variable-number-of-and-names-of-_request-variables/#findComment-268056 Share on other sites More sharing options...
cooldude832 Posted June 5, 2007 Author Share Posted June 5, 2007 well i need key and value so i guess i could consildate, but it works Link to comment https://forums.phpfreaks.com/topic/54213-help-with-a-variable-number-of-and-names-of-_request-variables/#findComment-268065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.