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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:14:00+00:00 2026-05-23T19:14:00+00:00

This is for adding images, categories and comments from an email to a photo

  • 0

This is for adding images, categories and comments from an email to a photo gallery I’m working on.

I’m pulling the first two found category names out of an email message body and need to assign the category id to $cat variable for insertion into DB.

I have it working fine hardcoded, but would like to make it dynamic so changes to category names will cascade throughout.

The switch statement I’d like to change:

Hardcoded:

foreach($foundKeywords as $key => $value) {  
            if($key<=1){

switch($value)
        {
            case 'family':
            $cat='3';
            break;
            case 'friends';
            $cat='4';
            break;
            case 'fun';
            $cat='6';
            break;
            case 'places';
            $cat='5';
            break;
            case 'general';
            $cat='2';
            break;
            case 'henry';
            $cat='7';
            break;
            default;
            $cat='2';
        }

I’d like to pull the categories from a MySQL table and do it this way:

$res = mysql_query('SELECT * FROM gallery_category');
            $cat_switch_list = "";
            while($row = mysql_fetch_array($res)){
                $cat_switch_list .= "case '".$row[1]."':
                                    $cat = ".$row[0].";
                                    break;";
            }
            //////////////////////
            foreach($foundKeywords as $key => $value) {  
                if($key<=1){


                    switch($value)
                    {
                        echo $cat_switch_list;
                        default:
                        $cat='1';
                    }

In theory, I believe this should work, but something is not right.

Any suggestions?

  • 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-23T19:14:00+00:00Added an answer on May 23, 2026 at 7:14 pm

    You’d be better of to either use mysql directly for querying:

    mysql_query('select id from gallery_category where name=\''.mysql_real_escape($name).'\'');
    

    or by generating an array from your result:

    $result = mysql_query('select * from gallery_category');
    $categories = array();
    while($row = mysql_fetch_num($result))
    {
      $categories[$row[1]] = $row[0];
    }
    

    Then you can find the correct id simply be looking it up in your categories array: $id = $categories[$name].

    If you want to generate code and it looks like it, you can use var_export() to save the $categories variable to real php code. Do you want to generate code?

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

Sidebar

Related Questions

I'm working with the jQuery Sortable plugin to drag and drop images from one
Here is my code. This is adding image but images are being appeared in
I have a WinForms empty panel, and I'm adding images dynamically to this panel.
I am reading this tutorial : http://sleekd.com/general/adding-multiple-images-to-a-rails-model-with-paperclip/ because i need Save the product images
I am adding some images to a div from a database in the Page_Load()
I had asked this question Adding more attributes to LINQ to SQL entity Now,
I am putting a label on a UIToolbar (per this tip: Adding a UILabel
I'm having a memory problem related to UIImageView. After adding this view to my
I have a root view controller with no nib file, I tried adding this
I am getting this error after adding the libxml2.2.dylib file Linking /Users/Biranchi/Desktop/Funmovies TabBarController/build/Debug-iphonesimulator/funmovies.app/funmovies (1

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.