Jump to content

Problem With mysql_fetch_array Not Working


EternalSorrow

Recommended Posts

I've recently upgraded some of my script to accept special characters for titles.  However, the new addition is interfering with a mysql_fetch_array I am using to retrieve information from a query within a query.

 

Here's the snippet of code newly added to accept special characters:

 

$select_table = sprintf("SELECT * FROM `stories` WHERE `story` = '%s' ", mysql_real_escape_string($story));
$select_results = mysql_query($select_table) or die (mysql_error());

 

I originally had a simple query statement selecting the same information, minus the special character addition, with the inclusion of this array:

 

$tableArray = mysql_fetch_array($select_table);

 

Now, however, with the use of the sprintf the fetch_array is ignored in favor (I'm guessing) of the $select_results.  When I try to use simply the $tablearray line, I receive the error message that the "mysql_fetch_array(): supplied argument is not a valid MySQL result resource."

 

I've tried adding a WHILE statement to the mess but that attempt failed.  I'd be grateful for any hints in the right direction to solving this annoying dilemma.

 

For reference, here's the complicated mess in all its infamy (minus the pagination script at the end):

 

<?php

$query = "SELECT * FROM stories WHERE `series`= '$series' ";
$result = mysql_query( $query ) or die(mysql_error());

$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];

$rows_per_page=5;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
$last = $pages -1;

if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$query .= "LIMIT $start, $rows_per_page";
$result= mysql_query($query) or die("Could not execute query : $query." . mysql_error());
$i = 1;

echo '<h1>'.$series.'</h1><ul>';

while ($row1 = mysql_fetch_array($result))
{
extract($row1);

$select_genre = mysql_query("SELECT * FROM genre WHERE story_id = $story_id ORDER BY genre asc ") or die (mysql_error());

$cat = "";
while ($row2 = mysql_fetch_array($select_genre)) {
   $cat .= "<a href=\"genre.php?genre={$row2[genre]}\">$row2[genre]</a>, ";
}

$cat = substr($cat,0,-2);

$select_table = sprintf("SELECT * FROM `stories` WHERE `story` = '%s' ", mysql_real_escape_string($story));
$select_results = mysql_query($select_table) or die (mysql_error());

$tableArray = mysql_fetch_array($select_table);

$retrieve = $tableArray['chapter_id'] -1;

$add = '';

if (strlen($status) >= 10) { 
$add = "| Newest Chapter: <a href=\"fanfiction.php?story=$story&screen=$retrieve\">$tableArray[title]</A> "; 
}
   
$contents_here = '<li><h3><a href="fanfiction.php?story='.$story.'" >'.$story.'</A></h3>
'.$summary.'
<div class="fan">Series: <a href="stories.php?series='.$series.'">'.$series.'</A> | Status: '.$status.' | Type: <a href="type.php?type='.$type.'">'.$type.'</A> | Universe: '.$universe.' | Rating: '.$rating.' | Chapter(s): '.$tableArray['chapter_id'].' '.$add.'| Pairing: '.$pairing.' | Genre: '.$cat.' | Last updated: '.$tableArray['date'].'</div>';
   
if ($i==1)
    {
    echo ''.$contents_here.'';
    }
   
    else if ($i==0)
    {
    echo ''.$contents_here.'';
    }

    $i++; $i=$i%2;

}
echo '</ul>

<ul class="series">';

Sorry about that mistake, I'd forgotten to change the Array to the updated code for the post.  I had tried to change the tableArray line accordingly, but all uses of the $tableArray within the contents_here area still do not retrieve any of the information within that database specified in the select_table query.

 

Which means blank areas with no data showing.  Lots of them :-[

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.