Need help on how to retrieve the respective value of array from another table
Need help on how to retrieve the respective value of array from another table
am 13.08.2007 08:19:15 von Andz
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!!!
Re: Need help on how to retrieve the respective value of array from another table
am 13.08.2007 12:32:52 von petersprc
You could select:
if (count($splitContent)) {
$set = join(',', $splitContent);
$cats = $mdb2->queryAll("select * from
categories_table where catid in ($set)");
}
> foreach ($splitContent as $result) {
> echo $result;
> }
On Aug 13, 2:19 am, Andz wrote:
> 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!!!
Re: Need help on how to retrieve the respective value of array from another table
am 14.08.2007 06:36:30 von contactfast
On Aug 13, 3:32 pm, petersprc wrote:
> You could select:
>
> if (count($splitContent)) {
> $set = join(',', $splitContent);
> $cats = $mdb2->queryAll("select * from
> categories_table where catid in ($set)");
>
> }
> > foreach ($splitContent as $result) {
> > echo $result;
> > }
>
> On Aug 13, 2:19 am, Andz wrote:
>
> > 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!!!
try this
select * from categories_table where catid in (select * from
implode_table where email = user_email)";
this will give you cat_id and name of cat_id in the user mail selected
cats_id .., this would work fine , in case just chk the cats_id come
correct in IN () might (',')
try it ...take care
Re: Need help on how to retrieve the respective value of array fromanother table
am 14.08.2007 18:41:20 von Toby A Inkster
Andz wrote:
> implode_table {
> email catid
>
> test@local 1,2,3
> help@local 2,3
>
> }
Google for "first normal form".
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 54 days, 20:20.]
Fake Steve is Dead; Long Live Fake Bob!
http://tobyinkster.co.uk/blog/2007/08/13/fake-bob/