sigmahokies Posted June 5, 2015 Share Posted June 5, 2015 (edited) Hi everyone, I hope cyberRobot or Guru is reading this thread. I am trying to create a vertical table data in php from method of GET and POST. Is it possible? I succeed created the vertical table data from database (MySQL). I created the vertical table data on php that inside the form thathas method of GET or POST, that should allow any value in php go to another page by method of GET, but seem it doesn't work. Maybe I miss something in code? Help will be very appreciate. I am still learning, ready to get in interaction in php. Here my code: <!doctype html><html><head><title>Test array attendence</title></head><body><table><?php$columns = 2;if(isset($_GET['member'])) {$display = $_GET['member'];$num_row = $display;$rows = ceil($num_row / $columns); <-- It is causing an error in code, line 14.while ($row = $display) {$data[] = $row;}echo "<table border='1'>";for($i = 0; $i < $rows; $i++) {echo "<tr>";for($j = 0; $j < $columns; $j++) {if(isset($data[$i + ($j * $row)])) {echo "<td>".$data[$i + ($j * $row)]."</td>"; $count = $count+1;}}echo "</tr>";}}?></table><table><tr><td><?php echo $count." are attending this meeting tonight." ?></td></tr></table></body></html> I get an error message - Fatal error: Unsupported operand types in /srv/disk10/1141650/www/sigmahokies.biz.ht/testarray3.php on line 14 Edited June 5, 2015 by sigmahokies Quote Link to comment https://forums.phpfreaks.com/topic/296663-what-is-fatal-error-unsupported-operand-types-in-mean/ Share on other sites More sharing options...
fastsol Posted June 5, 2015 Share Posted June 5, 2015 Most likely it's cause you are dividing a string value ($num_rows) by a integer value ($columns). Assuming that $_GET['member'] is always supposed to be a full integer value, do this. $display = (int)$_GET['member']; Quote Link to comment https://forums.phpfreaks.com/topic/296663-what-is-fatal-error-unsupported-operand-types-in-mean/#findComment-1513269 Share on other sites More sharing options...
darkfreaks Posted June 8, 2015 Share Posted June 8, 2015 fixed it up for you, had several syntax errors causing issues also using count() instead of num_row() <?php $columns = 2; if(isset($_GET['member'])) { $display = ceil(count($_GET['member'])); $rows = ($display / $columns); while ($row = $display) { $data[] = $row; } echo "<table border='1'>"; for($i = 0; $i < $rows; $i++) { echo "<tr>"; for($j = 0; $j < $columns; $j++) { if(isset($data[$i + ($j * $row)])) { echo "<td>".$data[$i + ($j * $row)]."</td>"; $count = $count+1; } } echo "</tr>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/296663-what-is-fatal-error-unsupported-operand-types-in-mean/#findComment-1513479 Share on other sites More sharing options...
sigmahokies Posted June 9, 2015 Author Share Posted June 9, 2015 Darkfreaks, seem your fixed is still not work...I followed your fixed code exactly, just no showing error, just blank...I think I better show you all full code, two pages, because it is about GET and POST, so you can understand very clearly... Here my first page: <!doctype html><html><head><title>Test array with columns</title></head><body><form action="testarray3.php" method="GET"> <--this is set up for second page, see code after this code.<fieldset><?php$column = 2;$Garydb = mysqli_connect('xxxxxx','xxxxxx','xxxxxx') or die("Could not connect to database.");mysqli_select_db($Garydb, 'xxxxxxx');$sql = "SELECT CONCAT(FirstName,' ',LastName) AS Name FROM Members ORDER BY LastName ASC"; <-- That is how I merge two columns into one column.$result = mysqli_query($Garydb, $sql);$num_rows = mysqli_num_rows($result);$rows = ceil($num_rows / $column);while ($row = mysqli_fetch_array($result)) {$data[] = $row['Name'];}echo "<table border='7'>\n";for($i = 0; $i < $rows; $i++) {echo "<tr>\n";for($j = 0; $j < $column; $j++) {if(isset($data[$i + ($j * $rows)])) {echo "<td>".$data[$i + ($j * $rows)]."</td><td><input type='checkbox' name='member' value='".$data[$i + ($j * $rows)]."'></td>\n"; <-- "member" is a transfer data from this page to other page.}}echo "</tr>\n";}echo "</table>\n";?><input type="submit" value='Attendence'></fieldset></form></body></html> Now, This is a second page that set up with GET from previous page: <!doctype html><html><head><title>Test array attendence</title></head><body><table><?php$columns = 2;$count = 0;if(isset($_GET['member'])) {$display = ceil(count($_GET['member']));$row = ($display/$columns);while ($row = $display) {$data['Name'] = $row; <-- I type "Name" because I made a merge from two columns into one column - "SELECT (FirstName,' ',LastName) AS Name from Members"}echo "<table border='1'>";for($i = 0; $i < $rows; $i++) {echo "<tr>";for($j = 0; $j < $columns; $j++) {if(isset($data[$i + ($j * $row)])) {echo "<td>".$data[$i + ($j * $row)]."</td>";$count = $count+1;}}echo "</tr>";}}?></table><table><tr><td><?php echo $count." are attending this meeting tonight." ?></td></tr></table></body></html> Seem website is blank, no display the record... Quote Link to comment https://forums.phpfreaks.com/topic/296663-what-is-fatal-error-unsupported-operand-types-in-mean/#findComment-1513530 Share on other sites More sharing options...
ginerjm Posted June 9, 2015 Share Posted June 9, 2015 Be sure you have php error checking turned on so that you can read any error messages that arrive. Quote Link to comment https://forums.phpfreaks.com/topic/296663-what-is-fatal-error-unsupported-operand-types-in-mean/#findComment-1513533 Share on other sites More sharing options...
Barand Posted June 9, 2015 Share Posted June 9, 2015 Your checkbox name needs to be name= 'member[]' if you want to post an array of multiple values Quote Link to comment https://forums.phpfreaks.com/topic/296663-what-is-fatal-error-unsupported-operand-types-in-mean/#findComment-1513550 Share on other sites More sharing options...
sigmahokies Posted June 9, 2015 Author Share Posted June 9, 2015 Barand, I tried that, still not working, website is still blank as white screen Quote Link to comment https://forums.phpfreaks.com/topic/296663-what-is-fatal-error-unsupported-operand-types-in-mean/#findComment-1513567 Share on other sites More sharing options...
Barand Posted June 9, 2015 Share Posted June 9, 2015 It will never fly! Suppose 6 members selected $display = ceil(count($_GET['member'])); // $display -> 6 (ceil not required) $row = ($display/$columns); // $row -> 3 (this is where you want ceil) while ($row = $display) { // $row never == $display so doesn't execute $data['Name'] = $row; // assigning number to $data['Name'] ??? } Quote Link to comment https://forums.phpfreaks.com/topic/296663-what-is-fatal-error-unsupported-operand-types-in-mean/#findComment-1513569 Share on other sites More sharing options...
sigmahokies Posted June 10, 2015 Author Share Posted June 10, 2015 Hi Barand, If I change to 6, I'm sure it will apply the up to 6 checkboxes, suppose if i have 200 people in database, I have to set it up as 200 as well? About row, if I set 3, will it be 3 row, then infinite columns?I'm not sure what do you mean about row. That $display is coming from GET, seem it lost data from GET? Also, I put "[]", too (name='member[]') on my script... Quote Link to comment https://forums.phpfreaks.com/topic/296663-what-is-fatal-error-unsupported-operand-types-in-mean/#findComment-1513600 Share on other sites More sharing options...
Barand Posted June 10, 2015 Share Posted June 10, 2015 A while() loop executes as long as the condition evaluates to true. Since you have 2 columns then $row is not equal to $display and so the loop does not execute. If you change to 1 column then the loop will execute infinitely, as neither of the values change in the execution of the loop. Either way it does not work. Shouldn't you be looping through the members sent in $_GET['members'] and listing those? Quote Link to comment https://forums.phpfreaks.com/topic/296663-what-is-fatal-error-unsupported-operand-types-in-mean/#findComment-1513603 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.