Jump to content

select records based on months


ramiwahdan

Recommended Posts

2 hours ago, ginerjm said:

Read a SQL manual for the functions available to be used in a query.   Research!

 

Feeling magnanimous - here:

https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_month

I was able to do it, Thanks. Now i need to know how to count the records.

my code:

$res = $conn->query("SELECT count(*) as counter
						 ,oracleid
                         , name 
                         , clockingindate   as clockin
                    FROM attendance_records
					where isdone =-1 and Month(ClockingInDate) = $themonth and Year(ClockingInDate) = $theyear
                    ORDER BY oracleid
                    ");

			$previd = 0;	
			$thecounter = 0;
			
            foreach ($res as $row) {
				
				if($row['counter'] == 1)

it is not working, how to know how many records i have?

Link to comment
Share on other sites

8 minutes ago, Barand said:

That query  should return a single record containing a count of all the records found

What does "not working" mean? Were you expecting more records?

here is my code, I know the answer to the count(*) is 4 so it should go through the second if statement but its not.

foreach ($res as $row) {
				
				if($row['counter'] == 1)	
				{
					if ($row['oracleid'] != $previd) { 
						
						if ($previd != 0) {
							
							$thecounter = 1;
							$previd = $row['oracleid'];					
							
						}
						else{
							
							$thecounter = $thecounter + 1;
							$previd = $row['oracleid'];
							echo "<br>";
							echo $thecounter;
							
							}
					}
				}
				
				if ($row['counter'] > 1)
				{
					
						if ($row['oracleid'] != $previd) { 
							
							if ($previd != 0) {
								
								$thecounter = 1;
								$previd = $row['oracleid'];	
								echo "<br>";
								echo $thecounter;
								
							}
							else{
								
								$thecounter = $thecounter + 1;
								$previd = $row['oracleid'];
								
								}
						}
						else
						{
							$thecounter = $thecounter + 1;
							$previd = $row['oracleid'];
							
						}
				}
				
			}

if ($row['counter'] > 1) is not work, what is wrong?

i echo out the result for the count(*) and says 4.

 

Untitled.png

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.