Remove this Banner Ad

Computers & Internet Simple Web dev question, PLEASE HELP!

  • Thread starter Thread starter power09
  • Start date Start date
  • Tagged users Tagged users None

🥰 Love BigFooty? Join now for free.

power09

Premiership Player
Joined
Dec 7, 2008
Posts
3,012
Reaction score
2,010
Location
Burra SA
AFL Club
Port Adelaide
Other Teams
Timberwolves
Hello

This is probably a dumb question because i cant find an answer anywhere, but when using PHP is HTML code affected by conditional statments?

say if i wanted to output a certain table ONLY if a variable equalled 1 or a different table if the variable equalled 2, could this be done?

if($colNum = 1 ){
echo <table>;
echo <tr>;
echo <td></td>;
echo </tr>;
}

if($colNum = 2){
echo <table>;
echo <tr>;
echo <td></td>;
echo <td></td>;
echo </tr>;
echo </table>;
}

i am trying something like this currently but the page loads all tables despite what the variable is equal to, im starting to think that HTML is not affected by conditional statments.
 
Another question

I am trying code a webpage that displays a table full of 24 pictures, when first loading the page the table has 5 columns.

Under the table i have put a drop down box that lets the user select how many columns the table should have, the user can choose between 5,8,10 or 20 columns.

i hope to make the page firstly load the default table of 5 cols and 5 rows, then when the user selects a different option the page reloads with a extra variable on the end of the URL.
like domain/pictable.php
(user selects 8 columns)
domain.pictable.php?choice=2

I have already got this to work, but the table wont change so the syntax or the way i have set out the <FORMS> must be wrong or i may of used the wrong method to reload the page...

examples of how others might attempt this simple php task would be appreciated.

this is how i have tried to get the user values not sure if its right

//code for a example drop down box
echo "<form method=\"get\" action=\"main2.php\">";

echo "Number of cols";
echo "<select name=\"$cols\">";
echo "<option value=\"1\">5columes</option>";
echo "<option value=\"2\">8columes</option>";
echo "<option value=\"3\">10columes</option>";
echo "<option value=\"4\">20columes</option>";
echo "<input type=\"submit\" value=\"re-display\">";
echo "</select>";
 
Hello

This is probably a dumb question because i cant find an answer anywhere, but when using PHP is HTML code affected by conditional statments?

say if i wanted to output a certain table ONLY if a variable equalled 1 or a different table if the variable equalled 2, could this be done?

if($colNum = 1 ){
echo <table>;
echo <tr>;
echo <td></td>;
echo </tr>;
}

if($colNum = 2){
echo <table>;
echo <tr>;
echo <td></td>;
echo <td></td>;
echo </tr>;
echo </table>;
}

i am trying something like this currently but the page loads all tables despite what the variable is equal to, im starting to think that HTML is not affected by conditional statments.

You need two =='s to do a compare in PHP, a single = will set the variable to what's after the equal, then evaluate setting it to true and drop into the logic.

Hence why it's dropping into each if statement.

For your second question- are you looking up the value of $_REQUEST['choice'] ?

technically, if you're passing back what they've chosen in the URL, there is no need for the form as the data is passed back in the URL. If you are aiming to pass it back through the form though, you'll want to name your select box "choice"

Also, just as an aside, did you know that you can replicate what you're doing as follows
echo "
Number of cols
<select name=\"$cols\">
<option value=\"1\">5columes</option>
<option value=\"2\">8columes</option>
<option value=\"3\">10columes</option>
<option value=\"4\">20columes</option>
<input type=\"submit\" value=\"re-display\">
</select>
";
 

Log in to remove this Banner Ad

Remove this Banner Ad

Remove this Banner Ad

🥰 Love BigFooty? Join now for free.

Back
Top Bottom