gengar003
11-01-2003, 12:26 PM
Okay, I want to be able to execute this code:
/////////////// get news vars
$nid=$HTTP_GET_VARS['nid'];
$newsget=$DB_SITE->query("SELECT * FROM news WHERE nid='$nid'");
$author=$newsget['author'];
$title=$newsget['title'];
$text=$newsget['text'];
$date=$newsget['date'];
$number=0;
$idfind=$DB_SITE->query_plain("SELECT `number` FROM `comments` WHERE cnid='$nid' ORDER BY `number`");
while($idloop=$DB_SITE->fetch_array($idfind))
{
$number++;
}
$ncomments=$number;
//////////////
////////////// show the news item
maketableheader("1","black","500","","white","","1","1");
newsdisplay_content($nid,$date,$author,$title,$tex t,$ncomments);
maketablefooter();
spacing("p");
/////////////get comment vars and show comments.
$commentfetch = $DB_SITE->query_plain("SELECT * FROM comments WHERE cnid='$nid' ORDER BY number DESC");
if (!$commentfetch){
echo "NO comments.<p>";
} else {
while($commentloop = $DB_SITE->fetch_array($commentfetch))
{
$name=$commentloop['author'];
$email=$commentloop['email'];
$www=$commentloop['www'];
$comment=$commentloop['text'];
commentdisplay($name,$email,$www,$comment);
}
}
And when I place it in the script by itself, it works fine. However, for the purposes of my script, It would be much better were it in a function. (This large amt of code is used more than once. Also, functions allow me to place it more accurately on the page) So, to make a funciton, I do this:
function makeviewcommentpage(){
/////////////// get news vars
global $DB_SITE,$loggedinuser,$session;
$nid=$HTTP_GET_VARS['nid'];
$newsget=$DB_SITE->query("SELECT * FROM news WHERE nid='$nid'");
$author=$newsget['author'];
$title=$newsget['title'];
$text=$newsget['text'];
$date=$newsget['date'];
$number=0;
$idfind=$DB_SITE->query_plain("SELECT `number` FROM `comments` WHERE cnid='$nid' ORDER BY `number`");
while($idloop=$DB_SITE->fetch_array($idfind))
{
$number++;
}
$ncomments=$number;
//////////////
////////////// show the news item
maketableheader("1","black","500","","white","","1","1");
newsdisplay_content($nid,$date,$author,$title,$tex t,$ncomments);
maketablefooter();
spacing("p");
/////////////get comment vars and show comments.
$commentfetch = $DB_SITE->query_plain("SELECT * FROM comments WHERE cnid='$nid' ORDER BY number DESC");
if (!$commentfetch){
echo "NO comments.<p>";
} else {
while($commentloop = $DB_SITE->fetch_array($commentfetch))
{
$name=$commentloop['author'];
$email=$commentloop['email'];
$www=$commentloop['www'];
$comment=$commentloop['text'];
commentdisplay($name,$email,$www,$comment);
}
}
}
Adding only the "Function name (){", "Global...", and "}" lines.
And all the queries cease to work. Anyone know why?
Thanks in advance.
/////////////// get news vars
$nid=$HTTP_GET_VARS['nid'];
$newsget=$DB_SITE->query("SELECT * FROM news WHERE nid='$nid'");
$author=$newsget['author'];
$title=$newsget['title'];
$text=$newsget['text'];
$date=$newsget['date'];
$number=0;
$idfind=$DB_SITE->query_plain("SELECT `number` FROM `comments` WHERE cnid='$nid' ORDER BY `number`");
while($idloop=$DB_SITE->fetch_array($idfind))
{
$number++;
}
$ncomments=$number;
//////////////
////////////// show the news item
maketableheader("1","black","500","","white","","1","1");
newsdisplay_content($nid,$date,$author,$title,$tex t,$ncomments);
maketablefooter();
spacing("p");
/////////////get comment vars and show comments.
$commentfetch = $DB_SITE->query_plain("SELECT * FROM comments WHERE cnid='$nid' ORDER BY number DESC");
if (!$commentfetch){
echo "NO comments.<p>";
} else {
while($commentloop = $DB_SITE->fetch_array($commentfetch))
{
$name=$commentloop['author'];
$email=$commentloop['email'];
$www=$commentloop['www'];
$comment=$commentloop['text'];
commentdisplay($name,$email,$www,$comment);
}
}
And when I place it in the script by itself, it works fine. However, for the purposes of my script, It would be much better were it in a function. (This large amt of code is used more than once. Also, functions allow me to place it more accurately on the page) So, to make a funciton, I do this:
function makeviewcommentpage(){
/////////////// get news vars
global $DB_SITE,$loggedinuser,$session;
$nid=$HTTP_GET_VARS['nid'];
$newsget=$DB_SITE->query("SELECT * FROM news WHERE nid='$nid'");
$author=$newsget['author'];
$title=$newsget['title'];
$text=$newsget['text'];
$date=$newsget['date'];
$number=0;
$idfind=$DB_SITE->query_plain("SELECT `number` FROM `comments` WHERE cnid='$nid' ORDER BY `number`");
while($idloop=$DB_SITE->fetch_array($idfind))
{
$number++;
}
$ncomments=$number;
//////////////
////////////// show the news item
maketableheader("1","black","500","","white","","1","1");
newsdisplay_content($nid,$date,$author,$title,$tex t,$ncomments);
maketablefooter();
spacing("p");
/////////////get comment vars and show comments.
$commentfetch = $DB_SITE->query_plain("SELECT * FROM comments WHERE cnid='$nid' ORDER BY number DESC");
if (!$commentfetch){
echo "NO comments.<p>";
} else {
while($commentloop = $DB_SITE->fetch_array($commentfetch))
{
$name=$commentloop['author'];
$email=$commentloop['email'];
$www=$commentloop['www'];
$comment=$commentloop['text'];
commentdisplay($name,$email,$www,$comment);
}
}
}
Adding only the "Function name (){", "Global...", and "}" lines.
And all the queries cease to work. Anyone know why?
Thanks in advance.