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)
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($result, 0);
}
I return this error when I try to view this:
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)
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:
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:
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