PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 15th, 2012, 04:30 PM
timsharpe timsharpe is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Posts: 909 timsharpe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 5 h 34 m 32 sec
Reputation Power: 0
Count is not working

I am using the code below I want a count beside each link but when I use it only 1 record link shows, why I do not use the count all links show why?

PHP Code:
while ($row mysql_fetch_array($result))
        {
extract($row);
$result mysql_query("SELECT * FROM answers WHERE qid ='qid'");
$num_rows mysql_num_rows($result);


print 
"<a href=\"?tab=View Question&qid=$qid\">$question</a> - Votes: $num_rows<br>"



__________________
Daily Deals from Kingston to Brockville and Cornwall Ontario. www.seawaydeals.com

Reply With Quote
  #2  
Old May 15th, 2012, 05:35 PM
Catacaustic's Avatar
Catacaustic Catacaustic is offline
Code Monkey V. 0.9
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2005
Location: A Land Down Under
Posts: 1,886 Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 15 h 12 m 20 sec
Reputation Power: 1798
Just wondering if it's not supposed to be this (I think you've left the $ off the $qid variable in your query)?
PHP Code:
 $result mysql_query("SELECT * FROM answers WHERE qid ='$qid'"); 


If your query is right, look at how many answers have the value for qid set as 'qid' and you'll find how many answers there are for that question.

Reply With Quote
  #3  
Old May 15th, 2012, 05:43 PM
timsharpe timsharpe is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Posts: 909 timsharpe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 5 h 34 m 32 sec
Reputation Power: 0
Yes I fixed that but it still does not work

Reply With Quote
  #4  
Old May 15th, 2012, 05:52 PM
Catacaustic's Avatar
Catacaustic Catacaustic is offline
Code Monkey V. 0.9
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2005
Location: A Land Down Under
Posts: 1,886 Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 15 h 12 m 20 sec
Reputation Power: 1798
Then echo out the query, and run that directly against your DB, using something like phpMyAdmin or whatever other DB management tool you have.
PHP Code:
 $query "SELECT * FROM answers WHERE qid ='$qid'";
echo 
"<p>".$query."</p>";
 
$result mysql_query($query); 

That will tell you the results from that query. The most likely cause of this is that there is only one answer in your DB for that question ID.

Reply With Quote
  #5  
Old May 16th, 2012, 03:41 AM
sypack sypack is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 2 sypack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m
Reputation Power: 0
Try using back tick around the table name.

Reply With Quote
  #6  
Old May 16th, 2012, 04:04 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Posts: 1,923 cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 16 h 21 m 8 sec
Reputation Power: 377
What does the query that builds the first result look like?

And can you provide a SHOW CREATE TABLE for each of the relevant tables?

Reply With Quote
  #7  
Old May 16th, 2012, 04:56 AM
badger_fruit's Avatar
badger_fruit badger_fruit is offline
Confused badger
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Location: West Yorkshire
Posts: 760 badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 5 h 15 m 18 sec
Reputation Power: 339
You're using $result twice and I suspect that's the reason.

PHP Code:
while ($row mysql_fetch_array($result))    <--- HERE
        
{
extract($row);
$result mysql_query("SELECT * FROM answers WHERE qid ='qid'");
$num_rows mysql_num_rows($result); <---- HERE


print "<a href=\"?tab=View Question&qid=$qid\">$question</a> - Votes: $num_rows<br>"



I recommend calling the 2nd $result something else such as $sub_result or $whatever_you_want_to_call_it_just_as_long_as_its_not_called_result

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Count is not working

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap