SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cant get my head round it...

    basically im trying to grab data from two tables.

    im trying to get the article from this table:

    news

    id | cat | article | title | date

    and an image associated with that category from author table using cat.

    author

    id | cat | name | title | email | imge

    ive heard of LEFT JOIN but im not sure how id include it in this query:

    <?
    $result = mysql_query("SELECT LEFT(article,200) AS shorttext FROM news");
    while($r=mysql_fetch_array($result))
    {
    $img=$r["img"]; //image from author table
    $shorttext = substr($r['shorttext'],0,strrpos($r['shorttext']," "));
    echo "<TR><TD><img src\"$img\"></TD><TD CLASS=\"nav\">$shorttext</TD></TR>";
    }
    ?>

    the code for article strips an article to 200 words but doesnt cut off the last whole word.

    any ideas?
    http://redgoals.com ... my site ... nuff said

  2. #2
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT news.article, author.imge
    FROM news
    LEFT JOIN author ON author.id = news.id


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
  •