Forum Moderators: coopster
$qcount=1; $count2=1;
#### Now The Questions
while($qcount<16)
{
echo "<tr><td class='red1b'>",$qcount,". </td><td class='red1b'>", $q[$qcount][0], "</td></tr>";
while ($count2<5)
{
if($q[$qcount][$count2]<>" ")
{
$abc=$q[$qcount][$count2];
echo "<tr><td align='center'><input type='radio' name=a[$qcount] value='$count2'></td><td class='blu1'>",$q[$qcount][$count2],"</td></tr>";
}
$count2++;
}
echo "<tr><td colspan='2'> </td></tr>";
$qcount++;
if($count2==5) { $count2=1; }
}
#### Now do the submit button
echo "<tr><td align='center' colspan='2'><input class='red2b' type='submit' name='submit' value='Submit'></table></table></form>";
echo "<br><br><br><p align='center' class='blu0'>04/22/2005</p>";
echo "<p align='center'><a class='red1b' href='../../index.htm' target='_top'><<<
Back to Main Website >>></a></p><br><br></body>";
$a01=$_POST['a[1]']; echo ">",$a01,"<";
die();
#Place answers into array
$q[1][1]=$a[1];
$q[2][1]=$a[2];
$q[3][1]=$a[3];
$q[4][1]=$a[4]; echo "<form name='traffic_test' method='post' action='traffictest2.php'>"; <?php
//Your current code
echo "<form name='traffic_test' method='post' action='traffictest2.php'>";
//Better Code
echo "<form name=\"traffic_test\" method=\"post\" action=\"traffictest2.php\">";
?> echo "<p class=\"greeting\">Hello World</p>"; BAD:
<a class='red1b' href='../../index.htm' target='_top'><<< Back to Main Website >>></a>
GOOD:
<a class="red1b" href="../../index.htm" target="_top"><<< Back to Main Website >>></a> <?php
//### Start Form (reference) ###
echo "<form name=\"traffic_test\" method=\"post\" action=\"traffictest2.php\">";
//### Incrementers ###
$qcount=1;
$count2=1;
//### Now The Questions ###
while($qcount<16)
{
echo "<tr><td class=\"red1b\">{$qcount} </td><td class=\"red1b\">{$q[$qcount][0]}</td></tr>";
while ($count2<5)
{
if($q[$qcount][$count2]!=" ")
{
$abc=$q[$qcount][$count2];
echo "<tr><td align=\"center\"><input type=\"radio\" name=\"a[{$qcount}]\" value=\"{$count2}\"></td><td class=\"blu1\">{$q[$qcount][$count2]}</td></tr>";
}
$count2++;
}
echo "<tr><td colspan=\"2\"> </td></tr>";
$qcount++;
if($count2==5) { $count2=1; }
}
//### Now do the submit button ###
echo "<tr><td align=\"center\" colspan=\"2\"><input class=\"red2b\" type=\"submit' name=\"submit\" value=\"Submit\"></table></table></form>";
echo "<br><br><br><p align=\"center\" class=\"blu0\">04/22/2005</p>";
echo "<p align=\"center\"><a class=\"red1b\" href=\"../../index.htm\" target=\"_top\"><<< Back to Main Website >>></a></p><br><br></body>";
?> <?php
echo "<p>Testing Form Values!</p>";
echo "<pre>";
print_r($_POST);
echo "</pre>";
echo "<p><i>Terminating Script!</i></p>";
exit();
?> # This processes the array from the form
foreach (array_keys($_POST) as $key) {
$$key = $_POST[$key]; }
# This sets answers into proper array
foreach($a as $key => $val) {$q[$key][1]=$val; }
Lastly, as for me using a comma instead of a period when building strings, if you examine the code a little more closely you'll see that I was building an echo statement, not a string. The comma is appropriate for building the echo statement and I agree that anything less than a period for building a string will generate errors. I also note that my use of echo instead of print is somewhat unusual but it is the result of an article I read that proved that in most cases, the use of echo instead of print consumes less memory and results in faster loading pages. I can neither find the article nor prove it, but that is how I wound up coding that way.
The comma is appropriate for building the echo statement and I agree that anything less than a period for building a string will generate errors.
//My personal preference:
echo "<p>Hello {$name}! Welcome to my site!</p>";
//What a lot of people do:
echo "<p>Hello ".$name."! Welcome to my site!"; I also note that my use of echo instead of print
People say don't use <FONT> for formatting and don't use <TABLE> for layout; but some people still do it, and if you do, it certainly won't break anything; but it isn't good practice. ;)
echo ">",$a01,"<"; to your echo ">{$a01}<";
...but I tend to write the entire page in php and not jump in and out of html. Perhaps that is why it doesn't become an issue.
<?php
echo "<div class=\"content\">";
echo "<h1>Welcome ".$name."!</h1>";
echo "<p>Websites are cool. OK?</p>";
echo "</div>";
?> <?php
echo <<<END
<div class="content">
<h1>Welcome $name</h1>
<p>Websites are cool. OK?</p>
</div>
END;
?>