in reply to Re: Joining Tables Problem
in thread Joining Tables Problem
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Joining Tables Problem
by chromatic (Archbishop) on Feb 17, 2003 at 20:43 UTC | |
That's how joins work. You can solve this in two different ways. First, select only the items. Run a query for each item to fetch the available colors. The other option is to continue with your single query, making sure the results are returned and sorted on the item id. Push the available colors onto an array for each item id -- you'll end up with a hash of arrays of colors. I'd go for the second solution. | [reply] |
|
Re^3: Joining Tables Problem
by LAI (Hermit) on Feb 17, 2003 at 20:49 UTC | |
Yes, you're outputting a new line for every line of the return from the Database query. What you probably want to do is one of two things: Whichever of these two you use, you can then pass $ref->{'color'} to CGI like:
Note that I haven't used CGI's drawing functions much, so double-check the syntax of popup_menu() before testing this out. Update: changed stuff to the american (mis)spelling of colour.
LAI
| [reply] [d/l] [select] |
by b310 (Scribe) on Feb 21, 2003 at 21:26 UTC | |
I'm trying on my own to figure out the array bit. I have no idea if I'm on the right track. I modified my query section in the shop_parameters subroutine which I included in my original node. Can you look at this code and tell me if I'm on the right track? Here's the code...
Thanks. | [reply] [d/l] |
by LAI (Hermit) on Feb 21, 2003 at 22:55 UTC | |
I see what you're trying to do (++ for effort!), but that's not quite it. See my previous response (to your previous response :o) for more details.
LAI
| [reply] |
by b310 (Scribe) on Feb 22, 2003 at 12:04 UTC | |
by b310 (Scribe) on Feb 22, 2003 at 19:04 UTC | |
by b310 (Scribe) on Feb 21, 2003 at 19:03 UTC | |
I could use your help in putting your ideas into actual code since I haven't had a need to write an array yet. Any chance you can help me out? Thanks. | [reply] |
by LAI (Hermit) on Feb 21, 2003 at 22:52 UTC | |
Okay, a brief lesson on references: you can do anything to the array pointed at by a reference that you could do to the array itself. So, the following two snippets do exactly the same thing (one to an array, the other to a referenced array):
So as you can see, using an arrayref is just an indirect way of using an array, with the added benefit that the reference can be passed around like a scalar, and put into arrays and hashes, and all sorts of fun stuff like that. So, back to your problem. You wind up with $ref (which happens to be a reference to a hash). You're already pulling out values like $ref->{item_id} and $ref->{description}, so now you need to make $ref->{color} an arrayref and iterate over it. Here's the part of your code that takes the record set and turns it into a table. The HTML looks kinda b0rked... Please forgive me if I screw it up more.
For more information on references and how to use them (from people who know a whole lot more than me) See:
LAI
| [reply] [d/l] [select] |
|
Re: Re: Re: Joining Tables Problem
by Tomte (Priest) on Feb 17, 2003 at 20:32 UTC | |
chromatic and LAI already explained what you're doing and what the possibilities are. So this is basically a useless node :(
regards, | [reply] |