Page 2 of 3
Posted: Wed Mar 02, 2005 7:28 am
by smpdawg
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?
Posted: Wed Mar 02, 2005 7:32 am
by pleigh
this gives me headache.....errors:
Undefined variable: row in c:
and
mysql_fetch_array(): supplied argument is not a valid MySQL result resource 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 adminpagination
Posted: Wed Mar 02, 2005 7:34 am
by smpdawg
Then instead of getting $postID by accessing the $row variable, pass it into the function that is getting the number of comments.
Posted: Wed Mar 02, 2005 7:39 am
by CoderGoblin
smpdawg wrote:CodeGoblin - I see we have a smartass here.
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).
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>";
Pass the row[2] variable through to your replies function...
Code: Select all
<td width=10% class=tableborder><table><tr><td>".replies($rowї2])."</td></tr></table></td>
The replies function now becoming
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");
}
}
Posted: Wed Mar 02, 2005 7:44 am
by smpdawg
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.
Posted: Wed Mar 02, 2005 7:49 am
by pleigh
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
Code: Select all
if ($rcResult)
{
return (@mysql_result($rcResult,0,'rowcount');
}
spmdawg -->yes, i believe so because my adminpagination function will, as i can see, will generate the $_GET['pid']
Posted: Wed Mar 02, 2005 7:54 am
by CoderGoblin
Sorry my fault, extra bracket...
Code: Select all
return @mysql_result($rcResult,0,'rowcount');
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.
Posted: Wed Mar 02, 2005 7:55 am
by pleigh
hey guys, it did work, but an error occured
Warning: 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=
to hightlight the line
Code: Select all
function replies($postID)
{
......
}
last one, and im on it....

Posted: Wed Mar 02, 2005 8:03 am
by smpdawg
It would appear that when you called to the replies function, you did not send the parameter. Look back in the other function where replies() was called inside of that table.
See coders second code block.
Posted: Wed Mar 02, 2005 8:07 am
by CoderGoblin
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...
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))
{
should be returning the postID as $row[2].
to check we can put...
Code: Select all
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
var_dump($row);
Run the code and at a guess the 3rd array value $row[2] is empty.
You need to fix this within the DB itself.
Posted: Wed Mar 02, 2005 8:19 am
by smpdawg
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()
Posted: Wed Mar 02, 2005 8:44 am
by pleigh
tried some experimentations, but still get the same error....
Posted: Wed Mar 02, 2005 8:45 am
by smpdawg
Show us the updated code.
Posted: Wed Mar 02, 2005 8:46 am
by CoderGoblin
Show code again time. Please show the I showed in my previous post.
Did you try the var_dump ? If so please also show that output.
Posted: Wed Mar 02, 2005 8:47 am
by pleigh
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");
}
}