Announcement

Collapse
No announcement yet.

PHP Questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    but there is nothing wrong with that line....

    Comment


    • #17
      Oh yes there is! The percent signs aren't a part of the PHP language, they're part of the out dated MySQL LIKE clause. it is now more appropriate to use something like

      Code:
      SELECT epTitle, epReview, epRating, epImage1 FROM episodes WHERE strcmp(epTitle, \"$searchword\")   > -1

      Comment


      • #18
        I beg to differ. I just forgot the LIKE in the select statement, I use it all the time in my code and it works beautifully.

        but that would not have caused the parse error. doing what you have there will cause the search to be more precise and have the potential to not return anything. and doing it that way is case sensitive and most searches need to be case insensitive. besides we use the % in VB all the time when we query the access database, no different than mysql.

        ahh I did goof. it should be like this.

        $result = mysql_query("SELECT epTitle, epReview, epRating, epImage1 FROM episodes WHERE epTitle LIKE '%$searchword%' "); // get the everything field from the_table (the name of the table) that = the search word

        that will work garrunteed

        Comment


        • #19
          Originally posted by scoutt
          I beg to differ. I just forgot the LIKE in the select statement, I use it all the time in my code and it works beautifully.

          but that would not have caused the parse error. doing what you have there will cause the search to be more precise and have the potential to not return anything. and doing it that way is case sensitive and most searches need to be case insensitive. besides we use the % in VB all the time when we query the access database, no different than mysql.

          ahh I did goof. it should be like this.

          $result = mysql_query("SELECT epTitle, epReview, epRating, epImage1 FROM episodes WHERE epTitle LIKE '%$searchword%' "); // get the everything field from the_table (the name of the table) that = the search word

          that will work garrunteed
          I never said it didn't exist in MySQL, I know that the LIKE clause exists...but I don't think that works with newer versions, i thought i saw it somewhere in the manual.

          In your original code, you had the % signs outside the mysql expression, inside the PHP code, and that caused the parse error...not just because you forgot the LIKE clause

          This isn't a competition though

          Comment


          • #20
            that is correct, it shouldn't have had the ". ." as that was the error. but I jsut forgot the like so it wouldn't work anyway.

            this is in the mysql manual

            SQL pattern matching allows you to use `_' to match any single character and `%' to match an arbitrary number of characters (including zero characters). In MySQL, SQL patterns are case insensitive by default. Some examples are shown below. Note that you do not use = or != when you use SQL patterns; use the LIKE or NOT LIKE comparison operators instead.

            To find names beginning with `b':

            mysql> SELECT * FROM pet WHERE name LIKE "b%";
            Last edited by scoutt; Sat 8 Jun '02, 8:52am.

            Comment


            • #21
              The error has gone, though now we have another in line 16, which is

              PHP Code:
              <td width="26%"><u><font face="Verdana" size="2"><b>$row["epTitle"]</b></font></u></td
              The actual error reads:

              Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\apache\htdocs\searchresults.php on line 14

              I'm maybe off track (don't know much about PHP), but is is that $row hasn't been properly defined?

              From the previous code, certain variables had to be clearly defined, and as I read the code below, it seems like $row is referenced to, but not set up before this?

              PHP Code:
              while ($row mysql_fetch_array($result)) { 
              As I said, that was the firest ref, which seems to say "So long as there is info from the query to feed into $row, pass the info to the table below and fill it in" or something like that.
              Last edited by MartynJ; Sat 8 Jun '02, 4:40am.

              Comment


              • #22
                my appologies, I wasn't sure in the heredoc syntax would except the " in the varialbe. try this

                PHP Code:
                <td width="26%"><u><font face="Verdana" size="2"><b>$row['epTitle']</b></font></u></td
                you will have to change all of them that are like that in between the myhtml syntax.

                Comment


                • #23
                  Still the same problem. Just thinking. The database connection part, where you define database name etc to $db - the user is specified as root, but I did not include pass as you do in something like vB config.php file. I have attached the php file here as it exists at the moment, and if I can, I will attach the sql too.

                  Comment


                  • #24
                    Nah, needed a double post to also attach the sql, it's in this zip file. For ease of construction, I made it in phpMyAdmin. (in case that means anything to anyone) - oh, and thanks for your help so far guys, I really do appreciate it. A lot. Once I get going with PHP/MySQL myself I will be certain to help those with less knowledge myself...

                    Comment


                    • #25
                      well all though it works I don't like it, but try this.
                      PHP Code:
                      <?
                      if($_REQUEST["submit"]){
                      // make sure search word doesn't contain special characters
                      $searchword htmlspecialchars($_REQUEST['searchword']);
                      ?>
                      <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="65%" id="AutoNumber1">
                      <?
                      $db 
                      mysql_connect("localhost","root");
                      mysql_db_select("sg1",$db);
                      $result mysql_query("SELECT epTitle, epReview, epRating, epImage1 FROM episodes WHERE epTitle LIKE '%$searchword%' "); // get the everything field from the_table (the name of the table) that = the search word 
                      while ($row mysql_fetch_array($result)) {
                      echo <<<myhtml
                       <tr>
                          <td width="26%"><u><font face="Verdana" size="2"><b>
                      $row[epTitle]</b></font></u></td>
                          <td width="174%">&nbsp;</td>
                        </tr>
                        <tr>
                          <td width="26%"><font face="Verdana" size="1">
                      $row[epRating]</font></td>
                          <td width="174%">
                          <font size="1"><img src="
                      $row[epImage1]">    </font></td>
                        </tr>
                        <tr>
                          <td width="26%">&nbsp;</td>
                          <td width="174%"><font size="1">
                      $row[epReview]</font></td>
                        </tr>
                        <tr>
                          <td width="26%">&nbsp;</td>
                          <td width="174%">&nbsp;</td>
                        </tr>
                        <tr>
                          <td width="26%"><font size="1">Result1</font></td>
                          <td width="174%"><a href="review.php&id=
                      $row[id]"><font size="1">eplongreview.php&$id=</font></a></td>
                        </tr>
                      myhtml;
                      }

                      echo
                      "</table>";
                      }
                      ?>

                      Comment


                      • #26
                        Yay! No more errors, but, now nothing at all. It just goes to a blank page. Even if I put in the *exact* phrase I know to exist in the table.

                        Comment


                        • #27
                          do you have a form on the same page? what is the whole page? can you upload it here

                          Comment


                          • #28
                            here this works. you had some problems with table names.

                            PHP Code:
                            <?
                            echo "<html><head></head><body>";
                            if(
                            $_REQUEST["submit"]){
                            // make sure search word doesn't contain special characters
                            $searchword htmlspecialchars($_REQUEST['searchword']);

                            echo
                            "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"65%\" id=\"AutoNumber1\">";

                            $db mysql_connect("localhost","root","*****");
                            mysql_select_db("DB_name");
                            $search = ("SELECT epName, epShortReview, epRating, epImage1 FROM episodes WHERE epName LIKE '%$searchword%' "); // get the everything field from the_table (the name of the table) that = the search word
                            $result mysql_query($search);
                            if (!
                            $result){echo mysql_error();}
                            $num mysql_num_rows($result);
                            if (
                            $num){
                            while (
                            $row mysql_fetch_array($result)) {
                            echo <<<myhtml
                             <tr>
                                <td width="26%"><u><font face="Verdana" size="2"><b>
                            $row[epName]</b></font></u></td>
                                <td width="174%">&nbsp;</td>
                              </tr>
                              <tr>
                                <td width="26%"><font face="Verdana" size="1">
                            $row[epRating]</font></td>
                                <td width="174%">
                                <img src="
                            $row[epImage1]"></td>
                              </tr>
                              <tr>
                                <td width="26%">&nbsp;</td>
                                <td width="174%"><font size="1">
                            $row[epShortReview]</font></td>
                              </tr>
                              <tr>
                                <td width="26%">&nbsp;</td>
                                <td width="174%">&nbsp;</td>
                              </tr>
                              <tr>
                                <td width="26%"><font size="1">Result1</font></td>
                                <td width="174%"><a href="review.php&id=
                            $row[id]"><font size="1">eplongreview.php&$id=</font></a></td>
                              </tr>
                            myhtml;
                            }
                            }else{
                            echo 
                            "<tr><td>Sorry no results found";
                            }
                            echo
                            "</table>";
                            }
                            ?>
                            <form action="searchresults.php" method="POST">
                            <input type=text name="searchword">
                            <input type="submit" name="submit" value="submit">
                            </form>
                            </body>
                            </html>

                            Comment


                            • #29
                              The approach I was looking for was something like:

                              http://hostname/seach.htm

                              which posts data to

                              http://hostname/searchresults.php

                              This kinda weird, cause it's always "neaarly there". The searchresults.php should be exaclty as the demo at

                              http://www.somethingreal.net/test - reading results etc

                              Comment


                              • #30
                                that is fine, just make the form on the other page. I just had it there for testing purposes. it doesn't have to be there.
                                Last edited by scoutt; Sat 8 Jun '02, 3:31pm.

                                Comment

                                widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                                Working...
                                X