nimzie Posted December 19, 2007 Share Posted December 19, 2007 My web app already takes all the data and it's stored in a DB where I will process things. What I want to do is load the data in to a <table> somehow and have checkbox form elements at the end of each row. Then on the screen, there will be a button to click for processing. Processing will go through all the checked rows and do something based on the data behind it : like in this case, it'll build a file and mark all rows as "processed" in the DB. I'm not quite understanding the best way to generate this table, and then going through it and knowing what is what as I process - and the whole relation between what I loaded and how to know which records to process. Can anyone assist? Thanks for any help, Adam Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/ Share on other sites More sharing options...
bobahad Posted December 19, 2007 Share Posted December 19, 2007 This is a basic example I took from my script: <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td bgcolor="#FFFFFF"><img src="images/thumbs/<? echo $rows['Filename']; ?>"></td> <td bgcolor="#FFFFFF"><? echo $rows['Make']; ?></td> <td bgcolor="#FFFFFF"><a href="viewspecificcar.php?id=<? echo $rows['id']; ?>"><? echo $rows['Model']; ?></a></td> <td bgcolor="#FFFFFF"><? echo $rows['Year']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['Color']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['VIN']; ?></td> <td bgcolor="#FFFFFF"><a href="editcar?id=<? echo $rows['id']; ?>">Edit<a/> <?php } ?> so it creates a table depending on the number of rows in the db table or the result of the query and goes from there, as you see in this table, it will add a checkbox and a link. Modify as you see necessary. Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-418562 Share on other sites More sharing options...
roopurt18 Posted December 19, 2007 Share Posted December 19, 2007 Well your first task is generating the table, for that you will need to: Grab all the records Echo the table header for each record echo a table row [*]echo the table footer Do you know how to do any of that? If not, you may want to look at some general PHP / MySQL tutorials first. Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-418563 Share on other sites More sharing options...
roopurt18 Posted December 19, 2007 Share Posted December 19, 2007 @bobahad Perhaps you know something that I don't, but isn't it incorrect to assign the same ID to all of your checkboxes? If you're not using JS, you can drop the ID attribute anyways. Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-418572 Share on other sites More sharing options...
nimzie Posted December 19, 2007 Author Share Posted December 19, 2007 yup, I guess building the HTML out of the Data isn't the problem - it's more doing it in a way so there is some sort of logical loop I can do to see what was checked and which records I need to process. Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-418575 Share on other sites More sharing options...
roopurt18 Posted December 19, 2007 Share Posted December 19, 2007 Do you already know how to perform form processing? Or is that totally new to you? Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-418579 Share on other sites More sharing options...
bobahad Posted December 19, 2007 Share Posted December 19, 2007 It will assign every checkbox a different id while the loop goes around, That's what I use to delete the "checked" values from the database. So I check all the checkboxes I want, click "delete" and it will delete the ones I checked. Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-418585 Share on other sites More sharing options...
roopurt18 Posted December 19, 2007 Share Posted December 19, 2007 @bobahad I was referring to this: id="checkbox[]" As far as I can tell, assigning an element's ID in that manner is useless. Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-418601 Share on other sites More sharing options...
bobahad Posted December 19, 2007 Share Posted December 19, 2007 Lol possibly, it's working so I am not messing with it now investigate my other issue please heh http://www.phpfreaks.com/forums/index.php/topic,172744.15.html Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-418607 Share on other sites More sharing options...
nimzie Posted January 2, 2008 Author Share Posted January 2, 2008 Thank you for your tips and tricks.. Here's what I've come up with .... $statement is my query result and it's currently building the table just fine... So - in order to be able to check on submit which rows were checked and which to process, I take it I need to make individual IDs for each checkbox and check the IDs on submit? Anyone have any tips on this please? Thanks, Adam <form action="processfile.php" method="POST"> <?php if ( isset ( $statement )) { echo "<table>"; echo "<tr>" . "<td>Process Order</td>" . "<td>OrderID</td>" . "<td>ShipBusinessName</td>" . "</tr>"; while($row = mysql_fetch_array($statement)) { echo "<tr>" . "<td> <input type=\"checkbox\" name=\"Process Record\" value=\"Process\"> </td>" . "<td>" . $row['OrderID'] . "</td>" . "<td>" . $row['ShipFirstName'] . ' ' . $row['ShipLastName'] . "</td>" . "</tr>"; } echo "</table>"; } ?> </form> Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-428357 Share on other sites More sharing options...
nimzie Posted January 2, 2008 Author Share Posted January 2, 2008 I've changed things a little ... <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Is how I am going to trigger things to re-process in the top part of the file itself. So - I don't know how to loop through all checkbox_x values in the $POST var dynamically. How do I do this in PHP? I am going to a confirmation page after this, but I want to do all the processing in the top of the pHP page itself - that's why I changed the form tag. Any advice please? Thanks, Adam Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-428558 Share on other sites More sharing options...
nimzie Posted January 2, 2008 Author Share Posted January 2, 2008 In working, I've tried this : $sql = 'select * from origin where BillCountry = \'United States\' and Processed = 0'; $statement = mysql_query($sql); if (isset($_POST['submit'])) { $i = 0; while($row = mysql_fetch_array($statement)) { //<<<< To me, this should be a for loop based on the HTML on the screen or something .. running the sql again to build the HTML seems silly... $i = $i + 1; echo "value for each row " . $row['ShipFirstName'] . "<br />"; if ( $_POST['checkbox_' . $i] = 'on' ) //****<<----this really doesn't look right - but I can't figure another way to access the checkboxes? { echo "checkbox " . $i . " is set"; } } //header("location: contest.php"); } else { echo "<br />submit is not set"; } I don't like it. It assumes too much and seems sloppy to me. Nothing is working anyhow. I am trying to address the checkboxes I create in the HTML form as: <td> <input type=\"checkbox\" name=\"checkbox_" . $i . "\" > </td>" Which are being created nicely... Quote Link to comment https://forums.phpfreaks.com/topic/82344-table-from-database-for-processing/#findComment-428569 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.