CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 more than one word to search

Print topic Send  topic

Author Message
martin
Posted: 10/03/2005, 8:55 PM

I tried this: http://forums.codecharge.com/posts.php?post_id=57524

but I need only the results that contained all the words I use, not those that contin "any" of the words Im searching for. So I replaced the "like" for "=" but it doesnt worked.
Martin K.
Posted: 10/04/2005, 12:02 AM

Hello.
Make an AND for any OR in the funktion and the result will show you only the Text where all searchwords include.

greets martin k.
martin
Posted: 10/04/2005, 9:24 PM

what about this part of the code:

##############################################
function My_MoreWhere_ds_BeforeBuildSelect() {
global $YOUR_FORM_NAME;

if ($YOUR_FORM_NAME->ds->Where <> "") {
$YOUR_FORM_NAME->ds->Where .= " AND ";
}

$YOUR_FORM_NAME->ds->Where .= CCGetMultiWord(CCGetFromGet("s_name", ""));

}
############################################


it only ask for "s_name", I use 2 fields (s_title, s_body), I tried this:

$booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_title", ""));
CCGetMultiWord(CCGetFromGet("s_body", ""));

but I receive this error:


Warning: Division by zero
Warning: Cannot modify header information - headers already sent
Martin K.
Posted: 10/05/2005, 2:51 AM

Hello.
If you have more than 1 url search Names (s_title, s_body) you must Add it Like this:


if(strlen(CCGetFromGet("s_title", "")))
$booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_title", ""));

if(strlen(CCGetFromGet("s_body", ""))) {
$booksresume->ds->Where .= " AND ";
$booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_body", ""));
}

I hope you understand me.

greets martin k.
Jeremy Spouken
Posted: 10/05/2005, 3:02 PM

Remember to use the ToSql Method to prevent SQL Injections. 8-)

Use you code and run this search "Jeremy's Code"
martin
Posted: 10/06/2005, 12:53 AM

What's about the function My_MoreWhere_ds_BeforeBuildSelect, it calls only one url parameter, I change it to this, but I still receive the "division by zero" error:

function My_MoreWhere_ds_BeforeBuildSelect() {
global $booksresume;

if ($booksresume->ds->Where <> "") {
$booksresume->ds->Where .= " AND ";
}


Im lost.....!
$booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_title", ""));
$booksresume->ds->Where .= " AND ";
$booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_body", ""));

}
martin
Posted: 10/18/2005, 12:10 AM

I've really tried to fix this by my self, but I couldnt.
If I write a value in the "title" field, it search only in the body filed, and if I write in the body search field, it sends this error:

Database error: Invalid SQL: SELECT COUNT(*) FROM (booksresume INNER JOIN section ON section.idsection = booksresume.section) INNER JOIN autor ON booksresume.autor = autor.idautor WHERE booksresume.section = '1' AND (booksresume.dateborrow >= '2005-10-14' AND booksresume.dateborrow <= '2005-10-17') AND body like '%american%' body like '%science%' AND body like '%american%' body like '%science%'
MySQL Error: 1064 (You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'body like '%science%' AND body like '%american%' body )
Session halted.



this is my complete code:

//booksresume_ds_BeforeBuildSelect
function booksresume_ds_BeforeBuildSelect()
{
$booksresume_ds_BeforeBuildSelect = true;
//End booksresume_ds_BeforeBuildSelect

//Custom Code @244-13992A6D
// -------------------------
global $booksresume;
// Write your own code here.
if(strlen(CCGetFromGet("s_title", "")))
My_MoreWhere_ds_BeforeBuildSelect();



if(strlen(CCGetFromGet("s_body", "")))
My_MoreWhere_ds_BeforeBuildSelect();
//}
// -------------------------
//End Custom Code

//Close booksresume_ds_BeforeBuildSelect
return $booksresume_ds_BeforeBuildSelect;
}
//End Close booksresume_ds_BeforeBuildSelect


##########################################
function CCGetMultiWord($value)
{
$Result = " ";
if(strlen($value) > 0) {
$string_to_split = $value;
$tok = split(" ", $string_to_split);
$size = sizeof($tok);
for ($i = 0; $i< $size; $i++)
{
if (($i == 0) && ($i == $size-1))
$Result = " s_title like '%".$tok[$i]."%'";
elseif ($i == 0)
$Result = " s_title like '%".$tok[$i]."%'";
elseif ($i == $size-1)
$Result .= " AND s_title like '%".$tok[$i]."%')";
else
$Result .= " AND s_title like '%".$tok[$i]."%'";
}
// Second Field + AND or OR
$Result .= " and ";
// Second Field to search Where begin

for ($i = 0; $i< $size; $i++)
{
if (($i == 0) && ($i == $size-1))
$Result = " s_body like '%".$tok[$i]."%'";
elseif ($i == 0)
$Result = " s_body like '%".$tok[$i]."%'";
elseif ($i == $size-1)
$Result .= " AND s_body like '%".$tok[$i]."%')";
else
$Result .= " AND s_body like '%".$tok[$i]."%'";
}
}
return $Result;
}
##################################################
##############################################
function My_MoreWhere_ds_BeforeBuildSelect() {
global $booksresume;

if ($booksresume->ds->Where <> "") {

$booksresume->ds->Where .= " AND ";
}

$booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_title", ""));
//$booksresume->ds->Where .= " AND "


$booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_body", ""));

}
############################################



thanks in advance...
Damian Hupfeld
Posted: 10/18/2005, 5:28 AM

maybe you need to have another AND or OR between the search terms?



"martin" <martin@forum.codecharge> wrote in message
news:543549ff586c61@news.codecharge.com...
> I've really tried to fix this by my self, but I couldnt.
> If I write a value in the "title" field, it search only in the body filed,
> and
> if I write in the body search field, it sends this error:
>
> Database error: Invalid SQL: SELECT COUNT(*) FROM (booksresume INNER JOIN
> section ON section.idsection = booksresume.section) INNER JOIN autor ON
> booksresume.autor = autor.idautor WHERE booksresume.section = '1' AND
> (booksresume.dateborrow >= '2005-10-14' AND booksresume.dateborrow <=
> '2005-10-17') AND body like '%american%' body like '%science%' AND body
> like
> '%american%' body like '%science%'
> MySQL Error: 1064 (You have an error in your SQL syntax. Check the manual
> that
> corresponds to your MySQL server version for the right syntax to use near
> 'body
> like '%science%' AND body like '%american%' body )
> Session halted.
>
>
>
> this is my complete code:
>
> //booksresume_ds_BeforeBuildSelect
> function booksresume_ds_BeforeBuildSelect()
> {
> $booksresume_ds_BeforeBuildSelect = true;
> //End booksresume_ds_BeforeBuildSelect
>
> //Custom Code @244-13992A6D
> // -------------------------
> global $booksresume;
> // Write your own code here.
> if(strlen(CCGetFromGet("s_title", "")))
> My_MoreWhere_ds_BeforeBuildSelect();
>
>
>
> if(strlen(CCGetFromGet("s_body", "")))
> My_MoreWhere_ds_BeforeBuildSelect();
> //}
> // -------------------------
> //End Custom Code
>
> //Close booksresume_ds_BeforeBuildSelect
> return $booksresume_ds_BeforeBuildSelect;
> }
> //End Close booksresume_ds_BeforeBuildSelect
>
>
> ##########################################
> function CCGetMultiWord($value)
> {
> $Result = " ";
> if(strlen($value) > 0) {
> $string_to_split = $value;
> $tok = split(" ", $string_to_split);
> $size = sizeof($tok);
> for ($i = 0; $i< $size; $i++)
> {
> if (($i == 0) && ($i == $size-1))
> $Result = " s_title like '%".$tok[$i]."%'";
> elseif ($i == 0)
> $Result = " s_title like '%".$tok[$i]."%'";
> elseif ($i == $size-1)
> $Result .= " AND s_title like '%".$tok[$i]."%')";
> else
> $Result .= " AND s_title like '%".$tok[$i]."%'";
> }
> // Second Field + AND or OR
> $Result .= " and ";
> // Second Field to search Where begin
>
> for ($i = 0; $i< $size; $i++)
> {
> if (($i == 0) && ($i == $size-1))
> $Result = " s_body like '%".$tok[$i]."%'";
> elseif ($i == 0)
> $Result = " s_body like '%".$tok[$i]."%'";
> elseif ($i == $size-1)
> $Result .= " AND s_body like '%".$tok[$i]."%')";
> else
> $Result .= " AND s_body like '%".$tok[$i]."%'";
> }
> }
> return $Result;
> }
> ##################################################
> ##############################################
> function My_MoreWhere_ds_BeforeBuildSelect() {
> global $booksresume;
>
> if ($booksresume->ds->Where <> "") {
>
> $booksresume->ds->Where .= " AND ";
> }
>
> $booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_title", ""));
> //$booksresume->ds->Where .= " AND "
>
>
> $booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_body", ""));
>
> }
> ############################################
>
>
>
> thanks in advance...
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

Walter Kempees
Posted: 10/18/2005, 5:33 AM

Quote :
AND body like '%american%' body like '%science%' AND body like
'%american%' body like '%science%'


Because it looks like a duplicated line and it is missing an AND or OR.

(Hi D.)


"Damian Hupfeld" <damian.hupfeld@itng.com.au> schreef in bericht
news:dj2pos$di3$1@news.codecharge.com...
> maybe you need to have another AND or OR between the search terms?
>
>
>
> "martin" <martin@forum.codecharge> wrote in message
>news:543549ff586c61@news.codecharge.com...
>> I've really tried to fix this by my self, but I couldnt.
>> If I write a value in the "title" field, it search only in the body
>> filed, and
>> if I write in the body search field, it sends this error:
>>
>> Database error: Invalid SQL: SELECT COUNT(*) FROM (booksresume INNER JOIN
>> section ON section.idsection = booksresume.section) INNER JOIN autor ON
>> booksresume.autor = autor.idautor WHERE booksresume.section = '1' AND
>> (booksresume.dateborrow >= '2005-10-14' AND booksresume.dateborrow <=
>> '2005-10-17') AND body like '%american%' body like '%science%' AND body
>> like
>> '%american%' body like '%science%'
>> MySQL Error: 1064 (You have an error in your SQL syntax. Check the manual
>> that
>> corresponds to your MySQL server version for the right syntax to use near
>> 'body
>> like '%science%' AND body like '%american%' body )
>> Session halted.
>>
>>
>>
>> this is my complete code:
>>
>> //booksresume_ds_BeforeBuildSelect
>> function booksresume_ds_BeforeBuildSelect()
>> {
>> $booksresume_ds_BeforeBuildSelect = true;
>> //End booksresume_ds_BeforeBuildSelect
>>
>> //Custom Code @244-13992A6D
>> // -------------------------
>> global $booksresume;
>> // Write your own code here.
>> if(strlen(CCGetFromGet("s_title", "")))
>> My_MoreWhere_ds_BeforeBuildSelect();
>>
>>
>>
>> if(strlen(CCGetFromGet("s_body", "")))
>> My_MoreWhere_ds_BeforeBuildSelect();
>> //}
>> // -------------------------
>> //End Custom Code
>>
>> //Close booksresume_ds_BeforeBuildSelect
>> return $booksresume_ds_BeforeBuildSelect;
>> }
>> //End Close booksresume_ds_BeforeBuildSelect
>>
>>
>> ##########################################
>> function CCGetMultiWord($value)
>> {
>> $Result = " ";
>> if(strlen($value) > 0) {
>> $string_to_split = $value;
>> $tok = split(" ", $string_to_split);
>> $size = sizeof($tok);
>> for ($i = 0; $i< $size; $i++)
>> {
>> if (($i == 0) && ($i == $size-1))
>> $Result = " s_title like '%".$tok[$i]."%'";
>> elseif ($i == 0)
>> $Result = " s_title like '%".$tok[$i]."%'";
>> elseif ($i == $size-1)
>> $Result .= " AND s_title like '%".$tok[$i]."%')";
>> else
>> $Result .= " AND s_title like '%".$tok[$i]."%'";
>> }
>> // Second Field + AND or OR
>> $Result .= " and ";
>> // Second Field to search Where begin
>>
>> for ($i = 0; $i< $size; $i++)
>> {
>> if (($i == 0) && ($i == $size-1))
>> $Result = " s_body like '%".$tok[$i]."%'";
>> elseif ($i == 0)
>> $Result = " s_body like '%".$tok[$i]."%'";
>> elseif ($i == $size-1)
>> $Result .= " AND s_body like '%".$tok[$i]."%')";
>> else
>> $Result .= " AND s_body like '%".$tok[$i]."%'";
>> }
>> }
>> return $Result;
>> }
>> ##################################################
>> ##############################################
>> function My_MoreWhere_ds_BeforeBuildSelect() {
>> global $booksresume;
>>
>> if ($booksresume->ds->Where <> "") {
>>
>> $booksresume->ds->Where .= " AND ";
>> }
>>
>> $booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_title", ""));
>> //$booksresume->ds->Where .= " AND "
>>
>>
>> $booksresume->ds->Where .= CCGetMultiWord(CCGetFromGet("s_body", ""));
>>
>> }
>> ############################################
>>
>>
>>
>> thanks in advance...
>> ---------------------------------------
>> Sent from YesSoftware forum
>> http://forums.codecharge.com/
>>
>
>


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.