unknown column like

Discussion in 'PHP' started by promotingspace.net, Aug 12, 2007.

  1. #1
    Hi
    The code is:
    $getbid="SELECT id FROM listing WHERE keywords LIKE `%$keyword%` ORDER BY maxb DESC LIMIT 5";
    PHP:
    and the error is:
    Unknown column '%%' in 'where clause': SELECT id FROM listing WHERE keywords LIKE `%%` ORDER BY maxb DESC LIMIT 5

    also if you have any comments about this code please let me know:
    <?php
    //collect bid data
    $content=$lrow['keywords'];
    $lines = explode(PHP_EOL, $content);
    ?>
    <table border=1 > 
      <tr>
                 <td> Keyword </td>
                <td> CPC </td>
                <td> Rank </td>
                <td> Method </td>
                <td> Bid </td>
    
                <?php 
                // keyword list goes here
                           ?>
                <td> 1st </td>
                <td> 2nd </td>
                <td> 3rd </td>
                <td> 4th </td>
                <td> 5th </td>
        </tr> <?php 
      foreach ($lines as $nrow => $keyword){
    $getbid="SELECT id FROM listing WHERE keywords LIKE `%$keyword%` ORDER BY maxb DESC LIMIT 5";
    $fivebids=mysql_query($getbid) or die(mysql_error().': '.$getbid);
    //table data inputs goes here
             ?>
        <tr>
                 <td> <?php echo  $keyword ?> </td>
                <td> <?php $get1=getcost($keyword, $id); echo $get1;  ?> </td>
                <td> <?php $get2=getrank ($keyword, $id); echo $get2; ?> </td>
                <td> Auto Bid</td>
                <td> <?php echo $maxb;  ?> </td>
         <?php       while($frow=mysql_fetch_array($fivebids)){ ?>
              
                <td> <?php echo getcost($keyword, $frow['id']) ;  ?> </td>
                     <?php 
                 }
                 
                ?>
      </tr> 
      <?php
           }
      ?>
      </table>
    <?php
    }
    PHP:

     
    promotingspace.net, Aug 12, 2007 IP
  2. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you may suggest that $keyword doesn't exist. but I tested and can confirm that $keyword exists. This is the code i used for testing
    
    <?php
    include 'global.php';
    $id=14;
    $_SESSION['id']=$id;
    $getlisting="SELECT * FROM listing WHERE id=$id";
    $resultb=mysql_query($getlisting) or die (mysql_error());
    //listing rows:
    $lrow=mysql_fetch_array($resultb);
    $maxb=$lrow['maxb'];
    $i=1;
    //collect bid data
    $content=$lrow['keywords'];
    echo $content;
    echo "done";
    $lines = explode(PHP_EOL, $content);
      foreach ($lines as $nrow => $keyword){
      echo $keyword
        ?><br><?php
      echo $i;
        $i++;
      }
    ?>
    
    PHP:
    that outputs:
    computers internet softwaredone
    1computers
    2internet
    3software
    4
    thanks in advance
     
    promotingspace.net, Aug 12, 2007 IP
  3. Webray

    Webray Active Member

    Messages:
    469
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #3
    The first thing I noticed was the back-ticks around `%$keyword%` ... should be single quotes.

    '%$keyword%'

    This seemed to indicate the problem.
    Unknown column '%%'
     
    Webray, Aug 12, 2007 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's right. Backticks are for MySQL column and table names, single quotes are for strings.
     
    TwistMyArm, Aug 13, 2007 IP