Jump to content

[SOLVED] Need help on how to retrieve the respective value of array from another table???


andz

Recommended Posts

I'm using explode() to extract and make an array() readable. I'm able

to make the array() from dbase readable.

 

categories_table {

        catid  name

 

        1      'test1'

        2      'test2'

        3      'test3'

 

}

 

implode_table {

        email          catid

 

        test@local      1,2,3

        help@local      2,3

 

}

 

For example, if test@local logged in to the system, how can test@local

load all the information of the catid he selected?

 

My code for the moment fetch only all the catid that's being saved

under test@local account.

 

foreach (getImplodeCategoriesByEmail($email) as $explodeCat) {

        $delimiter = ",";

        $content = $explodeCat['catid'];

        $splitContent = explode($delimiter, $content);

 

        foreach ($splitContent as $result) {

                echo $result;

        }

 

}

 

Assume that getImplodeCategoriesByEmail($email) is fetching all the

records that match the email. This piece of code worked.

It gives me a result of 123.

 

THE PROBLEM: HOW CAN I LOAD ALL THE INFORMATION OF THE EXTRACTED

CATID???

 

The output should be like this

 

        1      test1

        2      test2

        3      test3

 

What query AND how to implement it? If possible, please include

code.... THANKS and MORE POWER!!!

Link to comment
Share on other sites

As long as you don't want to add another table (it would be more efficient)

you can use

  $catids = getImplodeCategoriesByEmail($email);
  if (!empty($catids)) {
    $query = "select catid, name from categories where catid in (".$catids.")";
    // select catid, name from categories where catid in (1,2,3)
  }

Link to comment
Share on other sites

Yes.

  if (!empty($catids)) {
    $query = "select catid, name from categories where catid in (".$catids.")";
    // select catid, name from categories where catid in (1,2,3)
    $res = mysql_query($query);
    while($row = mysql_fetch_assoc($res)) 
      $ar_cate[] = $row['catid'].' '.$row['name'];
  }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.