473,569 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SELECT COUNT for column in database?

1 New Member
How to Count number of rows in a table that matches to the related condition and echo that count out.

Code goes as follows::
Expand|Select|Wrap|Line Numbers
  1.     <?php 
  2.          $sql = "SELECT * FROM input ORDER BY date DESC";
  3.          $result = $conn->query($sql);
  4.  
  5.          if ($result->num_rows > 0) { 
  6.          while($row = $result->fetch_assoc()) { 
  7.          $myid = $row["id"] ;
  8.      $sql3 = "SELECT COUNT question_id FROM output WHERE question_id = $myid";
  9.         $result3 = $conn->query($sql3);
  10.     ?>
  11.  
  12.     <div id="q">
  13.  
  14.             <small><p><?php echo $row["date"]; ?></p></small>
  15.             <p id="tag3"><small><?php echo $result3['']; ?></small></p>
  16.     </div>
  17.  
Any Suggestions will be appreciated..
Sep 6 '16 #1
1 1553
RonB
589 Recognized Expert Moderator Contributor
You need to use a GROUP BY clause.
Expand|Select|Wrap|Line Numbers
  1. "SELECT question_id, COUNT(*) FROM output GROUP BY question_id"
Sep 6 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
10859
by: JP Belanger | last post by:
I have a question on select count(), which may betray my lack of database knowledge. Here goes. I have java code driving a transaction which goes like this: select count(*) from table (Java code in the same transaction) if count < 50 then ...
1
3685
by: Hunter | last post by:
Hi group - I'm using php to extract data from postgres and print to browser. I have data that was input through checkboxes on a form - each checkbox had a different value but got pushed into the same column. So - my values look like this: surveys=# select distinct(additionaldeliverablearray) from csssurvey; additionaldeliverablearray...
2
2262
by: Sygen | last post by:
I am attempting to create a simple recordset that would return the number of duplicates that exist in a table with a single column. For example if I had a table like the following: ID Reference Amount 1 123456 1.00 2 123456 2.00 3 123 1.00 I would like to get the following result:
12
39647
by: Bing Wu | last post by:
Hi, Has anyone got problem with this on large table. It seems it take ages to return the result ( half an hour :-( ). SELECT COUNT(*) FROM COORDINATE A strange thing is the tempory space (System Managed) keeps growing during the query: 14346747904 Dec 2 16:22 SQL00002.TDA
4
26516
by: Alec Christie | last post by:
Hi All, I want to Count the number of members in my database that have specific criteria, such as Blue eyes, or Brown hair. I have fields named Hair and Eyes, and others ofcourse, but I just want my VBA code to count the number with the specified value, ie Blue Eyes, and assign it to a variable that I can use, that is already defined. ...
5
23696
by: Daniel Wetzler | last post by:
Dear MS SQL Experts, I have to get the number of datasets within several tables in my MSSQL 2000 SP4 database. Beyond these tables is one table with about 13 million entries. If I perform a "select count(*) from table" it takes about 1-2 min to perform that task. Since I know other databases like MySQL which take less than 1 sec for...
2
6354
by: db2udbgirl | last post by:
If I perform a select count(*) from tred.order_delivery query will it internally perform a full table scan to determine the row count for the following scenario case 1: There is a primary key on a column case 2: There is a compound key on 1 columns col1, col2 case 3: No primary key in the table (Just for my education)
22
12437
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient...
5
9639
by: FFMG | last post by:
Hi, I was running a test on a table with 50000 rows. When I do: $sql = "SELECT * FROM TABLE"; $result = mysql_query($sql); $total = mysql_num_rows(result); I get a 'run out of memory error', (the limit is set low on the test
8
3643
by: Gilles Ganault | last post by:
Hello I'm trying to use the APSW package to access a SQLite database, but can't find how to check if a row exists. I just to read a tab-separated file, extract a key/value from each line, run "SELECT COUNT(*)" to check whether this tuple exists in the SQLite database, and if not, run an INSERT. The problem is that "if not row" isn't run:
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.