Problem Finding Occurances Of One String Within Another

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Robinson

    Problem Finding Occurances Of One String Within Another

    Can anybody see what is wrong with this code? apparently i have an 'empty
    delimiter' on the line that sets $pos - can anybody see what is wrong with
    it?


    $search_for = $_GET['for'];
    $the_items_desc ription = $row ["descriptio n"];
    $pos = stristr($the_it ems_description , $search_for);

    if ($search_for == "") {
    $does_contain_t ext = true;
    } elseif ($pos === false) {
    $does_contain_t ext = false;
    } else {
    $does_contain_t ext = true;
    }

    // end text search
    if ($does_contain_ text == true) { // rest of page works fine


  • Pedro Graca

    #2
    Re: Problem Finding Occurances Of One String Within Another

    Matthew Robinson wrote:[color=blue]
    > Can anybody see what is wrong with this code? apparently i have an 'empty
    > delimiter' on the line that sets $pos - can anybody see what is wrong with
    > it?
    >
    >
    > $search_for = $_GET['for'];
    > $the_items_desc ription = $row ["descriptio n"];
    > $pos = stristr($the_it ems_description , $search_for);
    >
    > if ($search_for == "") {
    > $does_contain_t ext = true;
    > } elseif ($pos === false) {
    > $does_contain_t ext = false;
    > } else {
    > $does_contain_t ext = true;
    > }
    >
    > // end text search
    > if ($does_contain_ text == true) { // rest of page works fine[/color]

    Looks fine here.
    Do you have a mismatched quote somewhere before this code?
    I mean, before the line that sets $search_for?
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • Karen Cooke

      #3
      Re: Problem Finding Occurances Of One String Within Another

      have a look on the link below for the output



      the whole page:

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">

      <body bgcolor="#8C999 B">
      <?php
      $search_for = $_GET['for'];
      $search_categor y = $_GET['category']; global $search_for;
      global $search_categor y;
      global $the_items_desc ription;
      global $does_contain_t ext;
      ?>

      <div align=center>
      <form action="http://www.houseproudl ancs.co.uk/search.php"
      method="GET"> <br><table bgcolor="#FFF8D 7" cellpadding=6>
      <tr> <td> </td> </tr> <tr> <td> <div align=center> Search For:
      </div></td> <td> <div align=center> Category: </div></td> </td>
      </tr> <tr> <td>
      <INPUT name=for value=<?php echo ("$search_for") ; ?>>
      </td> <td>
      <SELECT NAME=category SIZE=1>
      <OPTION <?php if ($search_catego ry == "Search All
      Categories") { echo ("SELECTED") ; } ?>>Search All Categories
      <OPTION <?php if ($search_catego ry == "Floral Creations") {
      echo ("SELECTED") ; }?>>Floral Creations <OPTION <?php if
      ($search_catego ry == "Decorative Lighting") { echo
      ("SELECTED") ; }?>>Decorative Lighting <OPTION <?php if
      ($search_catego ry == "Kitchenwar e & Crockery") { echo
      ("SELECTED") ; }?>>Kitchenware & Crockery <OPTION <?php if
      ($search_catego ry == "Fancy Goods & Furniture") { echo
      ("SELECTED") ; }?>>Fancy Goods & Furniture
      </SELECT>
      </td> <td>
      <INPUT TYPE=submit VALUE="Search">
      </td>
      </form>
      <tr> <td> </td> </tr>
      </table>
      </div>


      <?php


      switch ($search_catego ry) {
      case "":
      exit;
      break;
      case "Search All Categories":
      $filter_categor y = "*" ;
      break;
      case "Floral Creations":
      $filter_categor y = "floral";
      break;
      case "Decorative Lighting":
      $filter_categor y = "lighting";
      break;
      case "Kitchenwar e & Crockery":
      $filter_categor y = "kitchenwar e";
      break;
      case "Fancy Goods & Furniture":
      $filter_categor y = "furniture" ;
      break;
      default:
      echo ("<P>Error - The Selected Category Was Not Found</P>"); break;
      }

      $dbcnx = @mysql_connect( "srv",
      "usr", "pwd"); $select =
      @mysql_select_d b("houseproudla ncs_co_uk1"); if ($filter_catego ry ==
      "*") {
      $command = "SELECT * FROM `stock` WHERE 1 ORDER BY `id`";
      } else {
      $command = "SELECT * FROM `stock` WHERE 1 AND `category` LIKE
      \"$filter_categ ory\" ORDER BY `id`";
      }
      $qresult = mysql_query($co mmand);



      echo ("text search returned true");

      $started_table = false;
      while ($row = mysql_fetch_arr ay($qresult)) {
      //text search
      $the_items_desc ription = $row ["descriptio n"];
      $pos = stristr($the_it ems_description , $search_for);

      echo ("POS = ");
      echo ("$pos");
      echo ("<br>item description = ");
      echo ("$the_items_de scription");
      echo ("<br> search for = ");
      echo ("$search_for") ;
      echo ("<br>");


      if ($search_for == "") {
      $does_contain_t ext = true;
      } elseif ($pos === false) {
      $does_contain_t ext = false;
      } else {
      $does_contain_t ext = true;
      }

      // end text search
      if ($does_contain_ text == true) {

      if ($started_table = false) {
      echo ("<center><tabl e width=80% cellpadding=5>" ); $tablebgcolor =
      "#FFF8D7"; }

      if ($tablebgcolor == "#FFF8D7"){ //yellow
      $tablebgcolor = "#C5C8FF"; //blue
      } else {
      $tablebgcolor = "#FFF8D7";
      } ?>

      <tr ><td> <table border=0 cellspacing=3 width=100% bgcolor=<?php
      echo ("$tablebgcolor "); ?>> <tr><td> <table> <tr>
      <?php
      switch ($row ["category"]) {
      case "lighting":
      $item_category = "Decorative Lighting"; break;
      case "floral";
      $item_category = "Floral Creations";
      break;
      case "kitchenwar e":
      $item_category = "Kitchenwar e & Crockery"; break;
      case "furniture" :
      $item_category = "Fancy Goods & Furniture"; break;
      default;
      $item_category = "Unknown Category";
      break;
      }
      ?>
      <td><pre>Name : </pre></td> <td><b><?php echo ($row
      ["name"]); ?> </b> </td></tr><tr> <td><pre>Descri ption:
      </pre></td> <td><?php echo ($row ["descriptio n"]); ?>
      </td></tr><tr> <td><pre>Catego ry: </pre></td> <td><?php echo
      ($item_category ); ?> </td></tr><tr> <td><pre>Pric e:
      ?</pre></td> <td><?php echo ($row ["price"]); ?>
      </td></tr><tr> <td><pre>P&P: ?</pre></td> <td><?php echo
      ($row ["pandp"]); ?> </td></tr><tr>
      <?php $quantity = $row ["quantity"];
      if ($quantity != "0") { ?>
      <td><pre>Quanti ty: </pre></td> <td><?php echo ($row
      ["quantity"]); ?> </td></tr><tr><?php } ?>
      <td><pre>Produc t ID: </pre></td> <td> <?php echo ($row
      ["id"]); ?> </td></tr><tr><td>
      <?php if ($quantity == "0") { ?>
      <td><b> <font color=#DD0000> Temporarily Out Of Stock
      </b></font></tr><tr>
      <?php } ?>
      </td></tr></table>
      </td><td width=30%>
      <?php $pictureid = $row ["id"]; ?>
      <?php $picturepath = "./images/" . $pictureid . ".jpg"; ?>
      <?php
      if (file_exists($p icturepath)) {
      echo ("<div align=\"center\ "><a href=\"$picture path\"
      target=LargeIma ge><img src=$picturepat h height=200 alt='Image
      Of Product'></a><font size=2><br>Clic k The Image To See It Full
      Size In A New Window</font></div>");
      } else {
      echo ("<div align=\"center\ "><img src=\"/images/nopic.png\"
      height=200 alt='No Picture Available'></a><font
      size=2><br>Sorr y, There Is No Available Picture For This
      Item</font></div>");
      }
      ?>
      </td></tr></table></td></tr>
      <?php } ?>
      </table></center>

      <?php } ?>

      Comment

      • Matthew Robinson

        #4
        Re: Problem Finding Occurances Of One String Within Another

        that post from karen cooke was me - thats my girlfriend and i accidently
        clicked her profile

        Comment

        • Pedro Graca

          #5
          Re: Problem Finding Occurances Of One String Within Another

          Matthew Robinson wrote:[color=blue]
          > that post from karen cooke was me - thats my girlfriend and i accidently
          > clicked her profile[/color]

          Your problem is in the stristr() call

          $search_for is "" (the URL was ....search.php? for=&category.. ..)
          and stristr() gives that warning.

          Put this before the line that sets $pos

          if ($search_for === '') $search_for = ':X:X:';
          // hopefully ":X:X:" is something that is *never* in $the_items_desc ription
          --
          --= my mail box only accepts =--
          --= Content-Type: text/plain =--
          --= Size below 10001 bytes =--

          Comment

          • Matthew Robinson

            #6
            Re: Problem Finding Occurances Of One String Within Another

            thanks again (again) pedro

            Comment

            Working...