Jump to content

Weird data allocation error


Skatecrazy1

Recommended Posts

Hey, was just writing rough code for a news feed script, and this error came up:

 

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 133693565 bytes) in /Applications/XAMPP/xamppfiles/htdocs/cameo/newsfeed.php on line 17

 

here's the code

<?php
require_once("vars.php");
//write the query to get the news feed info from the database
$query = "SELECT * FROM news_feed";
$result = mysqli_query($dbc, $query);
//create beginning tags for the news data table
$output = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" name=\"news_data\">";
//display the news feed data
$row = mysqli_fetch_array($result);
while($row){
    $output .= "<tr>"
    ."<td><h3>".$row['post_title']."</h3>"
    ."<br />Posted by: ".$row['posted_by']." on ".$row['date']."</td>"
    ."</tr>"
    ."<tr>"
    ."<td>".$row['post_body']."</td>"
    ."</tr>";
}

$output .= "</table>";

echo $output;

?>

 

and heres my vars file if needed

 

<?
//common session variables
$username = $_SESSION['username'];
$is_admin = $_SESSION['is_admin'];

//database connection information variables
$server = "localhost";
$user = "root";
$pass = "";
$db = "cameo";

//database function variables
$dbc = mysqli_connect($server, $user, $pass, $db);

//http header and script return variables
$index = "/cameo/index.php";
$self = $_SERVER['PHP_SELF'];

?>

Link to comment
https://forums.phpfreaks.com/topic/222433-weird-data-allocation-error/
Share on other sites

umm, i got an answer as to why my code's not working, but nothing on how to fix it, i tried incrementing the row's id field as such:

<?php
require_once("vars.php");
//write the query to get the news feed info from the database
$query = "SELECT * FROM news_feed WHERE ";
$result = mysqli_query($dbc, $query);
//create beginning tags for the news data table
$output = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" name=\"news_data\">";
//display the news feed data

while($row = mysql_fetch_array($result)){
    $row_id = $row['id'];
    $output .= "<tr>"
    ."<td><h3>".$row['post_title']."</h3>"
    ."<br />Posted by: ".$row['posted_by']." on ".$row['date']."</td>"
    ."</tr>"
    ."<tr>"
    ."<td>".$row['post_body']."</td>"
    ."</tr>";
    $row_id++;
}

$output .= "</table>";

echo $output;

?>

 

now I get this error, which by the way i've been getting a lot lately and it's quite annoying, I've used the same mysql_fetch_array parameters for years and the function is just now giving me problems, happens with select_db and mysql_connect as well:

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in /Applications/XAMPP/xamppfiles/htdocs/cameo/newsfeed.php on line 10

 

any help would be appreciated as I have a loose deadline coming up soon on this

k, finally got it working, but the 2 test rows I created are being displayed twice.  once again, here is the code:

 

<?php
require_once("vars.php");
//write the query to get the news feed info from the database
$query = "SELECT * FROM news_feed";
$result = mysqli_query($dbc, $query);
//create beginning tags for the news data table
$output = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" name=\"news_data\">";
//display the news feed data

while($row = mysqli_fetch_array($result)){
    
    $output .= "<tr>"
    ."<td><h3>".$row['post_title']."</h3>"
    ."<br />Posted by: ".$row['posted_by']." on ".$row['date']."</td>"
    ."</tr>"
    ."<tr>"
    ."<td>".$row['post_body']."</td>"
    ."</tr>";
    
}

$output .= "</table>";

echo $output;

?>

Archived

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

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