NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Adding ifs and elses

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 10-21-2005, 09:44 AM THREAD STARTER               #1 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Adding ifs and elses


Here's one for ya. I have an SQL query which echos the results from he table into a table row (using the 'while' statement). Half way through, I have an include but the file included is just a set of ifs and elses which set a variable. But when I open the PHP file, it only shows the last result of the database query. It works perfectly when I remove the include though.

Help would be very much appreciated and rewarded
Encenta.com is offline  
Old 10-21-2005, 10:45 AM   #2 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,074
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
without any code it will be difficult to help.
Peter is offline  
Old 10-21-2005, 10:55 AM THREAD STARTER               #3 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Sorry, didn't really want to show off my bad coding, plus it's a bit long..

viewthread.php:

PHP Code:
...

$result mysql_query("SELECT * FROM forum WHERE category='$category' AND threadid='$thread' ORDER BY id DESC"
or die(
"SELECT Error1: " .mysql_error());
$num=mysql_numrows($result);


$i=0;
while (
$i $num) {
if (
$i 2) {
$bgcolor "forumtable";
            }
????: NamePros.com http://www.namepros.com/programming/133661-adding-ifs-and-elses.html
else {
$bgcolor "forumtable2";
     }
$id=mysql_result($result,$i,"id");
$author=mysql_result($result,$i,"author");
$contentwo=mysql_result($result,$i,"content");
$time=mysql_result($result,$i,"time");
$date=mysql_result($result,$i,"date");
$today date("d/m/y");

if (
$date == $today) {$date "Today"; }


$content=nl2br($contentwo);


$query mysql_query("SELECT * FROM forum WHERE author='$author'"
or die(
"SELECT Error1: " .mysql_error());
$posts=mysql_numrows($query);


include(
"includes/statuses.php");


echo 
"    
<table width='100%' border='0' class='
$bgcolor'>
<tr>
<td width='150px' valign='top'>
<a href='view_profile.php?profile_id=
$id'>$author</a><br /><font color='#1616FF'>\"Registered user\"</font><br />
$status<br />Number of posts: $posts<br />$date at $time</td>
<td valign='top'>
$content</td>
</tr>

</table>
<br />"
;

$i++;

}

... 
includes/statuses.php:

PHP Code:
<?
if ($posts >=1)
{
$status "Newbie";}

elseif (
$posts >=20)
{
$status "Junior";}

elseif (
$posts >=60)
{
$status "Regular";}

elseif (
$posts >=200)
{
$status "Senior";}


$result1 mysql_query("SELECT * FROM users WHERE username='$author'"
or die(
"SELECT Error1: " .mysql_error());
$num=mysql_numrows($result1);
while (
$row mysql_fetch_array($result1)) 

$account $row['account'];
}


if (
$account == "a")
{
$status "<b>Administrator</b>";}
elseif (
$account == "m")
{
$status "<b>Moderator</b>";}

?>
Last edited by Encenta.com; 10-21-2005 at 11:09 AM.
Encenta.com is offline  
Old 10-21-2005, 11:00 AM   #4 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,074
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
not sure if it is causing the problem but I notice you are including config.php. Ussually people use this for creating theirdatabase connection plus other things. Are you also including this in viewthread.php if so it may be what is causing the problem.

If are including this in both files there may be and probably is not any need as includes/statuses.php would already have access to the connection varaibles etc because it has full access to what the main script uses.

When you include a file it acts as if the code is within the script it is included from.
Peter is offline  
Old 10-21-2005, 11:08 AM THREAD STARTER               #5 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 579
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




I've removed it from the included file (and updated my post) but still not working. Thanks for the suggestion.
Encenta.com is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:02 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger