Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

php-Update table by selecting multiple primary keys and perform two different actions

New Here ,
Jan 16, 2014 Jan 16, 2014

Table beside which there is a check box and at the bottom of the table two buttons which has to perform dirrent action

action1- Change the status of selected rows.

action2- Send the selected rows to an email address.

I know to do these action for single record bt not for multiple. I have taken check box as array[] where it will store the primary keys of the selected records. I do not Know to use them in a professional manner.

Also note that I need to perform either of the two actions on single table. Please help me to do so.

<?php

$sql="SELECT * FROM transaction WHERE status='$selstatus'AND merchant_id='$selmerchantid' ORDER BY transaction_date AND transaction_date BETWEEN '$from' AND '$to' " ;

$result = mysql_query($sql) or die(mysql_error());  ;

 

$result = mysql_query($sql) or die(mysql_error());

// Print the column names as the headers of a table

echo '<table class="tableviewsales"><tr>';

for($i = 0; $i < mysql_num_fields($result); $i++) {

    $field_info = mysql_fetch_field($result, $i);

    echo "<th>{$field_info->name}</th>";

}

// Print the data

while($row = mysql_fetch_row($result)) {

    echo "<tr>";

    foreach($row as $_column) {

        echo "<td>{$_column}</td>";

 

    }

 

          $transactionid = $row[0];

 

          echo '<td> <input name="action[]" type="checkbox"  value="'. $transactionid.'">' ;

    echo "</tr>";

}

echo "</table>";

?>

</div>

<div id="action">

<table>

<tr>

<td> <input type="submit" value="Change Status" class="btn">

<input type="hidden" name="MM_update" value="changestatus" /> </td>

<td> <input type="submit" value="Send Report" class="btn">

<input type="hidden" name="MM_update" value="sendreport" /> </td>

</tr>

</table>

</div>

TOPICS
Server side applications
975
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 17, 2014 Jan 17, 2014

1) Wrap a form around the table

2) Use Two AJAX functions to get the values of the Form, use something like  .serialize() to submit the values to something like email.php and updaterow.php

    You can you use  e.preventdefault() (JQuery) to stop the form submitting.

3) To run it on multiple records use a For / For each loop running a UPDATE SQL statement on each.

5) Refresh the page to see the changes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 18, 2014 Jan 18, 2014
LATEST

thank you ,

Unfortunately i have not done any programming in AJAX and i m completely unaware of e.preventdefault().

<form action="updaterow.php"> will pass the value but how should i retreive them from

<input name="action[]" type="checkbox"  value="'. $transactionid.'">' ;

But i got a complex project to do and the above part is just a part of it.

Please i need some more brief answer

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines