Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post

    SQL like statements

    I'm getting the following error:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/richard/labs/blog.php on line 28

    I has something to do with my sql statements
    PHP Code:
     $id $_GET['id'];
             
    $tag $_GET['tag'];
             if(empty(
    $id) && empty($tag)){
                 
    $sql 'SELECT `b_id`,`title`,`body`,`author`,`tags`, UNIX_TIMESTAMP(`date`) as blogdate FROM `blog`';
             }
             elseif(!empty(
    $tag)){
                 
    $sql "SELECT `b_id`,`title`,`body`,`author`,`tags`, UNIX_TIMESTAMP(`date`) as blogdate FROM blog WHERE tags LIKE '% $tag %'";
             }
             else{
                 
    $sql "SELECT `b_id`,`title`,`body`,`author`,`tags`, UNIX_TIMESTAMP(`date`) as blogdate FROM `blog` WHERE id='$id' ORDER BY blogdate DESC";
             }    
             
    $results mysql_query($sql);
             while(
    $rows mysql_fetch_array($results)){
                 
    $title $rows['title'];
                
    $body $rows['body'];
                
    $author $rows['author'];
                
    $b_date date("M d Y",$rows['blogdate']);
                
    $tags explode(" ",$rows['tags']);
                echo 
    '<div class="blog">';
                echo 
    '<h1>'.$title.' <span class="blogDate">'.$b_date.'</span></h1>';
                echo 
    '<p>'.$body.'</p>';
                echo 
    '<div id="author">'.$author.'</div> filed under: ';
                foreach(
    $tags as $tag){ 
                    echo 
    '<a href="?tag='.$tag.'">'.$tag.'</a>, '
                }
                echo 
    '</div>';
             } 

  • #2
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    You should add some error checking to find out why your query is not being executed.
    PHP Code:
    $results mysql_query($sql) or die(mysql_error() . "SQL statement: " $sql); 
    You have an if statement with conditions, under which condition is it not being executed?

    Also, I think your wildcards need to be on your tag variable %$tag% unless you're looking for 'anything here, space, variable value, space, anything here'.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •