PHP Creating a tag system for website
I'm creating a tag system for website with PHP. I created 3 tables: one for Art开发者_JS百科icles (table name:article, rows: id, title, alias), one for Tags (name:tag_content, rows:id, name, link) and one for assign tag for articles (name: tag_art, rows: id_tag, id_arty; for example: 4 articles, with different id, all with one id_tag equal 2). All scripts are done, so I can add the Articles, Tags, and assign Tags to Articles. I have also written a script for display the result-link:
$zmienna = "SELECT name, link FROM tag_content";
$result2 = mysql_query($zmienna);
echo $result2;
while($row=mysql_fetch_array($result2)){
echo "<a href='http://www.somelink.xx/tag/".$row['link']."'>".$row['name']."</a><br>";
}
And it shows all created links(tags). 1. Now i want to take not every tags but random from the database and display them (so it should be more natural). How to do it? 2. After clicking link/tag I want to display all articles with the same id_tag (assigned to one tag). How to do it?
Thx for help. If I didn't put enought information (code etc.), let me know.
the query for random
SELECT column FROM table ORDER BY RAND() LIMIT 4
you can set the limit whatever you want 2.
while($row=mysql_fetch_array($result2)){
echo "<a href='http://www.somelink.xx/tag.php?tag=".$row['link']."'>".$row['name']."</a><br>";
}
create tag.php file:
<?php
if($_GET['tag']){
$qr= sprintf("SELECT articles.id,articles.title FROM articles JOIN tag_art on articles.id=tag_art.id_arty JOIN tag_content on tag_content.id=tag_art.id_tag where tag_content.name='%s'",$_GET['tag']);
$rez= mysql_query($qr);
while($row=mysql_fetch_array($rez)){
echo $row["id"].$row["title"];
}
}
?>
?>
精彩评论