0

Running one single instance of the justgage which retrieves the "count" value of my select statement (Which I've retrieved from the net) This is working fine. It shows the amount of issues where the prio(ority) equals 2.

Here's my challenge. I wish to have 5 gauges, for each gauge I want to its value to be retrieved and showed from the database. However I can't figure out the $query command.

This is my php part:

  <?php

  // connect to the database
    include('connect-db.php');
   // Make a MySQL Query and assign variable
    $query = "SELECT COUNT(prio) as prio_a FROM ticket WHERE prio=2";       
   //assign result to a variable
    $result = mysql_query($query) or die(mysql_error());
   //fetch result as an associative array
    $data = mysql_fetch_assoc($result) or die(mysql_error());
?> 

This is my gauge:

<div id="r1"></div>

<script>
        var r1 = new JustGage({
          id: "r1",
          value: <?php echo $data['prio_a']; ?>,
          min: 0,
          max: 100,
          title: "Prio Geen",
          label: "PRIORITEIT"
        });

</script>

My idea was: A second gauge would look like this?

<div id="r1"></div>

<script>
        var r2 = new JustGage({
          id: "r2",
          value: <?php echo $data['prio_b']; ?>,
          min: 0,
          max: 100,
          title: "Prio Geen",
          label: "PRIORITEIT"
        });

</script>

Hopefully I can then continue with even more gauges (Five for 'priorities', Nine for 'status", Eight for 'type of issues' and two for 'open/closed tickets')

Any help, ideas would be appreciated.

  • First of all: Don't use `mysql_*` but use `mysqli_` or `PDO` instead. `mysql_*` is depreciated and will be removed. – KhorneHoly Jan 02 '17 at 15:42
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Jan 02 '17 at 15:46
  • So run 5 queries and get 5 results – RiggsFolly Jan 02 '17 at 15:47
  • It would be useful to know what the other queries where as there may be a quicker method, But guessing is a bad idea here – RiggsFolly Jan 02 '17 at 15:48
  • Thank you for your time. This is where the "Forest" gets bigger for me. As I'm not a native programmer. (I do like puzzles, but to copy pieces of puzzles and reuse/modify them. ;) – Michiel van Erven Jan 02 '17 at 15:49
  • @RiggsFolly: The selects I had in mind where: $query = "SELECT COUNT(prio) as prio_a FROM ticket WHERE prio=1"; $query = "SELECT COUNT(prio) as prio_a FROM ticket WHERE prio=3"; $query = "SELECT COUNT(prio) as prio_a FROM ticket WHERE prio=4"; $query = "SELECT COUNT(prio) as prio_a FROM ticket WHERE prio=5"; For the first set of 5 gauges. I'll will have a look at the link you've given me. – Michiel van Erven Jan 02 '17 at 15:52
  • @RiggsFolly: So you say I can have 5 different query's? 5 different $query = "SELECT COUNT(prio) as prio_a FROM ticket WHERE prio=2"; The "Where prio=2 would change to 1, 3, 4 and 5 Haven't tried that one yet. Will try immediately. – Michiel van Erven Jan 02 '17 at 16:00

2 Answers2

0

You could try

SELECT prio, COUNT(prio) as tot FROM ticket 
GROUP BY prio
WHERE prio in (1,2,3,4,5)
ORDER BY prio

If you only have 5 prio values you can forget the WHERE clause

This will return you 5 result rows, and you can build your javascript in the while loop which processes the resultset

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
0

I've solved with a work-around. I've created a stored procedure in the database from where I retrieved the results as a Json Array. Thanks for all info.

PS: @RiggsFolly: Allergic to cats ;) So one more or less cats...

Happy New year!