mysql to php query question

Discussion in 'PHP' started by smetten, May 20, 2008.

  1. #1
    I have a database with following fields:

    jobtitle
    company
    city
    state
    country
    source
    date
    snippet
    url

    now i want to display the following results from my database:
    country=US (no problem here)
    sate=OK (no problem here)
    snippet= (must contain the word 'accounting') --> this is where i have probs.

    I have this so far, but i can´t seem to only get results which contain the word accounting in snippet.

    $query="SELECT * FROM sri_xmlphp WHERE country='US' AND state='OK' ORDER BY id DESC limit $eu, $limit ";
    PHP:
    Anyone has an idea?

    Thx in advance

    Smetten
     
    smetten, May 20, 2008 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    AND snippet LIKE '%accounting%'
     
    krakjoe, May 20, 2008 IP
  3. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #3
    thx for the help krakjoe it worked but now i'm faced with another problem.

    It displays the correct results now, but my pagination is wrong.

    i have this code for the pagination query:
    
    /////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
    $query2="SELECT * FROM `sri_xmlphp` 
    WHERE `state` = 'OK'";
    $result2=mysql_query($query2);
    echo mysql_error();
    $nume=mysql_num_rows($result2);
    echo "<center><i><font size=2>We have found ".$nume." jobs of your choice</i></font size></center><br><br>";
    
    /////// The variable nume above will store the total number of records in the table////
    PHP:
    so i want:

    state=OK - this is ok already

    and
    snippet=(must contain the word 'accounting') -->what should i add to the code above for this to work?

    Greetz

    Smetten
     
    smetten, May 20, 2008 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    
    if( ( $result = mysql_query( "SELECT * FROM sri_xmlphp WHERE state = 'OK' AND snippet LIKE '%accounting%'" ) ) ) 
    {
    	if( ( $nume = mysql_num_rows( $result ) ) )
    	{
    		printf( "<center><i><font size=2>We have found no %d jobs terms</i></font size></center><br><br>", $nume );
    		/** execution continues from here **/
    	}
    	else echo "<center><i><font size=2>We have found no jobs matching terms</i></font size></center><br><br>";
    }
    else printf( "<center><i><font size=2 style=\"color:red;\">%s</i></font size></center><br><br>", mysql_error( ) );
    
    PHP:
     
    krakjoe, May 20, 2008 IP
  5. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #5
    worked again,

    thx for the help krakjoe

    Greetz

    smetten
     
    smetten, May 20, 2008 IP