I have a basic forum system set up (one I created myself) and one particular feature in the forum topic page is the option to "tag this topic" this essentially adds this topic to a favourite topics list. One example row in the "tagged_topics" table looks a bit like this layout:
topic_id: 56
username: DjDark1
date_added: Wednesday, November 3rd 2010, 15:40 GMT
date_added_timestamp: 1288798836
There is no issue adding data to the database but the problem arises to bring it back out.
So on my actual "tagged topics" page, I wish to retrieve every topic tagged by the user, I can do this by searching for a username and returning an array.
$q = "SELECT * FROM ".TB_FAVOURITETOPICS." where username = '$session->username'";
$result = mysql_query($q);
if(!$result || (mysql_numrows($result) < 1)){
return null;
}
$TopicResults = mysql_fetch_array($result);
Now another function within this page is to submit a topic id and it will check that topic to see if it exists and we can access it.
$forum->checktopic($topicid); returns an array with all the topic information.
What I want to do is set up a loop that loops through all the "topic_id" in the users tagged topics, then for each id check the topic so that it returns the array then output an array for each topic. This will all be done in one function preferably.
So far I have wrote this:
function getTaggedTopics(){
global $session;
$q = "SELECT * FROM ".TB_FAVOURITETOPICS." where username = '$session->username'";
$result = mysql_query($q);
if(!$result || (mysql_numrows($result) < 1)){
return null;
}
$TopicResults = mysql_fetch_array($result);
for ($j=0; $j<count($TopicResults); $j++){
$forum->checkTopic($TopicResults['topic_id']);
}
}
This does not work. I'm sorry for my very poor explanation of how this is going to work, but essentially you can see I want to check each topic_id and if successful this will return an array with the topic info such as the topic title, date posted etc... but a different array will be returned for every topic so really I want to return all these arrays for how many topics the user has tagged.
Thanks in advance for anyone that helps, if you don't need anymore elaboration, I'll try and be clearer.
Regards,
DjDark1

New Topic/Question
Reply



MultiQuote





|