Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I read the values from mssql server 2005 and display this in a html table.

This is main.php
print
    "<tr><th>Date</th><th>PABX</th><th>Error</th><th>Warning</th><th>Message</th><th>Target</th><th>Action</th><th>Processing</th><th>Solved</th></tr>";

while ($row=mssql_fetch_array($result))
    {
    print "<form action='update.php' method='post'><input type='hidden' name='update'  ><tr>";
    $i=0;                                                                                    
     print  "<input type='hidden' name='processing' value=$row[7]>";
     print  "<input type='hidden' name='solved' value=$row[8]>";
     print  "<input type='hidden' name='ID' value=$row[9]>";
     
    while ($i < mssql_num_fields($result))
        {
        if (!is_null($row[$i]))
            {
            //  print "<tr><td>.$row[$i].</td><td>Row:1 Cell:2</td><td>Row:1 Cell:3</td><td>Row:1 Cell:4</td><td>Row:1 Cell:5</td></tr>";    
            if (($row[2]) == 1) //red
                {
                print "<td bgcolor='FF0000'><font color='white'>$row[$i]</font></td>";
                }

            if (($row[3]) == 1) //orange
                {
                print "<td bgcolor='FFa500'><font color='white'>$row[$i]</font></td>";
                }
             //processing
            if (($row[7]) == 1)
                {
                $row[7]="1 <input type='checkbox' checked />";
                }
            else
                {
                $row[7]="0 <input type='checkbox'  />";
                }
             //solved
            if (($row[8]) == 1)
                {
                $row[8]="1 <input type='checkbox' checked name='checkbox_solved_$row[9]' /><input type='submit' name='update' value='Update row' /></form>";
                }
            else
                {
                $row[8]="0 <input type='checkbox' '' name='checkbox_solved_$row[9]'  /><input type='submit' name='update' value='Update row' /></form>";
                }
            }

        $i++;
        }

    print "</tr>";
    }


This is update.php
<?php
  session_start();

include('_connect.php');
$processing= $_POST['processing'];
$solved= $_POST['solved'];

$query ="UPDATE [DailyChecks].[dbo].[ghi]  SET [processing]=$processing, [solved]=$solved   WHERE id = 561";
$result=mssql_query($query);
?>

Now, if the user changes a checkbox I want to update my sqlserver. But he does not uses the current values on the screen but the values that generates the table.

How do I solve this?


Alex
Posted
Comments
karthik Udhayakumar 19-May-14 19:44pm    
Hello Alex,

How can a user change the checkbox..you can just check in or check out a checkbox..
What you wanna achieve dear ..where you are stuck up?Any error?Use improve question widget option to get better help from the coding community:)

1 solution

After is short night is solved the problem:

main.php:
PHP
//solved
            if (($row[8]) == 1)
                {
                $row[8]                    ="<form action="update.php" method="post"><input type="checkbox" name="checkbox_solved_$row[9]"  önclick="this.form.submit();" checked="" />
                                               <input type="hidden" name="solved" value="0"><input type="text" name="ID" value="$row[9]"></input></input></form>";
                                    
                }
            else
                {
               $row[8]                      ="<form action="update.php" method="post"><input type="checkbox" name="checkbox_solved_$row[9]"  önclick="this.form.submit();" />
                                                 <input type="hidden" name="solved" value="1"><input type="text" name="ID" value="$row[9]"></input></input></form>";
                }



and update.php uses the $_POST to create the query:
PHP
//UPDATE [DailyChecks].[dbo].[ghi] set [connection_errors] = CASE WHEN [connection_errors] = 1 THEN 0 ELSE 1 END  WHERE id = 561

session_start();
include ('_connect.php');
 $my_time = date('Y-m-d h:i:s',time());
   $ID=$_POST['ID'];
    if (isset($_POST['solved']))
        {
        $solved=$_POST['solved'];

        if ($solved == '0' or $solved == '1')
            {
            $query ="UPDATE [DailyChecks].[dbo].[ghi]  SET [solved]=$solved, [solveddate]='$my_time' WHERE id = $ID ";
            $result=mssql_query($query);
            if ($result = true)
            print "Solved ok! $ID $query $result";
            }
        }

    if (isset($_POST['processing']))
        {
        $processing=$_POST['processing'];

        if ($processing == '0' or $processing == '1')
            {
            $query ="UPDATE [DailyChecks].[dbo].[ghi]  SET [processing]=$processing , [processingdate]='$my_time' WHERE id = $ID ";
            $result=mssql_query($query);
            }
        }
    }  
?>


Problem:SOLVED!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900