Jump to content

Recommended Posts

What does this mean? is it an error with our php code or mysql query, I'm guessing it has to do with our query but I'm not sure, please help.

 

mysql_select_db($database_biosystem);
$query_content = "SELECT title, introtext, created FROM jos_content WHERE state=1 AND sectionid=1 AND catid=1 ORDER BY ordering";
$content = mysql_query($query_content);
$row_content = mysql_fetch_assoc($content);

do {
  echo "<div>".$row_content['title']."</div>";
  } while ($row_content = mysql_fetch_assoc($content)); ?>

You were using the resource id to echo the extracted rows.

 

Try this:

 

mysql_select_db($database_biosystem);
$query_content = "SELECT title, introtext, created FROM jos_content WHERE state=1 AND sectionid=1 AND catid=1 ORDER BY ordering";
$content = mysql_query($query_content);

while ($row = mysql_fetch_assoc($content)) {
   echo "".$row['title']."";
} 
?>

Thanks for the fast reply Maq,

 

The message is now Resource id #128

 

Here is my updated code

 

$query = "SELECT title, introtext, created FROM jos_content WHERE state=1 AND sectionid=1 AND catid=1 ORDER BY ordering";
$content = mysql_query($query);

while ($row = mysql_fetch_assoc($content)) {
   echo "<div>".$row['title']."</div>";
}

Good question, this code is for a custom Joomla module, I have built a lot of them and have never seen this before, if I disable the module or comment out all of the code the message goes away, here is all of the code I am using with in the module:

 

<div align="left" style="margin-bottom:15px;"><img src="templates/bcrc/images/latest_news.png" alt="" /></div>
<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

$query = "SELECT title, introtext, created FROM jos_content WHERE state=1 AND sectionid=1 AND catid=1 ORDER BY ordering";
$content = mysql_query($query);

while ($row = mysql_fetch_assoc($content)) {
   echo "<p>".$row['title']."</p>";
}

echo '<p>'.$params->get('catid').'</p>';

Ober, if I comment out the code like the following the message goes away:

 

<div align="left" style="margin-bottom:15px;"><img src="templates/bcrc/images/latest_news.png" alt="" /></div>
<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

/*
$query = "SELECT title, introtext, created FROM jos_content WHERE state=1 AND sectionid=1 AND catid=1 ORDER BY ordering";
$content = mysql_query($query);

while ($row = mysql_fetch_assoc($content)) {
   echo "<p>".$row['title']."</p>";
}
*/
echo '<p>'.$params->get('catid').'</p>';

<div align="left" style="margin-bottom:15px;"><img src="templates/bcrc/images/latest_news.png" alt="" /></div>
<?php

// no direct access
defined('_JEXEC') or die('Restricted access');


$query = "SELECT title, introtext, created FROM jos_content WHERE state=1 AND sectionid=1 AND catid=1 ORDER BY ordering";
$content = mysql_query($query);

if($content && mysql_num_rows($content) > 0)
{
while ($row = mysql_fetch_assoc($content)) {
   echo "<p>".$row['title']."</p>";
}
}
echo '<p>'.$params->get('catid').'</p>';

 

Time to go error trapping...

This is your error:

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/presto/public_html/bcr/modules/mod_latestnews1/mod_latestnews1.php on line 11

 

Means your query is failing.

 

Change your code to this and tell me what it outputs (should be a MySQL error):

 

$content = mysql_query($query) or die(mysql_error());

 

'state', 'sectionid', and 'catid' are all integer types in your table right?

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.