#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    113
    Rep Power
    14

    Change a specific query field within echo based on it's value?


    Hi, I’m needing my below query results to display “No” when ‘issue’ is a 0, and “Yes” when ‘issue’ is a 1.

    PHP Code:
    $sql "SELECT client_id,issue,comments FROM clients”;
    echo 
    $sql
    Returns something like:

    26|0|no comment
    42|0|no comment
    13|1|there was an issue
    58|0|no comment

    i.e.,

    26|No|no comment
    42|No|no comment
    13|Yes|there was an issue
    58|No|no comment


    Is that possible without changing the values within the database?

    Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,238
    Rep Power
    601
    Certainly. Simply loop through the resulting rows from your query and change '0' to 'No' and '1' to 'Yes' in that result array. Nothing will change the DB without issuing an 'UPDATE' query.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,089
    Rep Power
    1965
    You can also have a look at the CASE (WHEN) statement to add the required output directly in the SQL.

    Comments on this post

    • hominid4 agrees
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    113
    Rep Power
    14
    Originally Posted by MrFujin
    You can also have a look at the CASE (WHEN) statement to add the required output directly in the SQL.
    Ah! That works better for what I'm needing since it's within the query. Couldn't quite get the loop through to work as needed, but was able to with the CASE statement. Cool, thanks for pointing that out!
  8. #5
  9. No Profile Picture
    Super Moderator
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,399
    Rep Power
    24
    Just to throw it out there, to use within the while() loop or such...

    PHP Code:
    $response $value == 'There was an issue.' 'No comment.';
    $response = ($value == 1) ? 'There was an issue.' 'No comment.';
    $response = (($value == 1) ? 'There was an issue.' 'No comment.'); 
    Wrote the 3 lines just for favored formats and such...
    $newVar = ($dbVar == 1) ? 'IF TRUE' : 'IF FALSE';
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.

IMN logo majestic logo threadwatch logo seochat tools logo