Welcome!

And don't forget to edit your signature & profile.

 

Icon

Statistics

  • Total posts 26748
  • Total topics 4864
  • Total members 6599
  • Our newest member
    efru

TOP POSTERS

Warning: mysql_num_rows(): supplied argument is not a valid

All problems and developments related to PHP, Ruby on Rails & Co. are discussed and resolved here.
   
<?
$queryOne = "select * from news where active=1 order by published_date";
$queryOneRun = mysql_query($queryOne) or die('Query failed: ' . mysql_error() . "<br />\n$queryOne");
$queryOneCount = mysql_num_rows($queryOneRun);

for ($a=1;$a<=$queryOneCount;$a++)
{
$fetchRow = mysql_fetch_row($queryOneRun);
print "<tr>
<td class='s9' valign='top'>
<img src='img/gen/cg_icon_v.gif' border='0'>&nbsp;<b>$fetchRow[1] - $fetchRow[5]</b>
<br />
<p align='justify'>$fetchRow[2]
</td>
</tr>

<tr>
<td align='right' class='s10' colspan='2'>
<img src='img/gen/cg_icon_iv.gif' border='0'>&nbsp;<a href='news_details.php?id=$fetchRow[0]' target='_self'>Read more</a>&nbsp;&nbsp;&nbsp;&nbsp;
</td>
</tr>

<tr>
<td class='s22'>&nbsp;</td>
</tr>
";
}
?>

:?: Please help me what to do with this, I'm a newby to php. What is the error?
konsehal_14
 
Posts: 3
Joined: Sun Apr 26, 2009 7:34 am
   

   
I do not know what you did wrong, but after copying the example you gave, and rewriting it readable, i got it working.

Perhaps you should try it like this ?

Code: Select all
$connection = mysql_connect('localhost','root','root');
mysql_select_db('test',$connection);
$query = "select * from news where active=1 order by published_date";
$result = mysql_query( $query ) or die( mysql_error() );
$count = mysql_num_rows( $result );

for ($a=1;$a<=$count;$a++)
{
$fetchRow = mysql_fetch_row($result);
print "<tr>
<td class='s9' valign='top'>
<img src='img/gen/cg_icon_v.gif' border='0'>&nbsp;<b>$fetchRow[1] - $fetchRow[5]</b>
<br />
<p align='justify'>$fetchRow[2]
</td>
</tr>

<tr>
<td align='right' class='s10' colspan='2'>
<img src='img/gen/cg_icon_iv.gif' border='0'>&nbsp;<a href='news_details.php?id=$fetchRow[0]' target='_self'>Read more</a>&nbsp;&nbsp;&nbsp;&nbsp;
</td>
</tr>

<tr>
<td class='s22'>&nbsp;</td>
</tr>
";


even better would be like this

Code: Select all
while( $item = mysql_fetch_assoc( $result ) ) {
print "<tr>
<td class='s9' valign='top'>
<img src='img/gen/cg_icon_v.gif' border='0'>&nbsp;<strong>" . $item['title'] . " - " . $item['date'] . "</strong>
}


and naming the vars
frankbr
 
Posts: 1
Joined: Wed May 06, 2009 2:33 pm
   

   
as frankbr said, using mysql_fetch_assoc and a while loop would be much easier for you.

Code: Select all
$queryOne = "select * from news where active=1 order by published_date";
$queryOneRun = mysql_query($queryOne) or die('Query failed: ' . mysql_error() . "<br />\n$queryOne");
$queryOneCount = mysql_num_rows($queryOneRun);
for ($a=1;$a<=$queryOneCount;$a++)


would become:

Code: Select all
$queryOne = "select * from news where active=1 order by published_date";
$queryOneRun = mysql_query($queryOne) or die('Query failed: ' . mysql_error() . "<br />\n$queryOne");

while( $item = mysql_fetch_assoc( $queryOneRun ) )
{
      echo $item['fieldhere'];
}


As for the error, i can only guess your query is failing, and trying to use the debug output for a parameter.
spec
 
Posts: 6
Joined: Fri Mar 13, 2009 9:56 am
   


Return to Server-side Scripting



Who is online

Users browsing this forum: No registered users and 1 guest