logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-28-2012, 12:27 AM   #1
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default joins

I am having trouble accessing an array element when I add a join,

The below works fine:

$article = mysql_query("SELECT article_id, user_id, content, DATE_FORMAT(date, '%d %b %y')
AS date
FROM article
ORDER BY date
DESC");

while($row = mysql_fetch_array($article)){

echo "<p>" . $row['date'];
echo "<br/>";

$wstring = explode("\n", wordwrap($row['content'], 100, "\n") );
echo $wstring[0];
echo "<a href=\"fullarticle.php?id=" . $row['article_id'] . "\"> Read full acticle...</a>";

}

$row['date'] shows the date the article was added
$row['article_id'] shows the content of the post

When I add a join e.g.

$article = mysql_query("SELECT article.article_id, article.user_id, article.content, DATE_FORMAT(article.date, '%d %b %y'), user.user_id, user.username
AS date
FROM article
LEFT JOIN user
ON user.user_id = article.user_id
ORDER BY date
DESC");

while($row = mysql_fetch_array($article)){

echo "<p>" . $row['date'];
echo "<br/>";

$wstring = explode("\n", wordwrap($row['content'], 100, "\n") );
echo $wstring[0];
echo "<a href=\"fullarticle.php?id=" . $row['article_id'] . "\"> Read full acticle...</a>";

}

$row['date'] displays the username.

why does this happen?
tony09uk is offline   Reply With Quote
Old 04-28-2012, 02:34 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,176
Default

user.user_id, user.username
AS date
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 04-28-2012, 08:14 PM   #3
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

so by using AS date is the last item in the list used? I thought that command would create an array, that would allow me to access whichever element I wanted?
tony09uk is offline   Reply With Quote
Old 04-28-2012, 10:51 PM   #4
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

thanks for your advice ed, ive sorted it now. using the numeric arrays (if that's what they are called :s)
tony09uk is offline   Reply With Quote
Old 04-28-2012, 11:11 PM   #5
tony09uk
 
Join Date: Oct 2010
Posts: 340
Angry

Can you please advise me on this next issue too?

I have two pages, page one:

$months = mysql_query("SELECT DISTINCT(MONTHNAME(date)) as post_month
FROM article
LIMIT 12");

while($row = mysql_fetch_array($months)){
echo "<a href=\"montharticles.php?id=" . $row['0'] . "\">" . $row['0'] . "</a><br/>";
}

page two (montharticles):

$article = mysql_query("SELECT article_id, content, DATE_FORMAT(date, '%d %b %y')
FROM article
WHERE article_id = $_GET[date]");


while($row = mysql_fetch_array($article)){
echo $row . "</br>";
}

My aim is to display all articles on the montharticles page from the selected month on page one. I realise that $_GET[date] is incorrect but i cant work how to do it, I have tried a few ways now without any luck.

Hope im not to far off the mark
tony09uk is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:31 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com