#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Simple SQL Query


    Hello This is my first post in a forum, over the past few months I have been teaching myself PHP and MySQL/ MYPHP.

    Anywho, I have been building a database for my office and I have gotten to the point where I need to build a search engine. Everything works when I replace the variable with static text but that doesn't help me.

    I know its a simple fix but I can't figure it out.

    The $allfields is my issue.

    Code:
    $query = "SELECT * FROM `Projects` WHERE `1` LIKE"'.$allfields.'"LIMIT 0, 30 ";
    Below is a larger snip-it if you need it.


    Code:
    //Query 
    $query = "SELECT * FROM `Projects` WHERE `1` LIKE"'.$allfields.'"LIMIT 0, 30 "; 
    
    
     $numresults  = mysql_query($query);
     $numrows     =	mysql_num_rows($numresults);
    
    
    
      if (empty($s)) {
     					 $s=0;
      				 }
    
    
      $result = mysql_query($query) or die("Couldn't execute query");
    
    
    print "<p>You searched for: &quot;" .$_GET['allfields']. "&quot;</p>";
    
    
    echo "Results";
    $count = 1 + $s ;
    
    
    {	
    					while($info= mysql_fetch_array($result)) 
    						{ 
    							 print "<tr>";
    							 print "<table border=2>";
    							 
    							 
    							  
    							 print "<th>State:</th> <td width=200px font-size= 24px>".$info['0'] . "</td></tr>";
     
    							 print "<th>County:</th> <td width=200px font-size= 24px>".$info['1'] . "</td> "; 
    							 print "<th>City:</th> <td width=200px>".$info['2']. " </td>"; 
    							 print "<th>Owner:</th> <td width=250px>".$info['3'] . "</td></tr>";
    							  
    							 print "<th>Title4:</th> <td>".$info['4'] . " </td>";
    							 print "<th>Value:</th> <td>".$info['5'] . "</td> "; 
    							 print "<th>Title6:</th> <td>".$info['6'] . " </td></tr>";
    							 
    							 print "<th>Title1:</th> <td>".$info['7'] . "</td> "; 
    							 print "<th>Title2:</th> <td>".$info['8'] . " </td></tr>";
    							  
    							 print "<th>Title3:</th> <td>".$info['9'] . "</td> "; 
    							 print "<th>Title4:</th> <td>".$info['10'] . " </td></tr>";
    							 
    							 print "<th>Title5:</th> <td>".$info['11'] . "</td> ";
    							 print "<th>Title6:</th> <td>".$info['12'] . " </td></tr>";
    							 print "<th><br /><br /></th>";
    							 print " ";
    							 print " ";
    							 
    					 
    						} 
    					 print "</table>"; 
      
      
    
      echo "$count.)&nbsp;$title" ;
      $count++ ;
      }
    Thanks very much!
  2. #2
  3. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,055
    Rep Power
    487
    Originally Posted by b1ack1323
    The $allfields is my issue.

    Code:
    $query = "SELECT * FROM `Projects` WHERE `1` LIKE"'.$allfields.'"LIMIT 0, 30 ";
    Try

    Code:
    $query = "SELECT * FROM `Projects` WHERE `1` LIKE '%{$allfields}%' LIMIT 0, 30 ";
    instead
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0
    Thank You that worked like a charm.

IMN logo majestic logo threadwatch logo seochat tools logo