Basically, I am working on a joke site that allows users to submit jokes. When displaying the jokes, I want to use a function called joke_author, which will automatically find the authors username based on the authorid of the joke.
in both my users table and jokes table, the user id is authorid. so every new user is assigned an authorid.
anyways, here's my code for the function (in separate functions.inc.php).
function joke_author($jokeid) {
$authorid = mysql_query("SELECT authorid FROM jokes WHERE id=$jokeid");
$author = mysql_query("SELECT username FROM users WHERE authorid=$authorid");
echo "<a href=\"profile.php?id=" . $authorid . "\">" . $author . "</a>";
}
and here's the PHP executed for displaying a joke. I know it's rough, trying to make everything into a function...
<?php
$jokes = mysql_query("SELECT * FROM jokes");
while($row = mysql_fetch_array($jokes)) {
echo "<div class=\"joke\"><a href=\"#\" class=\"rating\">";
$jokeid = $row['id'];
echo vote_count($jokeid);
print $row ['joke'];
echo "<div class=\"meta\">";
echo joke_author($jokeid);
echo " | Today at 7:56PM | ";
echo "<a href=\"joke.php?jid=" . $jokeid . "\">";
echo comment_count($jokeid);
echo "</a></div></div>";
}
?>
I just want to know why it doesn't display and how to fix it. If you could, explain some of te steps. I keep going to a live support and they just say "run this query..." and IDK wtf to do next :(