DenchyKins Posted March 5, 2008 Share Posted March 5, 2008 Ok, so the idea here is that the code displays all of the gravestones in the table (which it does), and a checkbox is created for every item so that this checkbox can be clicked if a person can supply it. The problem i have is giving each checkbox a different name in the while, i tried $row['GravestoneID'] but it didn't like this, i need a way to check if each one has been checked individually to then change a boolean in a different table. Any pointers would be good, also if you think im going about this in completely the wrong way, please tell me, this is the first idea i had, thanks: <?php $connection = mysql_connect("****", "****", "****") or die('Could not connect: ' . mysql_error()); mysql_select_db("COMP10900_M3", $connection) or die('Could not select database'); $result = mysql_query("SELECT * FROM gravestone_table"); echo "<form>"; while($row = mysql_fetch_array($result)) { echo "<dl>"; echo "<dt>" .$row['GravestoneName'] . "</dt>"; echo "<dd>" .$row['GravestoneDescription'] . "</dd>"; echo "</dl>"; echo "<input type = 'checkbox'>" . "We can supply this"; echo "<hr>"; } echo "</form>"; ?> Quote Link to comment Share on other sites More sharing options...
shocker-z Posted March 5, 2008 Share Posted March 5, 2008 I would use echo "<input type = 'checkbox' name="checkbox[]" value="The value you want e.g. ID">" . "We can supply this"; That will create an array called $_POST['checkbox'] then use a foreach to loop through the data foreach ($_POST['checkbox'] as $ID) { rcho $ID; } Regards Liam Quote Link to comment Share on other sites More sharing options...
DenchyKins Posted March 5, 2008 Author Share Posted March 5, 2008 Oooh the array is a good idea, however my main problem is that for my value, i cannot set it to $row['GravestoneID'] as PHP doesn't like this, i have no idea how to make it have a unique value for each time the while happens, does that make sense? any ideas? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 5, 2008 Share Posted March 5, 2008 Oooh the array is a good idea, however my main problem is that for my value, i cannot set it to $row['GravestoneID'] as PHP doesn't like this, i have no idea how to make it have a unique value for each time the while happens, does that make sense? any ideas? What doesn't PHP 'like' about it? It should be an integer, and printed like so: ..... while($row = mysql_fetch_array($result)) { echo "<dl>"; echo "<dt>" .$row['GravestoneName'] . "</dt>"; echo "<dd>" .$row['GravestoneDescription'] . "</dd>"; echo "</dl>"; echo "<input type=\"checkbox\" name=\"checkbox[]\" value=\"".htmlspecialchars($row['GravestoneId'])."\"> We can supply this"; echo "<hr>"; } ..... Quote Link to comment Share on other sites More sharing options...
DenchyKins Posted March 5, 2008 Author Share Posted March 5, 2008 well my gravestone IDs are GS01, GS02, GS03 etc because of the need for this in another table, i assume you meant these need to be integers, and therefore i have a big problem :/. also, what would i need to place in *HERE* <?php foreach ($_POST['checkbox'] as *HERE*) { echo $ID; } ?> Quote Link to comment Share on other sites More sharing options...
DenchyKins Posted March 5, 2008 Author Share Posted March 5, 2008 Ahah! ive managed to get it to print out the correct IDs, thank you all very much, now onto the harder task of making these IDs change booleans lol. Quote Link to comment 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.