SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Quake 1 Addict CreedFeed's Avatar
    Join Date
    Feb 2002
    Location
    Milwaukee, WI
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem With SQL Query & PHP

    I'm trying to run the following code:
    PHP Code:
    178. $query "SELECT news_id, headline, summary, image, custom_linkname, " 
    179. "custom_linkurl, date_added, news_stories.cat_id, category, " 
    180. "DATE_FORMAT(date_added, 'Posted on %m/%d/%Y at %h:%i %p') AS " 
    181. "post_date FROM news_stories, news_images, news_categories " 
    182. "WHERE news_stories.img_id=news_images.img_id AND " 
    183. "news_stories.cat_id=news_categories.cat_id AND " 
    184. "MATCH(headline, story) AGAINST ('$term') ORDER BY " 
    185. "date_added DESC LIMIT $limit, "STORIES_PER_PAGE;
    186. $res mysql_query($query); 
    187. $num mysql_num_rows($res); 
    188. $i 0
    189. echo "<H5>$query</h5>";
    190. while ($news mysql_fetch_array($res)) {
    ...
    ... 
    I've set up a FULLTEXT index on headline,story. I keep getting PHP errors:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/*/public_html/inc/news_funcs.php on line 187

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/*/public_html/inc/news_funcs.php on line 190

    Yet, when I copy/paste the query (I output it on the screen in the code above) to phpMyAdmin and run it, it works just fine. What could the problem be? I'm at a loss right now...

    By the way, here's the query that gets printed on the screen that works right in phpMyAdmin:

    PHP Code:
    SELECT news_idheadlinesummaryimagecustom_linknamecustom_linkurldate_addednews_stories.cat_idcategoryDATE_FORMAT(date_added'Posted on %m/%d/%Y at %h:%i %p') AS post_date FROM news_storiesnews_imagesnews_categories WHERE news_stories.img_id=news_images.img_id AND news_stories.cat_id=news_categories.cat_id AND MATCH(headlinestoryAGAINST ('stapp'ORDER BY date_added DESC LIMIT 010 
    -- Steve Caponetto
    Quake 1 Resurrection :: CreedFeed

  2. #2
    Employed Again Viflux's Avatar
    Join Date
    May 2003
    Location
    London, On.
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Output the mysql_error() after you run your query to see what the problem is.

  3. #3
    Quake 1 Addict CreedFeed's Avatar
    Join Date
    Feb 2002
    Location
    Milwaukee, WI
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doh, I forgot about that. Here's the error:

    Can't find FULLTEXT index matching the column list

    I have set the FULLTEXT index though. The query I used to set it is here:

    PHP Code:
    ALTER TABLE news_stories ADD FULLTEXT (headline,story); 
    And the query works when I run it in phpMyAdmin?
    -- Steve Caponetto
    Quake 1 Resurrection :: CreedFeed

  4. #4
    Quake 1 Addict CreedFeed's Avatar
    Join Date
    Feb 2002
    Location
    Milwaukee, WI
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I'm an idiot. heh... I set the FULLTEXT index on a different database (my "test" db and not my "real" db). I think I need to get some more sleep...
    -- Steve Caponetto
    Quake 1 Resurrection :: CreedFeed


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
  •