cleibesouza Posted July 8, 2008 Share Posted July 8, 2008 Hi all. I have a form with a series of checkboxes which when checked and submitted runs a query based on record IDs. Because I don't know how many are going to get checked and submitted I run a loop: for($i = 0; $i < $totalSubmitted; $i++){ if(strlen($_POST[check . $i])){ //processing goes here }//end if }//end for This is all working fine. But to fetch the data I tried creating arrays: The entire code is below: for($i = 0; $i < $totalSubmitted; $i++){ if(strlen($_POST[check . $i])){ $and = " AND sesion_pk = " . $_POST[check . $i]; $results[$i] = mssql_query($someQuery); $row[$i] = mssql_fetch_array($results[$i]); echo $someQuery . $and . "<br>"; // this is just for debugging purposes echo $row[$i]['session_name'] . "<br>"; }else{ $totalItems = 0; }//end if/else }//end for The problem is that when I echo $row[$i]['session_name'] I only get the first ID passed. Any idea of what I'm missing? Thanks. Link to comment https://forums.phpfreaks.com/topic/113767-solved-problems-with-query-results/ Share on other sites More sharing options...
Barand Posted July 8, 2008 Share Posted July 8, 2008 Give your checkboxes all the same name, ending with "[]" so they are posted as an array while ($row = mysql_fetch_assoc($result)) { echo "<input type='checkbox' name='id[]' value='{$row['id']}' /> } Only checked ones are posted so to retrieve those selected $idlist = join(',' , $_POST['id']); $sql = "SELECT x,y,z FROM mytable WHERE id IN ($idlist)"; Link to comment https://forums.phpfreaks.com/topic/113767-solved-problems-with-query-results/#findComment-584654 Share on other sites More sharing options...
cleibesouza Posted July 8, 2008 Author Share Posted July 8, 2008 Thanks a lot. Worked well!! Link to comment https://forums.phpfreaks.com/topic/113767-solved-problems-with-query-results/#findComment-584673 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.