pleigh - What isn't working? Shows us your revised code. Is this site somewhere that we can see what is happening?
counting replies
Moderator: General Moderators
- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
CoderGoblin - I see we have a smartass here. 
pleigh - What isn't working? Shows us your revised code. Is this site somewhere that we can see what is happening?
pleigh - What isn't working? Shows us your revised code. Is this site somewhere that we can see what is happening?
Last edited by smpdawg on Wed Mar 02, 2005 7:38 am, edited 1 time in total.
this gives me headache.....errors:
andUndefined variable: row in c:
please be advised that the two codes i've posted earlier are two different funtions, i embedded the replies funtion to the adminpagination function, and to view the result of the viewing page, i only called the adminpagination function, not the replies function for it is embedded in the adminpaginationmysql_fetch_array(): supplied argument is not a valid MySQL result resource in c
- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
Then instead of getting $postID by accessing the $row variable, pass it into the function that is getting the number of comments.
Last edited by smpdawg on Wed Mar 02, 2005 7:45 am, edited 1 time in total.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Just following your logic through... Seriously though I have found it can make a lot of difference on response times even when doing a count (although I use postgres).smpdawg wrote:CodeGoblin - I see we have a smartass here.
On to the answer...
Code: Select all
$rowї0] = '<font size=1>'.$rowї0].'</font>';
echo "<tr><td width=20% class=tableborder align=center><table><tr><td><b><a href="" class="under">".strtolower($rowї3])."</a><b></td></tr></table></td>
<td width=50% class=tableborder><table><tr><td><a href="reportview.php?pid={$rowї2]}" class="under" style="font-weight: bold;">$rowї1]</a></td></tr></table></td>
<td width=10% class=tableborder><table><tr><td>".replies()."</td></tr></table></td>
<td width=20% class=tableborder><table><tr><td>$rowї0]</td></tr></table></td></tr>";Code: Select all
<td width=10% class=tableborder><table><tr><td>".replies($rowї2])."</td></tr></table></td>Code: Select all
function replies($postID)
{
$rcQuery = "SELECT count(postID) AS rowcount FROM comments WHERE postID=$postID";
$rcResult = @mysql_query($rcQuery);
if ($rcResult) {
return (@mysql_result($rcResult,0,'rowcount');
} else {
die("Error with $rcQuery");
}
}- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
Agreed, accessing a single field name is faster. In this case it was laziness that made me use the *.
While hate is a strong word, I will say that I am not fond of PostGres. I can't stand how difficult PostGres makes it to dump a database to a file and create a new database from it. pg_dump. ugh. I have made dumps of databases and then had PostGres die in the middle of trying to reload it because it didn't like the data in its own dumps. Don't get me wrong, I still use PostGres for some of my work but I do it with a frown.
While hate is a strong word, I will say that I am not fond of PostGres. I can't stand how difficult PostGres makes it to dump a database to a file and create a new database from it. pg_dump. ugh. I have made dumps of databases and then had PostGres die in the middle of trying to reload it because it didn't like the data in its own dumps. Don't get me wrong, I still use PostGres for some of my work but I do it with a frown.
wait....got mixed up....but thanks guys for your patience
coder --> i did what you shared to me but returned a parse error somewhere here
spmdawg -->yes, i believe so because my adminpagination function will, as i can see, will generate the $_GET['pid']
coder --> i did what you shared to me but returned a parse error somewhere here
Code: Select all
if ($rcResult)
{
return (@mysql_result($rcResult,0,'rowcount');
}- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Sorry my fault, extra bracket...
Off topic....
Postgres has many advantages especially when compared with older versions of MySQL (views being one), but several disadvantages. Lack of last_id and server support being a couple.
Code: Select all
return @mysql_result($rcResult,0,'rowcount');Postgres has many advantages especially when compared with older versions of MySQL (views being one), but several disadvantages. Lack of last_id and server support being a couple.
hey guys, it did work, but an error occured
last one, and im on it.... 
to hightlight the lineWarning: Missing argument 1 for replies() in c:\inetpub\wwwroot\mysample\functions\library.php on line 322
Error with SELECT count(postID) AS rowcount FROM comments WHERE postID=
Code: Select all
function replies($postID)
{
......
}- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Now you can see why I put the debug line in...
We are not getting a value for $postID hence not being placed in the SQL.
We now need to go back to where the function is called...
should be returning the postID as $row[2].
to check we can put...
Run the code and at a guess the 3rd array value $row[2] is empty.
You need to fix this within the DB itself.
We are not getting a value for $postID hence not being placed in the SQL.
We now need to go back to where the function is called...
Code: Select all
<td width=10% class=tableborder><table><tr><td>".replies($rowї2])."</td></tr></table></td>Code: Select all
$query = "SELECT DATE_FORMAT(postupdate, '%M %D, %Y - %l:%i %p'), title, postID, firstname FROM posts AS p, users AS you
WHERE p.userID = you.userID ORDER BY postupdate DESC LIMIT $start, $display";
$result = @mysql_query ($query);
.
.
.
.
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{to check we can put...
Code: Select all
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
var_dump($row);You need to fix this within the DB itself.
- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
Pleigh is definitely missing the change in what is your first code example from that last post. The right error messages are being displayed for that to be the case as demonstrated by PHP complaining about a missing parameter as that would only have happened if the call to replies looks like this. replies()
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
ok...
Code: Select all
//function for administrator pagination
function adminpagination()
{
$display = 10;
if (isset($_GETї'np']))
{
$num_pages = $_GETї'np'];
}
else
{
$query = "SELECT * FROM posts";
$query_result = mysql_query ($query);
$num_records = @mysql_num_rows ($query_result);
if ($num_records > $display)
{
$num_pages = ceil ($num_records/$display);
}
else
{
$num_pages = 1;
}
}
if (isset($_GETї's']))
{
$start = $_GETї's'];
}
else
{
$start = 0;
}
// Make the query.
$query = "SELECT DATE_FORMAT(postupdate, '%M %D, %Y - %l:%i %p'), title, postID, firstname FROM posts AS p, users AS u
WHERE p.userID = u.userID ORDER BY postupdate DESC LIMIT $start, $display";
$result = @mysql_query ($query);
$num = mysql_num_rows ($result);
if ($num > 0)
{
if ($num_pages > 1)
{
$current_page = ($start/$display) + 1;
if ($current_page != 1)
{
echo '<a href="report.php?s=' . ($start - $display) .
'&np=' . $num_pages . '" class=under>Previous</a> ';
}
for ($i = 1; $i <= $num_pages; $i++)
{
if ($i != $current_page)
{
echo '<a href="report.php?s=' . (($display * ($i - 1))) .
'&np=' . $num_pages . '" class=under>' . $i . '</a> ';
}
else
{
echo $i . ' ';
}
}
if ($current_page != $num_pages)
{
echo '<a href="report.php?s=' . ($start + $display) .
'&np=' . $num_pages . '" class=under>Next</a>';
}
}
echo "<tr align=center class=tablehead><td width=20% class=tableborder><table><tr><td><b>NAME</b></td></tr></table></td>
<td width=50% class=tableborder><table><tr><td><b>TOPIC</b></td></tr></table></td>
<td width=10% class=tableborder><table><tr><td><b>REPLIES</b></td></tr></table></td>
<td width=20% class=tableborder><table><tr><td><b>DATE</b></td></tr></table></td></tr>";
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
//puta
$rowї0] = '<font size=1>'.$rowї0].'</font>';
echo "<tr><td width=20% class=tableborder align=center><table><tr><td><b><a href="" class="under">".strtolower($rowї3])."</a><b></td></tr></table></td>
<td width=50% class=tableborder><table><tr><td><a href="reportview.php?pid={$rowї2]}" class="under" style="font-weight: bold;">$rowї1]</a></td></tr></table></td>
<td width=10% class=tableborder><table><tr><td>".replies($rowї2])."</td></tr></table></td>
<td width=20% class=tableborder><table><tr><td>$rowї0]</td></tr></table></td></tr>";
}
mysql_free_result ($result);
}
else
{
echo '<h3>There are no records to show.</h3>';
}
mysql_close();
}
//funtion for counting replies
function replies($postID)
{
$rcQuery = "SELECT count(postID) AS rowcount FROM comments WHERE postID=$postID";
$rcResult = @mysql_query($rcQuery);
if ($rcResult)
{
return (@mysql_result($rcResult,0,'rowcount'));
}
else
{
die("Error with $rcQuery");
}
}