Jump to content

Hi need a bit of help!


takn25

Recommended Posts

Hi I bought a script to search mysql database and its working great. The thing I am after is I have a row called Now in my database. Now can either be 0 or 1  what I want the script to do is search something like && WHERE now='1'

the problem I am facing is the script is not well commented and the query part is kinda confusing could some one take a look and tell me what and where can I make the changes for the desired result thanks a bunch!

 

// table fields to search

  $arrayFields = array(0 => $first_field, 1 => $second_field, 2 => $third_field, 3 => $fourth_field );

  $countSearch = count($arraySearch);

  $a = 0;

  $b = 0;

  $query = "SELECT * FROM $table_name WHERE (";

  $countFields = count($arrayFields);

  while ($a < $countFields)

  {

    while ($b < $countSearch)

    {

      $query = $query."$arrayFields[$a] LIKE '%$arraySearch[$b]%'";

      $b++;

      if ($b < $countSearch)

      {

        $query = $query." AND ";

      }

    }

    $b = 0;

    $a++;

    if ($a < $countFields)

    {

      $query = $query.") OR (";

    }

  }

  $query = $query.") LIMIT $offset, $records_number;";

  $search = mysql_query($query);

 

 

// get number of search results

  $arrayFields = array(0 => $first_field, 1 => $second_field, 2 => $third_field, 3 => $fourth_field );

  $countSearch = count($arraySearch);

  $a = 0;

  $b = 0;

  $query = "SELECT * FROM $table_name WHERE (";

  $countFields = count($arrayFields);

  while ($a < $countFields)

  {

    while ($b < $countSearch)

    {

      $query = $query."$arrayFields[$a] LIKE '%$arraySearch[$b]%'";

      $b++;

      if ($b < $countSearch)

      {

        $query = $query." AND ";

      }

    }

    $b = 0;

    $a++;

    if ($a < $countFields)

    {

      $query = $query.") OR (";

    }

  }

  $query = $query.")";

  $count_results = mysql_query($query);

  $numrows = mysql_num_rows($count_results);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.