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
Solved

else statment only ever outputs the first statement

Posted on 2008-10-29
3
165 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 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to count occurrences of each item in an array.
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.

792 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