Jump to content


Photo

table joins and implementation in php


  • Please log in to reply
1 reply to this topic

#1 kalel2

kalel2
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 08 August 2003 - 03:58 AM

I have my current query,
[php:1:361fd80a66]<?php
$query = \"SELECT id,title,newstext,\" .
\"DATE_FORMAT(postdate, \'%Y-%m-%d\') as date \" .
\"FROM news ORDER BY postdate DESC\";
?>[/php:1:361fd80a66]
but i need to also add a poster_id to the news table query and join that with a users table with an id and username. If i remember correctly i just have to add the table name and a period before the field, but how do i do it for the postdate?
Also, when I go to output the username from the users table in PHP, do i have to do $row[username], or will i have to do $row[users.username]?

any help is appreciated since i am new to table joins.

#2 DylanBlitz

DylanBlitz
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts
  • LocationOC Baby!

Posted 08 August 2003 - 03:18 PM

it would be something like this

[php:1:fcc535004c]<?php

$query = \"SELECT news.id,news.title,news.newstext,users.poster_id,users.username\" .
\"DATE_FORMAT(news.postdate, \'%Y-%m-%d\') as date \" .
\"FROM news INNER JOIN users ON news.field = users.field ORDER BY news.postdate DESC\";

?>[/php:1:fcc535004c]

replacing the \"field\" with whatever field is in both tables. The array would then be $row[username], and not $row[users.username]

Hope that helps




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users