Re: getting rows from separate tables stacked in a single array ? (newbie, mysql)

From: Date: Wed, 25 Apr 2001 03:38:52 +0000
Subject: Re: getting rows from separate tables stacked in a single array ? (newbie, mysql)
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-50226@lists.php.net to get a copy of this message
Doh, I shoulda thought of that, a temp table is the best way to do it. Altho, I don't see why you have a spot_id as a key for that table. Your are probably never going to access that table via that arbitrary number. If anything, you should make item_id the key. The id on your other tables should also be keys. SL. ----- Original Message ----- From: "Nicolas Mermet" <himself@nicolas-mermet.com> To: <php-general@lists.php.net> Sent: Tuesday, April 24, 2001 8:50 PM Subject: Re: [PHP] getting rows from separate tables stacked in a single array ? (newbie, mysql) > > Thanks a bunch, SL. I was expecting some heavy manipulation of that sort. > Wouldnt have been able to write that code. (yet ! ;-). I will try that > tomorow. > > This afternoon In despair I ended tweaking the db and creating an extra > table to link all the desired tables with a time indice, temporarily > solving my problem but promising future headaches when I devellop the db > admin page. Here is how I dit it: > > > > table "all_items" > item_id (id of the items in their original tables) > date_posted (original item post date) > table_name (where the item comes from) > spot_id (key to the project) > > > It works with this code: > > > > > //connecting to the link table to get time-ordered list of relevant items, > their origin and their keys > > $sql4="select DATE_FORMAT(date_posted, '%a %m/%d/%y at %l:%i %p.'), > item_id, item_table from spot_items where spot_id = \"$spot_id\" order by > date_posted desc"; > $result4=MySQL_query($sql4); > while($spotitems=MySQL_fetch_array($result4)) > { > list($items_date_posted, $items_id, $items_table) = $spotitems ; > > //linking to the real tables to get the real item info > > > $sql5="select * from $items_table where item_id = \"$items_id\""; > $result5=MySQL_query($sql5); > while($items=MySQL_fetch_array($result5)) > { > $items_title = $items["title"]; > $items_description = $items["description"]; > $items_duration = $items["duration"]; > } > > //outputing in fonction of the item origin > > if ($items_table == "movie") > echo "$items_title (Quicktime, duration: $items_duration) > $items_date_posted<br>$items_description<br"; > > if ($items_table == "storyboard") > echo "$items_id\ $items_title (Storyboard) $items_date_posted<br> > $items_description<br>"; > > if ($items_table == "picture") > echo "$items_title(Picture) $items_date_posted <br>$items_description<br>"; > > > } > > > > > > > > > > > > > > > > > thanks again, > Nicolas. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#50226) next »