Unstoppable Domains

Adding ifs and elses

Spaceship Spaceship
Watch

SiKing

Registered MemberEstablished Member
Impact
6
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 :hehe:
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
without any code it will be difficult to help.
 
0
•••
Sorry, didn't really want to show off my bad coding, plus it's a bit long..

viewthread.php:

PHP:
...

$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";
			}
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:
<?
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:
0
•••
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.
 
0
•••
I've removed it from the included file (and updated my post) but still not working. Thanks for the suggestion.
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back