Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3313804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:09:29+00:00 2026-05-17T22:09:29+00:00

Brain totally not working today. So, I have a few columns in a table

  • 0

Brain totally not working today.

So, I have a few columns in a table that basically designate whether a certain piece of information WAS or WAS NOT provided by the user.

For example, I have a table with:

| ID | USER | crit1 | crit2 | crit3 | crit4 | etc. |

Now, the record could have a 1 or yes for any of the “critX” fields. I dunno much about math and permutations, but I guess if there were 4 columns, you could have 16 combinations of output. In my real world example I have 16 different criteria, so I can’t factor for the output of that mess. I need to write a routine of some sort.

In my example, each of those crit values is going to be evaluated and if the criterion == 1/yes, it will be included in another variable AND have a more human friendly bit of data assigned to it. I am currently pulling each value from the DB an doing something like

### first I pull the values
$mydbarray[crit1] = $cr1;
$mydbarray[crit2] = $cr2;
$mydbarray[crit3] = $cr3;
(etc...)

### then I assign some human friendly text ONLY if the value == 1/yes
if($cr1==1) ($cr1 = "This info is present!";}
if($cr2==1) ($cr2 = "Number two is present!";}
if($cr3==1) ($cr3 = "Three was provided!";}

Now, what I need to do, is collect all that output only if the “IF” fired on true and assemble into a final variable.

So somehow, I want:

$finaloutput = $cr1, $cr2, $cr3;

Obviously that’s not valid or what I want, but even if it DID work, it would end up including all the == 0/no instances as well.

So essentially I need a conditional grouping of these variables and I am not getting it.

I was thinking of casting an array and looping through it, but then I was at a loss for including the human intelligible portions…

Some guy at work mentioned an IF statement using bool, but I am not wellversed there.

I would think this is easy, but I’ve been up all week with the baby. so my brain is broken.

Thanks in advance!!!
Rob

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:09:29+00:00Added an answer on May 17, 2026 at 10:09 pm

    First of all much of what you wrote is not valid PHP. I will assume you wrote it just to illustrate the point and didn’t bother with the syntax.

    Here is how to do it:

    You take an array in which you will put your texts:

    $texts = array();
    

    For each of your criteria you check if they are provided, but add to the array created before:

    if($cr1==1) {$texts[] = "This info is present!";}
    if($cr2==1) {$texts[] = "Number two is present!";}
    if($cr3==1) {$texts[] = "Three was provided!";}
    ...
    

    In the end you concatenate all your texts with implode:

    $finaloutput = implode(', ', $texts);
    

    I prefer the method with implode to the one that just appends to a string because if I want a comma separator I don’t get an extra one at the end.

    Good luck, Alin

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brain not working today - can anyone give me a regexp that would turn:
brain not working today...can't seem to figure this one out. your help is much
I have a SQL challenge that is wracking my brain. I am trying to
No coffee. Brain. Not. Functioning. I have this linq query here: Public Function ListAllVisitDates()
I have been working on this program for quite sometime and my brain is
Here's a brain teaser that's been on my mind for a few days. We
Suspect my brain isn't working today - I need to extract a list of
OK so my brain is just probably not working tonight. What I'm trying to
I collect a few corner cases and brain teasers and would always like to
I'm working on a C-brain teaser: Write the standard Hello-World program, without semi-colons. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.