Solved

Count the number of rows :

Posted on 2012-04-08
4
290 Views
Last Modified: 2012-04-09
Hi, I have the following sql statement in php:

$query_1 = "SELECT patient_id,visit_notes, DATE_FORMAT(visit_date,'%Y-%m-%d') AS event_date FROM patient_visitschedule WHERE visit_date LIKE '$year-$month%'";
$num_rows = mysql_num_rows($query_1);
echo $num_rows;

When I run this code I get the following error, why is this?

Warning: mysql_num_rows() expects parameter 1 to be resource, string given in C:\xampp\htdocs\carePlus\module_patient\viewPatientSchedule.php on line 65

Now when I run the following code;

$events = array();
$query_1 = "SELECT patient_id,visit_notes, DATE_FORMAT(visit_date,'%Y-%m-%d') AS event_date FROM patient_visitschedule WHERE visit_date LIKE '$year-$month%'";
$result_1 = mysql_query($query_1) or die('cannot get results!');
while($row = mysql_fetch_assoc($result_1)) {
$events[$row['event_date']][] = $row;

I get the event information displayed on my php page, but what I need is the count of the number of rows fetched. Can someone help me here. Thank  you.

A
0
Comment
Question by:aej1973
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Expert Comment

by:ramrom
ID: 37822163
instead of $num_rows = mysql_num_rows($query_1);
try $num_rows = mysql_num_rows($result_1);
after, of course, running the query,
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 125 total points
ID: 37822185
$query_1 is a string variable. To get a results set you actually need to run the query!
$query_1 = "SELECT patient_id,visit_notes, DATE_FORMAT(visit_date,'%Y-%m-%d') AS event_date FROM patient_visitschedule WHERE visit_date LIKE '$year-$month%'";
$x = mysql_query($query_1);
if (!$x) due("FAIL $query_1<br/>" . mysql_error() );
$num_rows = mysql_num_rows($x);
echo $num_rows;

Open in new window

0
 

Author Closing Comment

by:aej1973
ID: 37822397
Thank you.
0
 
LVL 17

Expert Comment

by:ramrom
ID: 37823674
Why did you accept a 2nd and later version of my solution instead of mine?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question