Jump to content

what is "Fatal error: Unsupported operand types in" mean?


sigmahokies
 Share

Recommended Posts

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 by sigmahokies
Link to comment
Share on other sites

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'];
Link to comment
Share on other sites

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>";
}
}
?>
Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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'] ???
}
Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.