Jump to content

Update to php 7 problem with checkbox form


JackW

Recommended Posts

I am updating a website to php7 from php5. The project was going well until I come to this page.  The page actually uses a form to transfer information to the next page with the checkboxs numbered as ($i+1). The code below in not the form but I "think" that if I can get that code to work I can make the form work. I need to place 1, 2, 3, etc in the result from the php7.  when I leave out (for ($i=0; $i < $match_results; $i++)) and (echo ($i+1);) the rest works fine but my form boxes are not numbered so will not transfer to the next page.

The link below is the page that works with php5 with the checkbox form on the right.

http://www.sheridancountyne.com/levy_page.php?year=2017&amp;value=56000


The below code works with php5

<html>
<body>
<?php


require ("$path/require/connect.php");
 $budget_year2=("2017");
  $tax_credit=("Tax Credit");
  $tax_credit_ag=("Tax Credit Ag");
  $show=("show");
  $base=("Base");
   $value2=("50000");
 echo '<table class="one" width="500" border="0" cellpadding="0" cellspacing="0" align="center">';

 $query= ("SELECT * FROM `outside_levy` WHERE `budget_year` = '".$budget_year2."' AND `department` != '".$blank."'  AND `levy_type` != '".$tax_credit."' AND `levy_type` != '".$tax_credit_ag."' ORDER BY `rank` ASC, `levy_type` ASC, `department` ASC LIMIT  0, 40");
$query_results=mysql_query($query);
$match_results=mysql_num_rows($query_results);

for ($i=0; $i < $match_results; $i++)
{
$row=mysql_fetch_array($query_results);
echo '<tr><td width="90%">';
echo  '<div class="levy2"><b>';
$tax=number_format(($row ['levy'] )*$value2, 2);

echo ($i+1);
echo ' &nbsp; ';
echo ($row ['department'] );
echo  '</b></div>';
echo '</td><td width="10%"><div class="rightblack">';
echo $tax;
echo '</div>';
echo '</td></tr>';
 }
echo '</table>';
mysql_close($db);
?>
</body>
</html>

I need to place the code for ($i=0; $i < $match_results; $i++) and echo ($i+1); in the new code for php7 below.

<html>
<body>
<?php

require ("$path/require/connectphp7.php");
 $budget_year2=("2017");
  $tax_credit=("Tax Credit");
  $tax_credit_ag=("Tax Credit Ag");
  $show=("show");
  $base=("Base");
   $value2=("50000");
 echo '<table class="one" width="500" border="0" cellpadding="0" cellspacing="0" align="center">';

$resource = $db->query("SELECT * FROM `outside_levy` WHERE `budget_year` = '".$budget_year2."' AND `department` != '".$blank."'  AND `levy_type` != '".$tax_credit."' AND `levy_type` != '".$tax_credit_ag."' ORDER BY `rank` ASC, `levy_type` ASC, `department` ASC LIMIT  0, 40");
while ($row = $resource->fetch_assoc() )
for ($i=0; $i < $match_results; $i++)       // this does not work here in php7 how do I write a code that will work with (Si+1) below
  {
echo '<tr><td width="90%">';
echo  '<div class="levy2"><b>';
$tax=number_format(($row ['levy'] )*$value2, 2);

echo ($i+1);    //this is the part that will not work in php7
echo ' &nbsp; ';
echo ($row ['department'] );
echo  '</b></div>';
echo '</td><td width="10%"><div class="rightblack">';
echo $tax;
echo '</div>';
echo '</td></tr>';
 }
echo '</table>';
  $db->close();
?>
</body>
</html>

Link to comment
Share on other sites

Drop the for() loop and just initialize a variable $i and increment it yourself, like this:

<?php

$i = 1; // Initialize $i outside the loop
while ($row = $resource->fetch_assoc()) {
  echo $i; // No "+1" here because we started $i as 1 already

  // All the rest of your code here
  //
  //
  //

  // Increment $i
  $i++;
}

 

Link to comment
Share on other sites

Thank you!! I have been the most of two days trying to figure that out. Now to incorporate it into the form on the actual page. Below is the code that worked.

$i = 1; // Initialize $i outside the loop
 echo '<table class="one" width="500" border="0" cellpadding="0" cellspacing="0" align="center">';
 
$resource = $db->query("SELECT * FROM `outside_levy` WHERE `budget_year` = '".$budget_year2."' AND `department` != '".$blank."'  AND `levy_type` != '".$tax_credit."' AND `levy_type` != '".$tax_credit_ag."' ORDER BY `rank` ASC, `levy_type` ASC, `department` ASC LIMIT  0, 40");
while ($row = $resource->fetch_assoc() )

  {  
echo '<tr><td width="90%">';
echo  '<div class="levy2">';
echo $i++;
echo '<b>';
$tax=number_format(($row ['levy'] )*$value2, 2);  
echo ' &nbsp; ';
echo ($row ['department'] );
echo  '</b></div>';
echo '</td><td width="10%"><div class="rightblack">';
echo $tax;  
echo '</div>';
echo '</td></tr>';
 }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...