Solved

BLog tags

Posted on 2012-12-20
4
196 Views
Last Modified: 2013-01-10
Hi i am making blog script for one website and i get a problem with making tags feature.
I try to make this kind of sql query
Select date,tag as tags, author, name, full_text, keywords, description, url, blog.id from blog RIGHT JOIN tags ON tags.blog = blog.id where ".$where." date <= DATE(NOW()) and `show` = '1' limit ".$page.",".$limit."

Open in new window


But if i have 2 tag in one article it make clone article and show it twice. So if it any way to group all tags using for example ",". Or is any way to do it better.
0
Comment
Question by:umaxim
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38710521
I am not very versed in php.  However, what you want to do is keep the tags in some delimited form such as a comma and your full record will look like

date = 1/1/2000
tags = abc,123,zxy
author=mr bill

Then in your php script  you can turn the tags field to an array and break it out with explode.
http://php.net/manual/en/function.explode.php

$tags = tags;
var_dump( explode( ',', $tags ) );

result

(
    [0] => string(5) "abc"
    [1] => string(5) "123"
    [2] => string(5) "xyz"
)

This is at least what I do in vb. I hope it translates.  I am trying to learn php too.
0
 
LVL 1

Author Comment

by:umaxim
ID: 38710530
I do not need to brake it on explode. I need to join them in mysql query so when i make query it give me all my blogs and all my tags with out making number of tags copy of blog.
0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 38710644
I'm sorry, I think I see.  You want to end up with a list of unduplicated blog tags that have been used at least once.    If that is the case you can use.


Select tag as tags from blog RIGHT JOIN tags ON tags.blog = blog.id where ".$where." date <= DATE(NOW()) and `show` = '1' limit ".$page.",".$limit. GroupBy tag"

Again, I am more versed in ms but I think this translates similarly.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 38711523
You might want to consider "normalization" of the tags into a separate table.  If you're not sure you understand what "normalization" means, make a Google search for "Should I Normalize My Database" and read the very interesting design ideas -- both pro and con -- about this subject.  

Armed with that information your query may be able to use GROUP BY to limit the size of the results set.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP: Filling Out/Creating a PDF 29 107
How to use session variables in php? 22 51
PHP substring 2 13
Trying to understand why my Index is so large 12 17
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question