Re: [PHP] Decide witch table within a union



On Sun, October 29, 2006 3:34 pm, Børge Holen wrote:
Hi.
I got this working (almost)
How do I decide (inside?) the whileloop the table_nr, 1 to 4 witch the
link is
echo'ed from.

I could add another field in each table telling witch table it is.
Easy
solution, but feels like polluting the db.

Also I could do another loop to check another of the printed fields up
agains
witch table is used, but that adding to the slowness of this union
stuff, it
would take forever, if the union in itself is slow or the fact that
I'm
cutting the message field after 100 characters I dunno.

This is anyway the main code wherein the problem lies:

$sql=" (select * from table_1 WHERE pid='0' order by id desc limit 10)

select *, 'table_1' from table_1 ...

union
(select * from table_2 WHERE pid='0' order by id desc limit 10)

select *, 'table_2' from table_2 ...

This gives you an extra field with the table name in it.

You may not be able to use * any more, and have to name all the fields
you actually want.

Which is a better practice anyway.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
.



Relevant Pages

  • Re: [PHP] Decide witch table within a union
    ... PHP can't tell what table the data came from. ... How do I decide the whileloop the table_nr, 1 to 4 witch the link is ... I could add another field in each table telling witch table it is. ... witch table is used, but that adding to the slowness of this union stuff, it ...
    (php.general)
  • Re: [PHP] Decide witch table within a union
    ... How do I decide the whileloop the table_nr, ... I could add another field in each table telling witch table it is. ... but that adding to the slowness of this union ... This is anyway the main code wherein the problem lies: ...
    (php.general)
  • Re: [PHP] Decide witch table within a union
    ... On Sunday 29 October 2006 22:59, Ed Lazor wrote: ... I could add another field in each table telling witch table it is. ... but that adding to the slowness of this union ... Kennel Arivene ...
    (php.general)
  • Decide witch table within a union
    ... I could add another field in each table telling witch table it is. ... but feels like polluting the db. ... witch table is used, but that adding to the slowness of this union stuff, it ... This is anyway the main code wherein the problem lies: ...
    (php.general)