[ic] SQL query returning no results
ic at 3edge.com
ic at 3edge.com
Fri Oct 27 08:59:21 EDT 2006
graham hadgraft writes:
> I am trying to perform a query that takes the string from a series of
> checkboxes and returns rowes which have a field which contains all
> these strings in any order.
>
> This is the code i am using:
>
> [perl tables="products"]
> @array = split(/-/,$CGI->{from});
> my $res = '';
> $sql = "SELECT * FROM products WHERE icons LIKE '%'";
>
> foreach(@array){
> $sql .= " AND icons LIKE '%" . $_ . "%'";
> }
>
> $Tag->query({sql=>$sql,hashref=>'results',table=>'products'});
>
> foreach my $row (@{$Tmp->{results}})
> {
> $res .= $row->{description} . "test<br>";
> }
> return $res;
> [/perl]
>
>
> This returns no string. I have changed the return to return the sql
> string and then ran the same sql query in directsql and this returns
> the correct products. Changing it back to return res brings back no
> string.
>
> This does not make any sense to me.
Kevin gave the solution to change:
@array = split(/-/,$CGI->{from});
in
@array = split(/\0/,$CGI->{from});
What confuses me in this is that above you say that you have returned the
sql string from this perl block and with that you got a correct query.
Perhaps Kevin can shed a light on that one aswell? I'd think that you would
not be able to have done a split with the - , so there would not have been a
correct sql query in the first place? Or is there something magic going on?
CU,
Gert
More information about the interchange-users
mailing list