Ask a Question related to Dreamweaver AppDev, Design and Development.
-
Wyebird #1
PHP explode function and recordset
Hi
Im using the php explode function in a search page to separate some
values and then trying to place those values in to my sql query. I can
get it to work if I put the result of the function in the default value
of the record set(usually -1) but this breaks my record set so i will
have to hand code the rest of the page, (i can't do this). what i want
to do is put the results of the explode into the HTTP_POST_VARS[] so
that the record set stays intact and i can use the dream weaver
behaviors. Here's the code that works but destroys the record set
<?php
//Connection statement
require_once('../Connections/test.php');
// BEGIN EXPLODE
$search_string = $HTTP_POST_VARS['search_string'];
$search_array = explode(" ",$search_string);
$colname1__rsTest = $search_array[0];
$colname2__rsTest = $search_array[1];
$colname3__rsTest = $search_array[2];
$colname4__rsTest = $search_array[3];
$query_rsTest = sprintf("SELECT * FROM html WHERE keywords LIKE '%%%s%%'
OR keywords LIKE '%%%s%%' OR keywords LIKE '%%%s%%' OR keywords LIKE
'%%%s%%'", $colname1__rsTest, $colname2__rsTest, $colname3__rsTest,
$colname4__rsTest);
$rsTest = $test->SelectLimit($query_rsTest) or die($test->ErrorMsg());
$totalRows_rsTest = $rsTest->RecordCount();
?>
what i think it should look like but dosnt work is below
<?php
//Connection statement
require_once('../Connections/test.php');
// BEGIN EXPLODE
$search_string = $HTTP_POST_VARS['search_string'];
$search_array = explode(" ",$search_string);
// begin Recordset
$colname1__rsTest = '-1';
if (isset($HTTP_POST_VARS['$search_array[0]'])) {
$colname1__rsTest = $HTTP_POST_VARS['$search_array[0]'];
}
$colname1__rsTest = '-2';
if (isset($HTTP_POST_VARS['$search_array[1]'])) {
$colname2__rsTest = $HTTP_POST_VARS['$search_array[1]'];
}
$colname1__rsTest = '-3';
if (isset($HTTP_POST_VARS['$search_array[2]'])) {
$colname3__rsTest = $HTTP_POST_VARS['$search_array[2]'];
}
$colname1__rsTest = '-4';
if (isset($HTTP_POST_VARS['$search_array[3]'])) {
$colname4__rsTest = $HTTP_POST_VARS['$search_array[3]'];
}
$query_rsTest = sprintf("SELECT * FROM html WHERE keywords LIKE '%%%s%%'
OR keywords LIKE '%%%s%%' OR keywords LIKE '%%%s%%' OR keywords LIKE
'%%%s%%'", $colname1__rsTest, $colname2__rsTest, $colname3__rsTest,
$colname4__rsTest);
$rsTest = $test->SelectLimit($query_rsTest) or die($test->ErrorMsg());
$totalRows_rsTest = $rsTest->RecordCount();
// end Recordset
//PHP ADODB document - made with PHAkt 2.8.2?>
Thanks in advance
Gav
Wyebird Guest
-
I don't see the "New function" button in RecordSet
Hi, I've been going through the ColdFusion tutorial for creating a sample database application from... -
function in DW recordset
Hi.. DW recordset comes with all of these functions, when and how we should use them? url_parameter,form_variable,cookie,session... -
Need a little help on RecordCount recordset function
I am testing a basic function to access a db from the web and step through a set of client email addresses and send each one an email. I have a... -
note 33743 added to function.explode
If you want to use an empty separator, see the preg_split page. ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit Note ... -
note 33594 added to function.explode
xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx ---- Manual Page --... -
visuality #2
Re: PHP explode function and recordset
in your second example... if (isset($HTTP_POST_VARS['$search_array[0]'])) {
$colname1__rsTest = $HTTP_POST_VARS['$search_array[0]']; } will always come
back false because there's no $HTTP_POST_VARS['$search_array[0]'] You
exploded into $search_array, so it now contains (presumably) single words, none
of which is 'search_string' -- the only known key in the $HTTP_POST_VARS array.
$HTTP_POST_VARS is just an associative array like anything else, and you can
write to it. You could explode your search string, then append the fragments
back into $HTTP_POST_VARS.
visuality Guest
-
Wyebird #3
Re: PHP explode function and recordset
thanks visuality
But how would i append the fragments back in to the $HTTP_POST_VARS
visuality wrote:
> in your second example... if (isset($HTTP_POST_VARS['$search_array[0]'])) {
> $colname1__rsTest = $HTTP_POST_VARS['$search_array[0]']; } will always come
> back false because there's no $HTTP_POST_VARS['$search_array[0]'] You
> exploded into $search_array, so it now contains (presumably) single words, none
> of which is 'search_string' -- the only known key in the $HTTP_POST_VARS array.
> $HTTP_POST_VARS is just an associative array like anything else, and you can
> write to it. You could explode your search string, then append the fragments
> back into $HTTP_POST_VARS.
>Wyebird Guest
-
visuality #4
Re: PHP explode function and recordset
Something like this: /* explode */ $search_string =
$HTTP_POST_VARS['search_string']; $search_array = explode(' ',$search_string);
/* append into $_POST */ foreach($search_array as $key => $val) {
$$HTTP_POST_VARS[$key] = $val; } That done, you'll have a $_POST array that
contains the original search string plus numbered indexes with each word, like
this: $HTTP_POST_VARS['search_string'] => 'this is a word' $HTTP_POST_VARS[0]
=> 'this' $HTTP_POST_VARS[1] => 'is' $HTTP_POST_VARS[2] => 'a'
$HTTP_POST_VARS[3] => 'word'
visuality Guest



Reply With Quote

