Solved

else statment only ever outputs the first statement

Posted on 2008-10-29
3
164 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
ID: 22836571
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
ID: 22836668
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]
ID: 22836729
>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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

813 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

19 Experts available now in Live!

Get 1:1 Help Now