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

  • Home
  • SEARCH
  • 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 7750989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:26:01+00:00 2026-06-01T11:26:01+00:00

I am fairly new to PHP and Codeigniter so im sure this will be

  • 0

I am fairly new to PHP and Codeigniter so im sure this will be simple.

I have contact details stored in this format where type is either (1,2,3,4) mapping to (facebook, mobile, bbm, msn, twitter):

ID | USERID | TYPE | VALUE
1  |    8   |  2   | 076773635

I have set up a model to access these contact details, there may be none, or at best one of each type;

function getContactDetails($userid) {
    $query = $this->db->query("SELECT * FROM who_user_contact_info WHERE userid=".$userid);

    foreach ($query->result() as $row)
    {
        switch ($row->type) {
            case 1:
                $contact['facebook'] = $row->value;  
            case 2:
                $contact['mobile'] = $row->value; 
            case 3:
                $contact['bbm'] = $row->value; 
            case 4:
                $contact['msn'] = $row->value;  
            case 5:
                $contact['twitter'] = $row->value; 
        }

    }


    return $contact;
}

My controller then passed this data to my view;

<h3>Contact Info</h2>
<?php   
    echo "Facebook: ". $facebook ."<br />";
    echo "mobile:".  $mobile ." <br />";
    echo "bbm:".  $bbm ." <br />";
    echo "msn:".  $msn ." <br />";
    echo "Twitter:".  $twitter ." <br />";
?>

This seems to nearly work, but there must be a mistake, as for example say type 3 and 5 didn’t exist, mobile and twitter shouldn’t have been assigned anything! yet on my output it gives the value from the one before, eg bbm=mobile and twitter=msn.

How is it possible for these array to be there when the case has not set them? or is my logic wrong?

  • 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-06-01T11:26:03+00:00Added an answer on June 1, 2026 at 11:26 am

    Don’t you need to put a break under each case?

    case 1:
    $contact['facebook'] = $row->value;  
    break;
    

    etc

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

Sidebar

Related Questions

This might be a simple question, but I'm fairly new to PHP and am
I have plenty of experience with this in PHP, but am fairly new to
I'm fairly new to PHP so am not sure how to do this. I
I'm fairly new to PHP and have been trying to make a simple login
I am fairly new to PHP, but have applied my previous knowledge of programming,
I'm fairly new to HTML, PHP, CSS and Javascript. I do have a bit
I am fairly new to SQL, so not sure if this is just a
I am fairly new to php and have not figured out how I would
I'm fairly new to PHP so I have a small problem as I'm learning:
Notes: I'm still fairly new to php This login form seems to work perfectly

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.