[ic] Re: select widget with lookup_select and sql

Aaron Berg ir.gath at gmail.com
Wed Mar 21 14:38:14 EST 2007


On 3/21/07, Aaron Berg <ir.gath at gmail.com> wrote:
> > When editing an image I'd like to have a list of rooms in a drop down
> > based on rooms related to the same listing as the image.  I've tried
> > putting a query in the extended.lookup_query box in the admin UI (it's
> > labeled 'SQL for options').  The query looks like this:
> >
> > SELECT room_id, room_name FROM listing_rooms WHERE listing_id = [cgi item_id]
>
>
> I must be on the wrong track for solving this.  Does anyone have any
> suggestions on a different direction or a better way to accomplish
> this?
>

This is now solved with some help from Mike Heins.

I had been trying to set the query using meta data and had also tried
something like:

[table-editor
	widget.room_id=select
	lookup_query.room_id="SELECT room_id, room_name
			    FROM listing_rooms
			    WHERE listing_id = [scratch listing_item_id]
				"
	no_top=1
]

This method was incorrectly escaping the query and passing it
literally to MySQL.

Mike gave me this solution:

[table-editor
	widget.room_id=select
	lookup_query.room_id=`
				$Scratch->{listing_item_id} =~ s/\D+//g;
				return qq{
			    SELECT room_id, room_name
			    FROM listing_rooms
			    WHERE listing_id = $Scratch->{listing_item_id}
				};
			`
	no_top=1
]

With the query correctly escaped it works much better. :)


More information about the interchange-users mailing list