Solved

else statment only ever outputs the first statement

Posted on 2008-10-29
3
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

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 143

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses four methods for overlaying images in a container on a web page
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

756 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