Page 1 of 1

PHP Issue

Posted: Mon Nov 07, 2005 8:01 pm
by Grinch
I know nothing about PHP but I have a problem that needs to be fized.

If you go to here you will see the error.

Here is the code, the bolded section is the line in question:

Code: Select all

$category = "";
$getposts = mysql_query("SELECT * FROM $posts_tbl ORDER BY Timestamp DESC LIMIT
    $showposts_is");
    while ($row = mysql_fetch_array($getposts)) {
    $postid = $row[PostID];
    $timestamp = $row[Timestamp];
    $date = date($postdatepattern_is,$timestamp);
    $pagetitle = $row[Title];
    $body = $row[Body];
    $catid = $row[PostCat];
    $catid2 = $row[PostCat2];
    $catid3 = $row[PostCat3];
    $catid4 = $row[PostCat4];
    $comms = mysql_query("SELECT CommID FROM $comments_tbl WHERE PostID=$postid");
    $countcomms = mysql_num_rows($comms);
        if($catid == "") {$category .= "";} else {
            $getcatname = mysql_query("SELECT PostCat, PostCatUrl FROM $postcat_tbl WHERE
                PCatID='$catid'");
            while ($cat = mysql_fetch_array($getcatname)) {
            $category .= "<a href=\"archive.php?cat=$cat[PostCatUrl]\">$cat[PostCat]</a>, ";
            }
        }
        if($catid2 == "") {$category .= "";} else {
            $getcatname = mysql_query("SELECT PostCat, PostCatUrl FROM $postcat_tbl WHERE
                PCatID='$catid2'");
            while ($cat = mysql_fetch_array($getcatname)) {
            $category .= "<a href=\"archive.php?cat=$cat[PostCatUrl]\">$cat[PostCat]</a>, ";
            }
        }
        if($catid3 == "") {$category .= "";} else {
            $getcatname = mysql_query("SELECT PostCat, PostCatUrl FROM $postcat_tbl WHERE
                PCatID='$catid3'");
            while ($cat = mysql_fetch_array($getcatname)) {
            $category .= "<a href=\"archive.php?cat=$cat[PostCatUrl]\">$cat[PostCat]</a>, ";
            }
        }
        if($catid4 == "") {$category .= "";} else {
            $getcatname = mysql_query("SELECT PostCat, PostCatUrl FROM $postcat_tbl WHERE
                PCatID='$catid4'");
            while ($cat = mysql_fetch_array($getcatname)) {
            $category .= "<a href=\"archive.php?cat=$cat[PostCatUrl]\">$cat[PostCat]</a>, ";
            }
        }
        $category = substr($category, 0, -2);
        if($category == "") $category = "no category";
        
    
    $prev_next = NULL;
    $prevlink = mysql_query("SELECT PostID FROM $posts_tbl WHERE Timestamp<'$timestamp' ORDER BY Timestamp DESC LIMIT 1");
    $prevcount = mysql_num_rows($prevlink);
    while ($row = mysql_fetch_array($prevlink)) {$prev = $row[PostID];}
    if($prevcount > 0) {$prev_next .= "<a href=\"permalink.php?PostID=$prev\">Previous Post</a> || ";
    } else {$prev_next .= "Previous Post || ";}
    
    $nextlink = mysql_query("SELECT PostID FROM $posts_tbl WHERE Timestamp>'$timestamp' ORDER BY Timestamp ASC LIMIT 1");
    $nextcount = mysql_num_rows($nextlink);
    while ($row = mysql_fetch_array($nextlink)) {$next = $row[PostID];}
    if($nextcount > 0) {$prev_next .= "<a href=\"permalink.php?PostID=$next\">Next Post</a>";
    } else {$prev_next .= "Next Post";}

    $use_template = array("{TITLE}" => $pagetitle,"{POST_ID}" => $postid,
        "{DATE}" => $date,"{BODY}" => $body,"{COMMENT_COUNT}" => $countcomms,
        "{CATEGORY}" => $category,"{PREV_NEXT}" => $prev_next);
    if ($file = implode('', file("template/blog.htm"))) {
        foreach($use_template as $key => $value) {
            $file=@str_replace($key,$value,$file);
        }
        echo $file;
    }
    
    $category = NULL;

}
This is the line that is causing problems:

Code: Select all

while ($row = mysql_fetch_array($getposts)) {
PHP geniuses please help me.

Posted: Tue Nov 08, 2005 6:10 am
by KrazyKid
Post your problem on webmasterworld.com. Someone will most likely help you there. You aren't allowed to post url there though, so I don't know how that will work out. Good luck

Posted: Tue Nov 08, 2005 10:53 am
by battye
Looks ok to me, but sometimes crazy things happen, and I have found that it sometimes fixes it.

Code: Select all

while ($row = mysql_fetch_array($getposts)) {
Replace with:

Code: Select all

while ($row = mysql_fetch_assoc($getposts)) {
Let me know how it goes

Posted: Tue Nov 08, 2005 1:17 pm
by Grinch
I contacted the creator and he has a new version coming out in a few days so I will wait till then and will check it out.

Posted: Tue Nov 08, 2005 2:32 pm
by battye
Ok, congratulations on your 1500 posts :)

Posted: Wed Nov 09, 2005 1:31 pm
by nesman
This is almost a close fit to the thread (and I don't think it's a big enough issue to get a new thread):

Battye, didn't you link to a php-based guestbook program a while back that doesn't require a database? I tried searching it, but I don't know where it went.

Posted: Wed Nov 09, 2005 2:24 pm
by battye
Yeah, I made a program called PetitionMX which runs without a database: http://forums.cricketmx.com/viewtopic.php?t=2248

Despite it being made for Petitions, it will work fine for guestbooks.

Posted: Thu Nov 10, 2005 8:40 am
by nesman
Heh, no wonder I couldn't find the thing. I had guestbook stuck in my head.