0

I am trying to get this piece of code to input something along the lines of "received (this many points) for (reason for points). So far I have this.

if ($resultss->num_rows > 0) {
// output data of each row
while($row2 = $resultss->fetch_assoc()) {
    echo "Received " . $row2["id_points"]. " points for " . $row2['id_task']."<br>";
  }
} else {
echo "0 results";
}

So far, my code is almost working. This is the input. "Received 15 points for 1" As you can see, the problem is that the reason is the number that is stored in the sql database. I want to know how I can convert that number into words. Thank you for your response in advance

Stefan
  • 4,831
  • 8
  • 24
  • 48
Anthony
  • 51
  • 6
  • Do you have a table with `task_id` and `task_name` ? – Tᴀʀᴇǫ Mᴀʜᴍᴏᴏᴅ Jan 09 '16 at 13:55
  • 1
    http://stackoverflow.com/questions/14314997/how-to-convert-amount-in-number-to-words – Nouphal.M Jan 09 '16 at 13:56
  • *id_points* does not sound like the right field for giving the number of points; but the **id** of the record that has the points. Provide in your question the SQL statement, the tables you have with some example data, and the output you expect to get. – trincot Jan 09 '16 at 13:58
  • Possible duplicate of [How to 'insert if not exists' in MySQL?](http://stackoverflow.com/questions/1361340/how-to-insert-if-not-exists-in-mysql) – brnrd Jan 09 '16 at 17:39

1 Answers1

2

Something like this perhaps?

<?php

  function getTaskFromID($id){
    switch($id){
      case 1: return 'foo';
      case 2: return 'bar';
      default:
        return 'You did something we did not approve of..';
    }
  }

  echo "Received " . $row2["id_points"]. " points for " . getTaskFromID($row2['id_task'])."<br>";
?>

However, this should actually be done with a sql join. In 1 query you would be able to select the points and the task string by just adding 1 table with two cols of "task_id" and "task_msg".

Xorifelse
  • 7,408
  • 1
  • 23
  • 37