Jump to content


Photo

SO Actually whats wrong?


  • Please log in to reply
3 replies to this topic

#1 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 01 August 2006 - 04:27 AM


$s1 = mysql_query("SELECT * FROM topics WHERE fid='$s'");

$count = mysql_num_rows($s1);
mysql_query("UPDATE forums SET topics='$count' WHERE id='$s' ");


welll i have this code and im trying to update the topics on index page so when i add that to one of my pages it doesnt update the forums topics the way it should but when i add it to my add reply page it counts everytime and shows on index then i come back like a hour later and it doesnt update until the next time i count

what should i do
Dont Piss me Off today

#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 01 August 2006 - 06:22 AM

Don't mind explain more in details ?

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 01 August 2006 - 06:35 AM

alright i have a script 2 addtopic's and everytime i add a topic it updates the forum topics so after it updates the mysql_num_rows guess it messes up and doesnt show until another post is made.

<?php
$s = $_GET['id'];

$name = $logged[username];
$title = htmlspecialchars($_POST['title']);
$post = htmlspecialchars($_POST['post']);
$spost = $_POST['spost'];


if(isset($spost)){

$s1 = mysql_query("SELECT * FROM topics WHERE fid='$s'");

$count = mysql_num_rows($s1);
mysql_query("UPDATE forums SET topics='$count' WHERE id='$s' ");
mysql_query("INSERT INTO topics(fid,title,post,username) VALUES('$s','$title','$post','$name')") or die(mysql_error());
echo "Post Created Successfully";


}elseif(!isset($spost)){
?>
<table colspan=2 bgColor="#FFFFFF">
<tr>
<td><form  method="post"></td>
</tr>
<tr>
<td>User Name</td>
<td><? echo $logged[username]; ?></td>
</tr>
<tr>
<td>Topic Title</td>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td>Post:<td>
<td><textarea width="200" height="200" name="post"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="spost"></td>
<td></form></td>
</tr>
</table>
<? } ?>



and i do this on index where i grab the info

<?php
$nc9 = mysql_query("SELECT * FROM topics") or die(mysql_error());
$f2 = mysql_fetch_array($nc9);


$nc2 = mysql_query("SELECT * FROM forums") or die(mysql_error());
while($f = mysql_fetch_array($nc2)){
if($f[cid] ==$c[id]){
$replies = $f[replies];
$topics = $f[topics];
?>
<table colspan=4 bgColor="#E4EAF2" width="90%" style=" border:1px solid #000;border-top:0px solid #000">
<tr>
<td width="50%"><a href="viewforum.php?fid=<? echo $f[id]; ?>"><? echo $f[title]; ?></a></td>
<td width="20%"><? echo $f[lastpost]; ?></td>
<td width="10%"><? echo $topics; ?></td>
<td width="10%"><? echo $replies; ?></td>
</tr>
</table>
<? }}} ?>


so im wondering why does the topics row in forums table doesnt stay updated?
Dont Piss me Off today

#4 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 01 August 2006 - 09:32 AM

I believe the problem is at
mysql_query("UPDATE forums SET topics='$count' WHERE id='$s' ");

Is your topics refer to the latest thread ?

Try this
mysql_query("UPDATE forums SET topics='".$count+1."' WHERE id='$count' ");


Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users