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
https://forums.phpfreaks.com/topic/229347-hi-need-a-bit-of-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.