SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Another Question

    Hey all,

    I have a database and I am trying to select a bit of info out of it using this:

    <?php

    $db = @mysql_connect('localhost') or die ("Failed to connect to database!");
    @mysql_select_db('brian', $db) or die ("Failed to connect to database!");

    $text = mysql_query('SELECT text FROM website WHERE id=1') or die ("Invalid entry!");

    echo ($text);

    ?>
    When I do this is the mysql prompt thingy It works and I can view the information but when I run the php page all it says is:

    Resource id #3
    and not what it is supposed to say which is: Welcome to my website

    Any ideas what could be wrong?
    Thanks for any help,
    Matt

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use the mysql_result() function. Instead of $text = mysql_query('SELECT text FROM website WHERE id=1') or die ("Invalid entry!" ); use:

    $text = mysql_result(mysql_query('SELECT text FROM website WHERE id=1') or die ("Invalid entry!" ),0);

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    Thanks for the help,
    When I do that I get this error:

    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in d:\inetpub\wwwroot\Brian Ryan\index.php on line 40
    Any ideas?
    Matt

  4. #4
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hmmmm....

    $text = mysql_result(mysql_query("select text from website where ID=1"),0);


    That code works on my machine. What line exactely is line 40?

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is line 40:

    $text = mysql_query('SELECT text FROM website WHERE id=1') or die ("Invalid entry!");

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but with the mysql_result command

  7. #7
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I got it, it turns out I must do this:

    $result = mysql_query('SELECT text FROM website WHERE id=1') or die ("Invalid entry!");

    $text = mysql_fetch_row($result);

    echo ($text[0]);
    Cheers

  8. #8
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    umm... i don't know why you getting that error. it works fine on my computer. let me see the whole code how you have it written.

  9. #9
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have it working but here is the code:
    $text = mysql_result(mysql_query('SELECT text FROM website WHERE id=1') or die ("Invalid entry!" ),0);

    echo($text);


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
  •