Loop Through PHP Request Values – GET and POST

Loop through PHP Request Values

In order to Loop through PHP Request Values – GET and POST without knowing what they all might be, you can simply use the following code:

	
foreach ($_REQUEST as $key => $value)  
{  
$value = mysql_real_escape_string( $value );  
$value = addslashes($value);  
$value = strip_tags($value);  
if($value != ""){$requestnumber ++;}  
echo $key. ' - '.$value.'
'; }

This is useful when you have an undetermined/unknown set of POST or GET values that you would like to loop through.

Mobile Redirection With Full Site Option

It’s handy for people who don’t know that you have a mobile version of your site, or know what the URL is (is it sitename.com/mobile? Is it mobile.sitename.com? Is it something else?) On the other hand people often want to view the full version of a site on their mobile device. You can achieve this quite simply.

This code goes at the top of your header include file, or at least at the top of each page you wish to redirect. It must go before any page rendering happens, or you will get the dreaded “headers have already been sent” error.



In the header of the mobile site add some code to reset the override cookie to allow the mobile site to be seen. The assumption is that you view the mobile site until you tell the application otherwise:



All that is left to do is to give the manual option for switching between the two versions, in the form of links.

From mobile to full (includes variable to set view mobile to false):

<a href="http://yoursite.com/index.php?mv=0">View Full Website</a>

And the option to return to the mobile version, where the cookie is automatically changed just by visiting:

<a href="http://yoursite.com/mobile/">View Mobile Website</a>

Encode Mysql Results to JSON

The title says it all:


mysql_set_charset('utf8', $database_connection); // charset
$sqlStr = "SELECT * FROM yourtable;"; //provide the query
$result = mysql_query ($sqlStr, $database_connection) or die ($sqlStr); // get the results
$rows = array(); // create the array
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) { // populate array with results
$rows[] = $row;
}
}
echo json_encode($rows); // encode all in json
mysql_close($database_connection); // close the database connection