Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About kilnakorr

  • Rank

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Thanks a bunch. I did get it to work doing an if statement in the loop, but this is much better!
  2. Thanks for the reply, and very true the "Error" makes no sense at all. I can't get your code to work, maybe because it needs to be split up as the while loop, sets an array. The main problem is, that I have the following code: var myData=[<?php $data=mysqli_query($mysqli,"SELECT Date, COUNT(*) as total FROM db WHERE Step='CPR' AND Error='1' AND Date BETWEEN '$Fromdate' AND '$Todate' GROUP BY Date"); while($info=mysqli_fetch_array($data)) echo '"'.$info['Date'].'",'; /* We use the concatenation operator '.' to add comma delimiters after each data value. */ ?>]; The result of the above code is: var myData=["2019-01-02","2019-01-03","2019-01-15","2019-01-18","2019-01-21","2019-01-22","2019-01-24","2019-01-28","2019-01-31","2019-02-01","2019-02-02","2019-02-06","2019-02-07","2019-02-08","2019-02-15","2019-02-17","2019-02-20","2019-02-25","2019-02-28","2019-03-05","2019-03-06","2019-03-15","2019-03-19","2019-03-30",]; Basically, getting every date where the 'Step' is CPR and 'Error' is 1. Now I also need to get the same values but only for a specific 'Department': $data=mysqli_query($mysqli,"SELECT COUNT(*) as total FROM jss_test WHERE Step='CPR' AND Error='1' AND Department='Kundeservice' AND Date BETWEEN '$Fromdate' AND '$Todate' GROUP BY Date"); ?> var totalKS=[<?php while($info=mysqli_fetch_array($data)){ echo $info['total'].',';} /* The concatenation operator '.' is used here to create string values from our database names. */ ?>]; This returns: var totalKS=[1,2,2,1,1,1,1,2,]; All good, but since I don't have same number of results, they don't really match up as intended. What I need really is be able to have the same amount of results, but if 'Department' isn't 'Kundeservice' then return a "0" Hope it makes sense, and someone got an idea.
  3. Thanks for the reply. Yes, I was thinking the same thing. Testing if something is returned and if not set my variable to '0'. I just can't seem to figure out how?!
  4. Hi I'm using the below code <?php //Getting failed orders for Online $data=mysqli_query($mysqli,"SELECT Error, COUNT(*) as total FROM db WHERE Department='Online' AND Date BETWEEN '$Fromdate' AND '$Todate' GROUP BY Date"); ?> var totalOnline=[<?php while($info=mysqli_fetch_array($data)){ echo $info['total'].',';} /* ?>]; Now some of these doesn't return anything as it should, but is there a way to return 0 instead?
  5. thanks for the input. I'm very aware that the input right now doesn't validate if it's a correct format. At the moment, I'm simple wondering why the query won't work i $Startdate is set as $Startdate = '1980-01-01' but works fine when it comes from the input?
  6. Hi I'm having a problem getting a query to work. I have a simple form with user input for start and end date with format: 2009-03-19 (todays date): $Startdate = $_POST['date']; This works well when something is entered into the form, and afterwards using my query: SELECT COUNT(*) as total FROM mydb WHERE Date BETWEEN '$Startdate' AND '$EndDate' ........ Problem is if user submits the form without entering anything in the date input fields, which makes sense. I want to check if inputs has been made, and if not set af default date, but can't make it work: if (isset($_POST['date']) && $_POST['date'] !='') { $Startdate = $_POST['date'];} else { $Startdate = '1980-01-01';} How can I set $Startdate to something that can be used in the query as below doesn't work?
  7. It helps a bunch, and works great for outputting a neat table. I figured out how to use it for the rest of my code. Thank you so much for helping out a noob
  8. It's not that I'm lazy. As mentioned in my original post 'I'm not at all good at PHP'. I do appreciate the time you and everyone else is spending trying to show me possible solutions, but what you have already shown me simply isn't enough for me to understand, or the shown code isn't what I'm looking for. I do get the fact that the query sums up the number of unique steps for each department, which truly was my first hurdle, but how do I get those 'totals' into the next part of the code?: // total for Online, step1 if(totalgoeshere > 0 && < 25) { copy(image1.png,'other_image.png'); } // total for Online, step2 if(totalgoeshere > 0 && < 25) { copy(image1.png,'other_image.png'); } // total for Online, step3 if(totalgoeshere > 0 && < 25) { copy(image1.png,'other_image.png'); } // total for Sales, step1 if(totalgoeshere > 0 && < 25) { copy(image1.png,'other_image.png'); } // and so on and on and on..... And will I be forced to do the above for each department and step?
  9. So how will perform the remaining code?: if($result > 0 && < 25) { copy(image1.png,'other_image.png'); } How can I get the '$result' for example 'Sales' 'step1'? And will I be forced to do above if statement for all variations or is there a better way?
  10. Thanks for the fast replies! They are all in same column called 'Department'. Maybe I should try and explain the entire problem, and what I wish to achieve. First the database: +------+----------+-------------+ | ID | Step | Department | +------+----------+-------------+ | 1 | step1 | Sales | | 2 | step1 | Support | | 3 | step2 | Online | | 4 | step2 | Online | | 5 | step1 | Support | | 6 | step2 | Support | | 7 | step3 | Online | | 8 | step2 | Sales | | 9 | step4 | Support | +------+----------+-------------+ What are actually need as end result is to count the number of rows for EACH Department and EACH step: so I need the rows for: Sales step1 Sales step2 Sales step3 etc Support step1 Support step2 Support step3 and so on... They will be 4 or 5 Values (text) in column 'Department', but hundreds of values in column 'Step'. So whats the simplest approach to get all these counts? I will afterwards need to copy an image from a folder based on the count of rows - so below code (just example) needs to work for every row count: if($result > 0 && < 25) { copy(image1.png,'other_image.png'); } elseif($result >= 25 && $cpr_errors < 75 { $copy(image2.png,'other_image.png'); } elseif($result <= 75) { $copy(image3.png,'other_image.png'); } This means hundreds of images copied and replaced. Hope you get the idea
  11. Hi I'm not at all good at PHP and haven't really played with it for some years, so bare with me if code examples are old I'm looking for a simple solution to count rows (MySQL), without using multiple queries. The below code is quite simple, counting rows where 'Department' is 'Sales': $sql ="SELECT * FROM DB WHERE Department ='Sales'"; $result=mysqli_query($con,$sql); $rowcount=mysqli_num_rows($result); But what If I need to count the rows for the different departments?: $sql ="SELECT * FROM DB WHERE Department ='Sales'"; $result=mysqli_query($con,$sql); $rowcount=mysqli_num_rows($result); $sql ="SELECT * FROM DB WHERE Department ='Support'"; $result=mysqli_query($con,$sql); $rowcount=mysqli_num_rows($result); $sql ="SELECT * FROM DB WHERE Department ='Online'"; $result=mysqli_query($con,$sql); $rowcount=mysqli_num_rows($result); There must be a better / simpler way to this with a single query? Hope for someone to show me the light PS. Once this is resolved, I'll probably need further help, to accomplish my final result.
  12. Hi I'm using an opensource program called draw.io. ( https://www.draw.io/ ) It has some limitations, which I need corrected if possible. It seems plugins can be created, so this might be the way to go. Firstly, I need to be able to create links with html code eg. 'google.com class="myclasshere" target="myframe"' etc. There will also, be some minor things (i think it's minor), that I want to be possible. Send me PM for details, and I'll explain in details, send you some files to look at. Let's discuss payment / amount after the project is clear and understood. Regards Casper
  • 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.