Hello, I'm new here, but I'm hoping someone can help me. I'm setting up a PHP-Nuke site, and I'm trying to customize some code on one of the pages, and I'm at a total loss. I don't know PHP that well yet, so I could be doing this totally wrong.
What I have is 2 tables in the same database, a user table and a topics table. The original page was set up to simply grab all the topics from the topics table and populate a drop down menu. What I would like to do is filter what topics appear in the menu based on a username. The reason I'd like this is because the site is being set up as a magazine, and instead of just anyone being able to post to any section, I want the users to have their own sections that only they post to.
Let me show you the part of the code I'm working with, as it was on the original page.
."<b>".TOPIC.":</b> <select name=\"topic\">";
$toplist = sql_query("select topicid, topictext from ".$prefix."topics order by topictext", $dbi);
echo "<option value=\"\">"._SELECTTOPIC."</option>\n";
while(list($topicid, $topics) = sql_fetch_row($toplist, $dbi)) {
if ($topicid==$topic) {
$sel = "selected ";
}
echo "<option $sel value=\"$topicid\">$topics</option>\n";
$sel = "";
}
echo "</select>";
It's the $topiclist line and then the 'while' line I think I'm needing to change. So here's one of my attempts, but it's not working.
."<b>".TOPIC.":</b> <select name=\"topic\">";
$result=sql_query("select stltopics from ".$prefix."users where uname='$cookie[1]'", $dbi);
list($stltopics) = sql_fetch_array($result);
$toplist=sql_query("select topicid, topictext from ".$prefix."topics where topicid='$stltopics'", $dbi);
echo "<option value=\"\">".SELECTTOPIC."</option>\n";
while(list($topicid, $topics) = sql_fetch_row($toplist, $dbi)) {
if ($topicid==$topic) {
$sel = "selected ";
}
echo "<option $sel value=\"$topicid\">$topics</option>\n";
$sel = "";
}
echo "$user";
echo "</select>";
In the users table I've added the field stltopics, which is a SET field that will accept null values. Then, some of the users have more than one topic to post to, so some of them have values like "4,7,12" etc. The second example above does work enough to return the first value found, but not the rest. I need for the rest of the user's topics to be in the menu as well.
I tried using the explode() but I couldn't get it to work.
I hope I'm explaining this well. Please, if anyone can help me with this, I would be very grateful. Thanks.
Tortured