php-db | 2001071
Date: 07/09/01
- Next message: nloboek <email protected>: "[PHP-DB] Re: ereg_replace"
- Previous message: Michael Rudel: "RE: [PHP-DB] Converting an Access DAtabase to.."
- In reply to: Mark Gordon: "[PHP-DB] Dynamic SQL + result resource error"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Mark,
... beside of what was mentioned be4, you have also
a logical error in the way you append to your $sql-
query in the while loop.
Look: letz say, $find is "The Fields of the Nephilim",
so your $wordsarray would be:
0 ==> The
1 ==> Fields
2 ==> of
3 ==> the
4 ==> Nephilim
in your while-loop, you append every array-entry to
your $sql with "$word)".
So your whole SQL-Statement would read:
"SELECT bandname FROM bands WHERE (bandname LIKE The)Fields)of)the)Nephilim)"
This statement will result in error !
Try this 1:
/////////////////////////////////////////////////////////////////
//$find is text box input
$wordsarray = explode(" ",$find);
$sql = "SELECT bandname FROM bands WHERE bandname <> ''";
while ( list( $key, $word ) = each( $wordsarray ) )
{
$sql .= " OR bandname like '%".$word."%'";
}
echo $sql."<hr>";
$queryResult = mysql_query($sql);
while ( $myrow = mysql_fetch_assoc( $queryResult ) )
{
echo "<p> ".$myrow["bandname"]." </p>"."\n";
}
/////////////////////////////////////////////////////////////////
Hope this helps ;)
Greetinx,
Mike
Michael Rudel
- Web-Development, Systemadministration -
Besuchen Sie uns am 20. und 21. August 2001 auf der
online-marketing-düsseldorf in Halle 1 Stand E 16
_______________________________________________________________
Suchtreffer AG
Bleicherstraße 20
D-78467 Konstanz
Germany
fon: +49-(0)7531-89207-17
fax: +49-(0)7531-89207-13
e-mail: mailto:mru <email protected>
internet: http://www.suchtreffer.de
_______________________________________________________________
> -----Original Message-----
> From: Mark Gordon [mailto:eyesyte <email protected>]
> Sent: Monday, July 09, 2001 1:54 AM
> To: php-db <email protected>
> Subject: [PHP-DB] Dynamic SQL + result resource error
>
>
> Why is this code generating an error when it outputs a
> valid SQL statement? (there are no parse errors)
>
> //$find is text box input
> $wordsarray = explode(" ",$find);
> $sql = "SELECT bandname FROM bands WHERE (bandname
> LIKE ";
> $i = 0;
> while ($i < count($wordsarray))
> {
> $word = current($wordsarray);
> next($wordsarray);
> $sql=$sql."$word)";
> $i++;
> }
> print "$sql<hr>";
> while ($myrow=mysql_fetch_row($sql))
> {
> print "$myrow[0],<p>";
> }
>
> =====
> Mark
> eyesyte <email protected>
>
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe <email protected>
> For additional commands, e-mail: php-db-help <email protected>
> To contact the list administrators, e-mail:
> php-list-admin <email protected>
>
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe <email protected> For additional commands, e-mail: php-db-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: nloboek <email protected>: "[PHP-DB] Re: ereg_replace"
- Previous message: Michael Rudel: "RE: [PHP-DB] Converting an Access DAtabase to.."
- In reply to: Mark Gordon: "[PHP-DB] Dynamic SQL + result resource error"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

