PDA

View Full Version : Creating tag cloud from scratch for blog


dellis87
04-13-2010, 03:15 PM
Hi,

I'm trying to make a tag cloud for a blog I'm creating from scratch. I'm a little confused with how to go about it though. Here's my thought process so far:


Have an input field where tags can be entered and separated by a comma by the author: "computers, plants, desk".

Use an explode command to transform all tags into an array $tags[]

Insert the array into a mysql table where each piece of the array is inserted into a different row, all with a unique id number (primary key)

take the blog entry and insert it into a separate table (php_blog), use mysql_id to get it's id.

*this is where I'm getting lost* :: somehow, take the id's from all the rows that were added to the database from the tag array (need to get the ids from all these new rows) and, in a new table, put each one on the same row with the id from the entry that was added.


So, for example: computer, plant, desk are added into the category table with each it's own id & row computer (id = 1), plant (id = 2), desk (id = 3). The entry that was also added goes into the php_blog table with an id of 1. On my joining table (entrycategory) I want to set 1 = 1, 1 = 2, 1 = 3 where the first column is my entry id & my second column is the tag/category id.

I hope this makes sense, and sorry for driving anybody crazy. I am basically trying to augment Kevin Yank's build a database driven website but for a blog.

I'd appreciate any help! Thanks.

dellis87
04-15-2010, 05:01 PM
It seems I'm being ignored.

I guess I'm just asking if this seems like a good workflow and I'm wondering how to add an array into a MySQL database after I use explode to take an input and turn it into an array.

Corrosive
04-15-2010, 05:39 PM
Not being ignored I wouldn't think. I guess no one who knows the answer has seen your post yet. I'm sure a PHP expert will be along at some stage.

dellis87
04-16-2010, 03:09 AM
Okay, actually I figured out the previous problem, but now I'm running into a new one:

I need to select an id for multiple rows from a table. Then use those ids that were just selected, and select values from a different table.

Here's what I've got so far:

$sql = "SELECT categoryid FROM entrycategory WHERE entryid = '$id'";
$result = mysqli_query($link, $sql);
if (!$result)
{
$error = 'Error fetching list of selected categories.';
include 'error.html.php';
exit();
}

while ($row = mysqli_fetch_array($result, MYSQLI_NUM))
{
$tagid_array[] = array($row[0]);
if (!mysqli_query($link, $sql))
{
$error = 'Error selecting tags.';
include 'error.html.php';
exit();
}
}
$tagid_array_imploded = implode(',', $tagid_array);
$sql_GetTags = "SELECT name FROM category WHERE id IN ($tagid_array_imploded)";
$result = mysqli_query($link, $sql);
if (!$result)
{
$error = 'Error fetching list of selected categories.';
include 'error.html.php';
exit();
}
while ($row = mysqli_fetch_array($result, MYSQLI_NUM))
{
$tag_array[] = array($row[0]);
if (!mysqli_query($link, $sql))
{
$error = 'Error selecting tag cloud.';
include 'error.html.php';
exit();
}
}
$tags = implode(', ', $tag_array);
echo $tags;

So, The only problem is, the echo $tags displays "Array, Array, Array, Array, Array".

I think it might be that I'm setting the $result array incorrectly $tagid_array[] = array($row[0]);

Any ideas? Any help would be appreciated, I've been working on this for a while!

davidj
04-20-2010, 11:17 AM
You cant echo an array

You need to do a foreach loop and iterate through them assigning each to its own variable

Without digging deeper into your requirements i couldn't really say if you are on the right path