Jump to content

Archived

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

sigmahokies

"Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 36 bytes)" what does it mean?

Recommended Posts

Cronix and Jazzman1, here my update script in PHP. Jazzman1, I tired your code, seem it doesn't work. I get error in 13th line
 

<!doctype html>
<html>
<head>
<title>Test array attendence</title>
</head>
<body>
<table border="1">
            <?php
            if (!empty($_GET['member'])) {
                
                $data = $_GET['member'];
 
                foreach (array_chunk($data, 2) as $row): <-- 13th line
                    ?>
                    <tr>
                        <?php foreach ($row as $value): ?>
                            <td><?php echo htmlentities($value); ?></td>
                    <?php endforeach; ?>
                    </tr>
                <?php
                endforeach;
            }else {
                echo "Fail to get data from previous";
            }
            ?>
        </table>
<table><tr><td><?php echo count($_GET['member'])." are attending this meeting tonight." ?></td></tr></table>
</body>
</html>
 
I get result:

Warning: array_chunk() expects parameter 1 to be array, string given in /srv/disk10/1141650/www/sigmahokies.biz.ht/testarray3.php on line 13

Warning: Invalid argument supplied for foreach() in /srv/disk10/1141650/www/sigmahokies.biz.ht/testarray3.php on line 13
 
Those are error message.
 
Hope to hear from you soon

Share this post


Link to post
Share on other sites

It boils down to $_GET['member'] is not an array, so it's breaking the array_chunk() function which only works on...arrays. Where is 'member' coming from in the GET request? A form? A custom built url? Post how that is generated.

Share this post


Link to post
Share on other sites

Cronix,

 

That 'member' is come from first page that has name='member' that should transfer value to second page. it is on thread in here on first page, but I better post my first page...

 

Here my code:

 

<!doctype html>
<html>
<head>
<title>Test array with columns</title>
</head>
<body>
<form action="testarray3.php" method="GET">
<fieldset>
<?php
$column = 2;
 
$Garydb = mysqli_connect('XXXXX','XXXXX','XXXXX') or die("Could not connect to database.");
mysqli_select_db($Garydb, 'XXXXX');
$sql = "SELECT CONCAT(FirstName,' ',LastName) AS Name FROM Members ORDER BY LastName ASC";
$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";
}
}
echo "</tr>\n";
}
echo "</table>\n";
?>
<input type="submit" value='Attendence'>
</fieldset>
</form>
</body>
</html>
 
This is my first page, so name='member' suppose to delivery value (person's name) to my second page. This first page DO work in vertical table data perfect that I found website that show me a code. Check this website for example - http://sigmahokies.biz.ht/testarray2.php

Share this post


Link to post
Share on other sites
echo "<td>".$data[$i + ($j * $rows)]."</td><td><input type='checkbox' name='member' value='".$data[$i + ($j * $rows)]."'></td>\n";

Change name="member[]", with [] after. That's the HTML way to create an array in a form using the same name.

Share this post


Link to post
Share on other sites

Oh FINALLY!!!! it works!!! FINALLY!!! i am going to create 200 name in database! It is EXACTLY what I need to do! Thank you, Cronix and Jazzman1!!!

Share this post


Link to post
Share on other sites

Jazzman1,

 

your code is working, but it apply to two columns, I need to have many columns, I notice ascending don't work in 1 and 3 or more than 3 columns. I added sort(), but seem it won't recognized this code to make those name stay in order...

Share this post


Link to post
Share on other sites

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