SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Location
    USA
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm new to mySQL, so I need some help retrieiving the stored data in the table.

    Ok I've got 5 columns: id, url, title, and descrip.

    How can I retrieve the information for the columns from each row?

    So that it does something like this:
    Code:
    while (there are still some rows to get information from){
    echo ("<a href='$url[0]'>$title[0]</a><br><small>$descrip[0]</small><br><br>");
    }
    I found out that getting information from mySQL dbs is harder the sending information to mySQL dbs. In my opinion, anyways.

    Thanks for the help.

    Suggestions for different methods and flames are welcome!
    Living the OO way.
    Hardware Help | Desperados!

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That's 4 columns, by the way.

    Everything you need is explained in my article here. Meanwhile, here's your code:

    Code:
    $result = mysql_query("SELECT * FROM tableName") or die("Error: " . mysql_error());
    while ($row = mysql_fetch_array($result)) {
      $url = $row["url"];
      $title = $row["title"];
      $descrip = $row["descrip"];
      echo ("<a href='$url'>$title</a><br><small>$descrip</small><br><br>");
    }
    [EDIT: fixed a small bug]
    <Edited by kyank on 12-15-2000 at 11:19 PM>
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Location
    USA
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh wow that's easy
    Thanks

    I tried that article, but I was sortof confused about what he ment at some parts. But now it's all clear. Thanks
    Living the OO way.
    Hardware Help | Desperados!

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    He is me. If you have any lingering questions, ask away!
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Location
    USA
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Warning: Supplied argument is not a valid MySQL result resource in /home2/webdev/public_html/links.php on line 32


    Hmmm
    PHP isn't liking :

    Code:
    while ($row = mysql_fetch_array($resultSet)) {
      $id = $row["id"];
      $url = $row["url"];
      $title = $row["title"];
      $descrip = $row["descrip"];
      echo ("<a href='$url'>$title</a><br><small>$descrip<small><font color=gray>$id</font></small</small><br><br>");
    }

    My guess is the resultSet.. But then again I've never really used arrays much before..
    Living the OO way.
    Hardware Help | Desperados!

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Where is the code creating that $resultSet? It's the source of your problem. See my example above for the correct method.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  7. #7
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    We resolved this via email. Turns out the culprit was a typo in my code above, which I have since corrected.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •