SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot Selatos's Avatar
    Join Date
    Aug 2002
    Location
    USA
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP ME!!!! MySQL query trouble

    I am working on a site about cooking. The point of the site is to share recipes and tips about cooking, and to meet other people interested in cooking.

    On the main page I am trying to call mysql_fetch_array, but I always get the following error:
    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\kitchen\index.php on line 98
    Here is the code I use:
    PHP Code:
    $sql2 "SELECT `ID`,`news`,`posted`,'newsdate' FROM `news` WHERE 1 LIMIT 0, 30"
    $news_fetch mysql_query($sql2);
    while (
    $news mysql_fetch_array($news_fetch) ) {
        echo (
    $news['content']);

    What did I do wrong?

  2. #2
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: HELP ME!!!! MySQL query trouble

    Originally posted by Selatos

    What did I do wrong?
    Pretty much everything...

    There shouldn't be quotes around your column names in the sql query. What on earth is "WHERE 1" for? Where is $news['content'] coming from?

    PHP Code:
    $sql2 "SELECT ID, news, posted, newsdate FROM news LIMIT 30" 
    $news_fetch mysql_query$sql2 ) ;
    while( 
    $news mysql_fetch_assoc$news_fetch ) ) {
        echo( 
    $news['ID'] ) ;
        echo( 
    $news['news'] ) ;
        echo( 
    $news['posted'] ) ;
        echo( 
    $news['newsdate'] ) ;


  3. #3
    SitePoint Member
    Join Date
    Jan 2002
    Location
    Sri Lanka
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What about Conecting ?

    Okay. But dont you have to establish a connection to MySql First



    PHP Code:

    $dbcnx 
    mysql_connect('LocalHost''username''Password');

    $sql2 "SELECT ID, news, posted, newsdate FROM news LIMIT 30" ;  
    $news_fetch mysql_query$sql2 ) ; 
    while( 
    $news mysql_fetch_assoc$news_fetch ) ) { 
        echo( 
    $news['ID'] ) ; 
        echo( 
    $news['news'] ) ; 
        echo( 
    $news['posted'] ) ; 
        echo( 
    $news['newsdate'] ) ; 


  4. #4
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: What about Conecting ?

    Originally posted by ArjunaK
    Okay. But dont you have to establish a connection to MySql First
    I'd taken that as read, although you never know...

    But anyone who's not got that far should at least read a few articles before diving in feet first.

  5. #5
    SitePoint Zealot Selatos's Avatar
    Join Date
    Aug 2002
    Location
    USA
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I already had a function defined that connects and I call the function at the top. I figured out what I did wrong, and it was not only the quotes(generated by PHPMyAdmin) but also some mistyping, I accidentally named a column something slighty different from my code.

    Thanks for the help guys, when I post the site somewhere, I'm having a little touble finishing, I'll tell you first

    EDIT:
    I dont usually mess up PHP, and I'm pretty far along, but I do have a tendecy to screw something up when I use MySQL.

    Is it 'ok' for me to use () with echo?
    ex.
    PHP Code:
    echo ("Hello World\n"); 
    Some people tell me not to do it, but it works fine. Should I break the habbit?

  6. #6
    SitePoint Enthusiast ericthehalfbee's Avatar
    Join Date
    Oct 2001
    Location
    Auckland, NZ
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you shouldn't use ()s I'd like to know too 'cos I always use them.

  7. #7
    SitePoint Zealot Selatos's Avatar
    Join Date
    Aug 2002
    Location
    USA
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then I need to introduce you to my friend, who says that noone but me uses () with echo.

    For me, it makes sense because I did some C before PHP, and printf (""); was normal, and it just followed me.

    Besides, every function is called with parameters, so I dont think we should be dropping the () with echo, it is a function too


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
  •