Jump to content

checkbox in a table


niche

Recommended Posts

I have three records in a MYSQL database. I have successfully echoed these records in a table. Now I'd like to add a checkbox to each row. My script won't work. How do I script a checkbox into a table with PHP?Here's my script:

<?phpinclude_once "connect_to_mysql.php";$result = mysql_query("SELECT * FROM clioff") or die(mysql_error()); echo "<table border='4' align='right'>";echo "<tr> <th>Company</th> <th>Item</th> <th>Price</th> </tr>";// keeps getting the next row until there are no more to getwhile($row = mysql_fetch_array( $result )) {	// Print out the contents of each row into a tableecho "<tr><td>"; echo "<input type="checkbox" name="abc" />"; 		echo "<tr><td>"; 	echo $row['client'];	echo "</td><td>"; 	echo $row['item'];	echo "</td><td>"; 	echo $row['price'];	echo "</td></tr>"; } echo "</table>";?>

Link to comment
Share on other sites

it looks like you have things incorrectly structured. I think you are looking for this kind of output, right?

| checkbox | client | item | price |

Well keep the row starting before the echo of the checkbox, and then don't start a new one before client. Essentially you just need to add an extra set of <td></td>'s for the checkbox. That is unless i have things wrong.

Link to comment
Share on other sites

you also require extra <th></th> to allow for this extra cell.

<?phpinclude_once "connect_to_mysql.php";$result = mysql_query("SELECT * FROM clioff") or die(mysql_error()); echo "<table border='4' align='right'>";echo "<tr><th>whateever title</th><th>Company</th> <th>Item</th> <th>Price</th> </tr>";// keeps getting the next row until there are no more to getwhile($row = mysql_fetch_array( $result )) {	// Print out the contents of each row into a tableecho "<tr><td>"; echo "<input type="checkbox" name="abc" />"; 		echo "</td><td>";	echo $row['client'];	echo "</td><td>"; 	echo $row['item'];	echo "</td><td>"; 	echo $row['price'];	echo "</td></tr>"; } echo "</table>";?>

Link to comment
Share on other sites

I reran the script with dsonesuk's changes and got a blank screen.When I commented out:

//echo "<input type="checkbox" name="abc" />"; 

the table appeared, but was incorrect (what I expected).If the HTML is the problem, how should it be scripted (know I'll have a problem using the same name for each row, but that will a later topic)?Thanks

Link to comment
Share on other sites

This produces a blank screen:If I comment out the checkbox line it, produces a table, but obviously not the one I want. Therefore, I think its the checkbox line that causing problems. Right?

<?phpinclude_once "connect_to_mysql.php";$result = mysql_query("SELECT * FROM clioff") or die(mysql_error()); echo "<table border='4' align='right'>";echo "<tr>  <th>Select</th><th>Company</th> <th>Item</th> <th>Price</th> </tr>";// keeps getting the next row until there are no more to getwhile($row = mysql_fetch_array( $result )) {	// Print out the contents of each row into a tableecho "<tr><td>"; echo "<input type="checkbox" name="abc" />"; 		echo "<tr><td>"; 	echo $row['client'];	echo "</td><td>"; 	echo $row['item'];	echo "</td><td>"; 	echo $row['price'];	echo "</td></tr>"; } echo "</table>";?>

Link to comment
Share on other sites

Thanks to thescientist and for their help.Niche

Link to comment
Share on other sites

Thanks to thescientist and dsonesuk for their help.Niche

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...