Current location: Hot Scripts Forums » Programming Languages » PHP » count row with myslq


count row with myslq

Reply
  #1 (permalink)  
Old 11-11-11, 04:05 PM
williamh26 williamh26 is offline
Wannabe Coder
 
Join Date: Jul 2010
Posts: 132
Thanks: 2
Thanked 0 Times in 0 Posts
count row with myslq

I am ttrying to count how many entries have the row but for some reason i have error this the code
PHP Code:



<?php
         login
();
         
$quest_sub_id $_GET['cat'];
         
$query="SELECT quest_sub_id, topic from topicquestion where quest_sub_id = $quest_sub_id ORDER BY topic ASC";
         
$result=mysql_query($query);
         while(
$row=mysql_fetch_array($result,MYSQL_ASSOC))
         {
             
$quest_sub_id $row['quest_sub_id'];
             
$topic $row['topic'];
             
$query2="SELECT count(quest_sub_id) FROM topicproblems WHERE quest_sub_id = $quest_sub_id ";
             
$result2 mysql_query($query2);
             
$row=mysql_fetch_array($result2);
             
$total $row[0];

             echo 
"<h3><a href=\"index.php?content=problems&cat=$quest_sub_id\">$topic</a>($total)</h3><br>\n";
         }
       
?>
I have this error
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\chemath.com\topics.inc.php on line 13

thank your for your help
Reply With Quote
  #2 (permalink)  
Old 11-16-11, 12:57 AM
phplabs phplabs is offline
Newbie Coder
 
Join Date: Oct 2011
Posts: 37
Thanks: 0
Thanked 7 Times in 7 Posts
it seems that lines 12-13 have this code (i'm referring to those lines because the warning says the problem is in line 13).

$result=mysql_query($query);
while($row=mysql_fetch_array($result,MYSQL_ASSOC))

the warning also says that parameter 1 ($result) is boolean, which probably means that $result is false here. you can check this using var_dump($result). if that is so, it means that you have an error in your query execution.

in general, it's a good idea to check if $result has a value before fetching the data:

$result=mysql_query($query);
if($result) {
// result is ok, fetching the data
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
...
}
else {
// some error occurred
}
__________________
blog.phplabs.net
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help 1Column count doesn't match value count at row 1 matedgo PHP 2 05-16-09 09:09 PM
[SOLVED] row count in mysql zodehala PHP 3 01-13-08 02:56 PM
Mysql Incorrect Count MrDarko Database 6 08-07-07 12:22 PM
"Column count doesn't match value count at row 1" Oskare100 PHP 3 01-12-07 12:54 PM
Row Count Sniper12p PHP 3 07-03-04 04:49 AM


All times are GMT -5. The time now is 08:53 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.