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 6350221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:46:14+00:00 2026-05-24T21:46:14+00:00

There is a table contains columns like username,settings1,settings2,settings3 username is a unique and settings1,2,3

  • 0

There is a table contains columns like

username,settings1,settings2,settings3

username is a unique and settings1,2,3 is contain 0 or 1 values.

$query = $this->db->query("SELECT * FROM tbl_users WHERE username = 'test'");
$queryrow = $query->row();

so i want to select the row that matching to username and loop through columns and check which column contain 0’s and 1’s

i can do this by writing a if statement for every column though, like

if($queryrow->settings1=="1"){
..
}

there is like 7 columns in table so instead of writing 7 if statements, any other way to do this? im using codeigniter 2.0.2

Regards

  • 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-24T21:46:15+00:00Added an answer on May 24, 2026 at 9:46 pm

    You can iterate objects

    // use active record to work less and be safer
    $this->db->where('username', 'test');
    $query = $this->db->get('tbl_users');
    
    foreach ($query->result() as $row)
    {
        // iterate the row object
        foreach($row as $key => $item)
        {
            if($row->$key == "1")
            {
                // your code
            }
        }
    }
    

    If all you need to do in this loop is checking those values, you should do a SELECT to have only those items in $row, and avoid having “username”

    $this->db->select('setting1, setting2, setting3');
    

    Otherwise, if you want to keep username, the IF statement could be rather

    if(in_array($key, array('setting1', 'setting2', 'setting3')) && $row->$key == "1")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The table contains 4 columns: id (autoincrement), userid (unique, like ssn), status (TINYINT(1), 0
So I have a SQL table that contains time-clock information like this. The number
I'm trying to perform a CONTAINS query with multiple terms over multiple columns, like
I have a table that contains id, created, user_id. I'm wondering if there is
Consider i have a registartion table and there is field prefLocationId and it contains
Is there any way to make sure that a table and cells it contains
There are some section in the table that does not contain any data and
I have two columns from a table; fromid and toid , which contain the
I have a user table in my database which contains two columns FirstName and
I have a log table that contains job status. One of the columns is

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.