Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

else statment only ever outputs the first statement

Posted on 2008-10-29
3
Medium Priority
?
171 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

971 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