Problem with table in php
Problem with table in php
I'm trying to create a table in php that would show the data on the mysql database based on the check box that is checked by the user. As you can see in this screen shot, it will have problems when you did not check on a checkbox before the one that will be the last: http://www.mypicx.com/04282010/1/
Here is my code:
if($_POST['general'] == 'ADDRESS'){ $result2 = mysql_query("SELECT * FROM student WHERE ADDRESS='$saddress'"); ?> IDNO YEAR SECTION LASTNAME" ?> FIRSTNAME" ?> MIDNAME" ?> ADDRESS" ?> GENDER" ?> RELIGION" ?> BIRTHDAY" ?> CONTACT" ?>
What can you recommend so that the output will not look like this when you one of the checkbox before a checkbox is not clicked: http://www.mypicx.com/04282010/2/
Answer by Vinze for Problem with table in php
instead of
you should do something like
".$row['GENDER']."" ?>
So that the You only print table header elements ( Instead of all that, loop over the fields to be printed out. No need to test each and every field. Example form: Form handler: The You could even make it self-configuring by constructing the Yeah, do it the same way as you've done the th tags, with the if statement around the td tags, rather than inside them. Way you've done it now will always show 9 columns, no matter what check boxes are selected. Ok first thing's first, let's clean your code up, because it's so difficult to read in it's current format: Your best bet would be to try putting this code in and telling us if this improves things? EDIT Ah, as the others have said your Your 're printing the cells in the iteration, but only it's content depends on the condition. tags only appears if the "if" statement is true. Answer by outis for Problem with table in php
) if the corresponding $is*Field*
variable is set, but you print all table cells, only testing whether or not to print the cell contents.
$label) { ?> $label) { ?> foreach ($results as $row) {
needs to be rewritten as a while
loop if you stick with the outdated mysql driver, but works with PDOStatement. Switching to PDO also makes it easier to injection vulnerabilities, as prepared statement parameters are invulnerable to them. You can also rewrite that SELECT *
to only fetch the requested columns, reducing DB load.$validFields = array('last' => 'Last Name', 'first' => 'First Name', 'stAddr' => 'Address', ...); $fields = array_intersect($validFields, $_POST['show']);
$validFields
array by inspecting the DB table(s), though this would incur an extra table query.Answer by thebluefox for Problem with table in php
Answer by Ben Everard for Problem with table in php
IDNO YEAR SECTION LASTNAME FIRSTNAME MIDNAME ADDRESS GENDER RELIGION BIRTHDAY CONTACT '.$row['LASTNAME'].''); } ?> '.$row['FIRSTNAME'].''); } ?> '.$row['MI'].''); } ?> '.$row['ADDRESS'].''); } ?> '.$row['GENDER'].''); } ?> '.$row['RELIGION'].''); }?> '.$row['BIRTHDAY'].''); }?> '.$row['S_CONTACTNUM'].''); }?> tags are sitting outside of your condition, still, the above code is much easier to read and will help future debugging :-) ' ?> Answer by Mikulas Dite for Problem with table in php
' . $row['S_CONTACTNUM'] . '
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment