Solved

else statment only ever outputs the first statement

Posted on 2008-10-29
3
163 Views
Last Modified: 2012-05-05
im trying to grab from the db users that have posted in my forum... so then if they have posted in a spesific thread then it will show an icon ...
think is my code only shows yes u possted here... no matter what the outcome :S
<?php

require_once '../settings.php';
 
 

$query = mysql_query("SELECT COUNT(postid) FROM forumtutorial_posts WHERE postid='255' OR parentid = '255' AND author='demo'");
 

   if($query != 0) {

      echo 'yes you poster here';

   }

   else

   {echo 'no';}

   ?>

Open in new window

0
Comment
Question by:runnerjp
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
you need () around the OR condition?

also, you need to "fetch" the result:
$query = mysql_query("SELECT COUNT(postid) FROM forumtutorial_posts WHERE( postid='255' OR parentid = '255' ) AND author='demo'");
$count = mysql_result($query, 0,0);
if ($count != 0) 
 ...

Open in new window

0
 

Author Comment

by:runnerjp
Comment Utility
thanks that worked great... 2 questions... who () the or and also whats this ($query, 0,0);
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
>also whats this ($query, 0,0);
actually, that is mysql_result($query, 0,0);

that function returns the first column (0-based index) from the first row (again, 0-based index) from the query handle ($query). more info:
www.php.net/mysql_result

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now