I have an PHP Switch case. How do I swt the value of “n” using the onclick of a button?
switch (n)
{
case 1:
$result = mysql_query("select * from tblRestaurants order by RestName ASC");
break;
case 2:
$result = mysql_query("select * from tblCuisines order by RestName ASC");
break;
case 3:
$result = mysql_query("select * from tblLocations order by RestName ASC");
break;
case 4:
$result = mysql_query("select * from tblLocations order by RestName ASC");
break;
case 5:
$result = mysql_query("select * from tblLocations order by RestName ASC");
break;
}
onclick = (switch)n=1
Just guessing
The only way you can set a PHP variable after the page has loaded with a request for a JSON data return… All PHP code is executed before all of the HTML so if you submit a button you can call a java-script function but you can only use java-script functions from that onClick call.
If you insist on not having your page refresh you would have to use a lot of AJAX and get a JSON data return document. But if you are fine with a page redirect you could just have a form submit to the same page and then at the top of the page check if you posted and if so then execute your queries.
Top of Page:
In your form: