PHP explode function and recordset

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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 ...
    5. note 33594 added to function.explode
      xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx ---- Manual Page --...
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139