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!!!

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)
  }

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'];
  }

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.