SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function error.... mysql_fetch_array():

    Hi, I am trying to write a function to pull data from a comments table..

    here is the code for the get_num_comments (number of comments)

    PHP Code:
    function get_num_comments() {
            
    $search_string = isset($_POST['search_string']) ? check_input($_POST['search_string']) : '';

            
    $result $GLOBALS['db']->query("SELECT COUNT(p.comment_id) FROM " $GLOBALS['config']['db']['prefix'] . "gallery_comments p LEFT OUTER JOIN " $GLOBALS['config']['db']['prefix'] . "gallery_images c ON p.image_id = c.image_id WHERE p.name LIKE '%$search_string%' OR p.content LIKE '%$search_string%' OR c.category_name LIKE '%$search_string%'");

            return 
    $GLOBALS['db']->result($result0);
        } 
    I return this error when I try to view this:

    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/timminsp/new.freelance-creator.com/www/includes/db/mysql.php on line 37
    This is the code for getting the comments (get_comments)

    PHP Code:
    function get_comments($page) {
            
    $search_string = isset($_POST['search_string']) ? check_input($_POST['search_string']) : '';

            
    $result $GLOBALS['db']->query("SELECT p.*, c.image_id, p.image_id FROM " $GLOBALS['config']['db']['prefix'] . "gallery_comments p LEFT OUTER JOIN " $GLOBALS['config']['db']['prefix'] . "gallery_images c ON p.image_id = c.image_id WHERE p.name LIKE '%$search_string%' OR p.content LIKE '%$search_string%' OR c.category_name LIKE '%$search_string%' ORDER BY p.date_created DESC LIMIT " . ($page 1) * 15 ", 15");

            return 
    fetch_array($result);
        } 
    I return this error when I try to view this:

    Code:
    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/timminsp/new.freelance-creator.com/www/includes/db/mysql.php on line 88
    ----

    Here is the contents for galley_images & gallery_comments:

    Code:
    echo 'Creating ' . $config['db']['prefix'] . 'gallery_comments...<br />';
    
    $db->query("DROP TABLE IF EXISTS " . $config['db']['prefix'] . "gallery_comments");
    $db->query("CREATE TABLE " . $config['db']['prefix'] . "gallery_comments (
    	`comment_id` mediumint(6) NOT NULL auto_increment,
    	`image_id` mediumint(6) NOT NULL,
    	`user_id` mediumint(6) NOT NULL,
    	`name` text NOT NULL,
    	`comment` text NOT NULL,
    	`date_created` int(10) NOT NULL,
    	PRIMARY KEY (`comment_id`),
    	KEY `image_id` (`image_id`),
    	KEY `user_id` (`user_id`)
    ) TYPE=MyISAM ");
    
    echo 'Creating ' . $config['db']['prefix'] . 'gallery_images...<br />';
    
    $db->query("DROP TABLE IF EXISTS " . $config['db']['prefix'] . "gallery_images");
    $db->query("CREATE TABLE " . $config['db']['prefix'] . "gallery_images (
    	`image_id` mediumint(6) NOT NULL auto_increment,
    	`category_id` mediumint(6) NOT NULL,
    	`image_name` varchar(100) NOT NULL,
    	`content` text NOT NULL,
    	`description` text NOT NULL,
    	`keywords` text NOT NULL,
    	`display_order` int(10) NOT NULL default 0,
    	`image_url` varchar(64) default NULL,
    	`date_created` int(10) NOT NULL,
    	`date_edited` int(10) NOT NULL,
    	`status` tinyint(1) NOT NULL default 1,
    	`rating` int(10) NOT NULL default 0,
    	`num_votes` int(10) NOT NULL default 0,
    	PRIMARY KEY (`image_id`),
    	KEY `category_id` (`category_id`),
    	FULLTEXT (`image_name`, `content`)
    ) TYPE=MyISAM ");
    Played around for this now the past few hours - gallery_images and gallery_comments tables are both installed, and the data is there to be taken but doesn't want to be pulled .. any help or guidance would be very very much appreciated.

    Thanks,

    Paul

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    It means that your query is failing for some reason. Add an error check onto the query and see what it says.
    PHP Code:
    $result $GLOBALS['db']->query("
        SELECT 
            COUNT(p.comment_id) 
        FROM 
            " 
    $GLOBALS['config']['db']['prefix'] . "gallery_comments p 
        LEFT OUTER JOIN 
            " 
    $GLOBALS['config']['db']['prefix'] . "gallery_images c 
        ON 
            p.image_id = c.image_id 
        WHERE 
            p.name 
        LIKE 
            '%
    $search_string%' 
        OR 
            p.content 
        LIKE 
            '%
    $search_string%' 
        OR 
            c.category_name 
        LIKE 
            '%
    $search_string%'
        "
    ) or die(mysql_error()); 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're a beauty !! did that little or die, and managed to figure out what was up - thank you very much!!

    You're a top dooby dooby doo guy

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    You're welcome
    One thing I do is to try and format the queries to make them easier to read. When they are all on one line it makes it difficult to follow sometimes.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I liked the way you setup your previous post - made it whole lot easier to go through ..

    Thank you for your time and help.


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
  •