Jump to content


query trouble


  • Please log in to reply
3 replies to this topic

#1 Guest_edwinsweep_*

Guest_edwinsweep_*
  • Guests

Posted 01 March 2006 - 01:15 PM

hi everybody
i have been messing with my php script trying to get it to work.
before trowing my monitor out of the window i thought maybe you guys know what is going on:)
its a small piece of script from a forum.
this peace of code delete's a complete topic from my forum and will also set the total number of replys back.
lets say my counter is on 15 for the amount of replys that are on my forum.
then when i delete a topic with only 5 replys in it, i want the counter to go back to 10.
so i wrote this script.


$quik =mysql_query("SELECT * FROM forumnews WHERE vantopicid = '$topic_id' ") or die(mysql_error());
$ab =mysql_num_rows($quik);
if (($ab = 1) OR ($ab = 0)){

}else{
mysql_query("UPDATE forums SET nrofreplys = nrofreplys-'$ab' WHERE forum_id = '$vfi' ") or die(mysql_error());
}

the damn thing just wont work, anybody have an idea???
thanks in advance

#2 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 01 March 2006 - 01:20 PM

Is this closer to what you want?
$quik =mysql_query("SELECT * FROM forumnews WHERE vantopicid = '$topic_id' ") or die(mysql_error());
$ab =mysql_num_rows($quik);
if (($ab! <= 1){
     mysql_query("UPDATE forums SET nrofreplys = nrofreplys-$ab WHERE forum_id = '$vfi' ") or die(mysql_error());
}


#3 Guest_edwinsweep_*

Guest_edwinsweep_*
  • Guests

Posted 01 March 2006 - 01:25 PM

[!--quoteo(post=350594:date=Mar 1 2006, 02:20 PM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 1 2006, 02:20 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Is this closer to what you want?
$quik =mysql_query("SELECT * FROM forumnews WHERE vantopicid = '$topic_id' ") or die(mysql_error());
$ab =mysql_num_rows($quik);
if (($ab! <= 1){
     mysql_query("UPDATE forums SET nrofreplys = nrofreplys-$ab WHERE forum_id = '$vfi' ") or die(mysql_error());
}
[/quote]

yeah i think this will work and i think i just found what i have done wrong.
if (($ab = 1) OR ($ab = 0)){ <-------- 1x=
if (($ab == 1) OR ($ab == 0)){ <--------2x=

#4 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 02 March 2006 - 10:13 PM

I've been bit by that a hundred times... I think it happens because you write an SQL query that does a single = followed by a PHP clause that uses a double ==
That's my theory, anyways...

I also cleaned up your first clause, by making the if !== you don't need the if then else you had before...





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users