SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: function error

  1. #1
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function error

    Hi all, I am getting an error when trying to execute this function:

    PHP Code:
    function list_newest_blog_posts($x) {
        
    $Query "SELECT user_id, title FROM blogs_content WHERE publish = '1' ORDER BY id DESC LIMIT '$x'";
        
    $Result mysql_query($Query)or print("Could not select newest blog posts: " mysql_error());
        while(
    $Row mysql_fetch_array($Result)) {
            
    $user userid_to_username($Row['user_id']);
            
    $title stripslashes($Row['title']);
            echo
                
    '
            <a href="/blog/'
    .$user.'">'.$title.'</a> <br />
                '
    ;
        }

    PHP Code:
    Could not select newest blog postsYou have an error in your SQL syntaxCheck the manual that corresponds to your MySQL server version for the right syntax to use near ''5'' at line 1
    Warning
    mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/blongle/public_html/functions.php on line 259 
    Can anyone see my problem? I know the table name / column names are correct. Thanks!
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $Query = "SELECT user_id, title FROM blogs_content WHERE publish = '1' ORDER BY id DESC LIMIT '$x'";

    no quotes around '$x' only $x

    AND when you do
    mysql_query() or print(mysql_error());
    then
    EITHER use die()
    OR
    PHP Code:
    $result mysql_query() or print(mysql_error());
    if(
    $result)
    {
    //DO your WHILE OR WHATEVER HERE
    }
    else
    {
       
    //DO ANY THING ELSE

    becasue if your query has an error then, not only would query not execute BUT also when you try to use that $result in other function they would compain too.
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!

    I usually use die(), but for this one I was thinking that if that query didn't work, it is not critical to the site so might as well continue on with the rest of the site. Though, now that I really think about it it is a better idea to use die(). Thanks again!
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches


Bookmarks

Posting Permissions

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