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

Link to comment
Share on other sites

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;

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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