Forum Moderators: coopster

Message Too Old, No Replies

sql query problem

query that retrieves multiple rows with duplicate data

         

abushahin

3:19 pm on Nov 20, 2009 (gmt 0)

10+ Year Member



Hello, Ive got a query that returns fields from a user table and at the same time with this query other related fields from two other tables are called, the query is:
SELECT blogs.blog_Id, blog_Title, blog_Created_Datetime, entry_Text, entry_Datetime, user_Name, location
FROM blogs, users, blog_entries
WHERE blogs.user_Id = users.user_Id AND blogs.blog_Id = blog_entries.blog_Id AND user_Name = '$username';
this returns all the neccessary fields, but in this case the blog titles are being repeated each time an entry comes up for the same blog, I want to be able to retrieve all the blog entries for a blog title but not repeat the blog titles if that makes sense, thanks in advance abu

StoutFiles

4:44 am on Nov 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have to access all the rows anyway for different information, then why does it matter if you access the blog_Title variable multiple times as well?

abushahin

3:13 pm on Nov 25, 2009 (gmt 0)

10+ Year Member



hey this is returning all the blog titles by a user and the related entries, so when i echo it i want to be able to see just the blogtitle echoed once and the related entries however many there are, at the moment i may get something like this:
Blog Title: winter by abu
entry 1: blah blah blah
Blog Title: winter by abu
entry 2: blah! blah! blah!
as you can see the title is being repeated twice with the entries.
i want to be able to see something like this
Blog title: winter by abu
entry 1: blah blah blah
entry 2: blah! blah! blah!
if that makes sense, any help appreciated abu

d40sithui

4:58 pm on Nov 25, 2009 (gmt 0)

10+ Year Member



Try ::
SELECT blogs.blog_Id, blogs.blog_Title, blog_Created_Datetime, entry_Text, entry_Datetime, user_Name, location
FROM blogs, users, blog_entries
WHERE blogs.user_Id = users.user_Id AND blogs.blog_Id = blog_entries.blog_Id AND user_Name = '$username';

abushahin

5:11 pm on Nov 25, 2009 (gmt 0)

10+ Year Member



hey im sorry but i dont see any different to what im already doing, maybe im missing something that u posted, how is it any different from the query i put on only thing i can see is that u added blogs.blog_Title thats not a problem because that field is only in the blogs table anyway so no ambiguity problem. thanks abu

StoutFiles

9:10 pm on Nov 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Create an array. When you pull out the titles from the database, check to see if they're in the array.

If they aren't, insert into them into the array and echo the title.
If they are, don't echo the title.