Saturday, 31 August 2013

How to have a if statment inside if

How to have a if statment inside if

if (mysql_num_rows($res) > 0) {
while ($row = mysql_fetch_assoc($res)) {
$tid = $row['id'];
$cid = $row['category_id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
if ($row['topic_last_user']== "") { $last_user =
getusername($row['topic_creator']); } else { $last_user =
getusername($row['topic_last_user']); }
if ($row['topic_last_user']== "") { $last2_user = 'Started by'; }
else { $last2_user = 'Most recent by'; }
$topics .= "<li class='category'><div class='left_cat'>
<a class='underline'
href='view_topic.php?cid=".$cid."&tid=".$tid."'><div
class='title'><i
class='icon-comment'></i>&nbsp;".$title."</div></a>
<div class='info'><i class='icon-comments
icon-1'></i>&nbsp;".topicreplies($cid, $tid)." Comments&nbsp;
&nbsp; &nbsp;<i class='icon-user icon-1'>
&nbsp;</i>".$last2_user."&nbsp;
Inside here i want to have this but this error is comming: Parse error:
syntax error, unexpected T_IF
This is the code i want here:
if ($info['rank'] == 1) { echo "<div class='admin'>".$last_user."</div>";
} else { echo "<div>".$last_user."</div>"; }
rest of the code:
&nbsp; &nbsp; &nbsp;<i
class='icon-calendar'>&nbsp;</i>&nbsp;".convertdate($date)."</div>
</div>";
$topics .= "<div class='right_cat'>
<div class='face'>
<img class='img_face'
src='https://minotar.net/avatar/".getusername($creator)."/40.png'></div>
<div class='comments_cat'>
<div class='comments_top'>Comments</div>
<div class='comments'>".topicreplies($cid, $tid)."</div></div>
<div class='views_cat'>
<div class='views_top'>Views</div>
<div class='views'>".$views."</div></div>
</div></li>";
}
echo $topics;
} else {
echo "<div class='alert alert-danger text5'>There are no topics
available yet.</div>";
}
Whole page:
<?php session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Forum</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css"></link>
<link rel="stylesheet" type="text/css" href="style.css"></link>
<script type="text/javascript"
src="http://mctheblitz.com/servers/js/bootstrap.js"></script>
<script type="text/javascript"
src="http://mctheblitz.com/servers/js/jquery.js"></script>
<script type="text/javascript" src="js/custom.js"></script>
<link
href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css"
rel="stylesheet"></link>
<link
href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css"
rel="stylesheet">
<link
href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css"
rel="stylesheet">
</head>
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse"
data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">The Blitz Forum</a>
<div class="nav-collapse collapse
navbar-responsive-collapse">
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</li>
</ul>
<ul class="nav pull-right">
<a href="http://localhost/forum/signin.php"
type="button" class="btn btn-default
navbar-btn">Sign in</a>
</li>
</ul>
</div><!-- /.nav-collapse -->
</div>
</div><!-- /navbar-inner -->
</div>
<body class="body box1">
<div class="container">
<div class="row-fluid">
<div class="box">
<div class="cat">Categories</div>
<div class="cat1">NETWORK ANNOUNCEMENTS</div>
<a class="underline" href="view_category.php?cid=3">
<li class="cat2">&#8627;<span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> Hide And Seek<span
class="label label-info right">0</span></li>
</a>
<div class="cat1">GENERAL</div>
<a class="underline" href="#">
<li class="cat2">&#8627;<span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> Questions<span class="label
label-info right">0</span></li>
</a>
<a class="underline" href="#">
<li class="cat2">&#8627;<span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> Bugs<span class="label
label-info right">0</span></li>
</a>
<div class="cat1">HIDE AND SEEK</div>
<a class="underline" href="#">
<li class="cat2">
&#8627; <span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> General Discussions<span
class="label label-info right">0</span></li>
</a>
<a class="underline" href="#">
<li class="cat2">
&#8627; <span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> Suggestions And Feedback<span
class="label label-info right">0</span></li>
</a>
<a class="underline" href="#">
<li class="cat2">
&#8627; <span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> Bugs<span class="label
label-info right">0</span></li>
</a>
<a class="progress-bar" data-placement="bottom" aria-valuenow=""
aria-valuemax="" title="Online Players"></a>
<div class="cat1">OFF TOPIC</div>
<a class="underline" href="#">
<li class="cat2">
&#8627; <span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> Minecraft<span class="label
label-info right">0</span></li>
</a>
<a class="underline" href="#">
<li class="cat2">
&#8627; <span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> Non-Gaming<span class="label
label-info right">0</span></li>
</a>
<a class="underline" href="#">
<li class="cat2">
&#8627; <span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> Gaming<span class="label
label-info right">0</span></li>
</a>
<div class="cat1">REPORTS AND APPEALS</div>
<a class="underline" href="#">
<li class="cat2">
&#8627; <span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> Player Reports<span
class="label label-info right">0</span></li>
</a>
<a class="underline" href="#">
<li class="cat4">
&#8627; <span class="">&nbsp;<i
class="icon-folder-close"></i>&nbsp;</span> Appeals<span class="label
label-info right">0</span></li>
</a>
</div>
<div class="topics">
<p class="text1">My First Forum!</p>
<div class="category_topics">
<?php
include_once("connect.php");
$topic_replies='';
function getusername($uid) {
$sql ="SELECT username FROM users WHERE id='".$uid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
return $row['username'];
}
function topicreplies($cid, $tid) {
$sql = "SELECT count(*) AS topicreplies FROM posts WHERE
category_id='".$cid."' AND topic_id='".$tid."'";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
return $row['topicreplies'] -1;
}
function convertdate($date) {
$date = strtotime($date);
return date("M j, g:ia", $date);
}
$hmm = mysql_query("SELECT rank FROM users")
or die(mysql_error());
$info = mysql_fetch_array( $hmm );
$cid = (isset($_GET['cid'])) ? $_GET['cid'] : '';
$tid = (isset($_GET['tid'])) ? $_GET['tid'] : '';
$logged='';
$topics='';
$new_views='';
$post_replys='';
$sql = "SELECT * FROM topics ORDER BY topic_date DESC";
$res = mysql_query($sql) or die(mysql_error());
$topics='';
if (mysql_num_rows($res) > 0) {
while ($row = mysql_fetch_assoc($res)) {
$tid = $row['id'];
$cid = $row['category_id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
if ($row['topic_last_user']== "") { $last_user =
getusername($row['topic_creator']); } else { $last_user =
getusername($row['topic_last_user']); }
if ($row['topic_last_user']== "") { $last2_user = 'Started by'; }
else { $last2_user = 'Most recent by'; }
$topics .= "<li class='category'><div class='left_cat'>
<a class='underline'
href='view_topic.php?cid=".$cid."&tid=".$tid."'><div
class='title'><i
class='icon-comment'></i>&nbsp;".$title."</div></a>
<div class='info'><i class='icon-comments
icon-1'></i>&nbsp;".topicreplies($cid, $tid)." Comments&nbsp;
&nbsp; &nbsp;<i class='icon-user icon-1'>
&nbsp;</i>".$last2_user."&nbsp;
*****Here i want i:*****
&nbsp; &nbsp; &nbsp;<i
class='icon-calendar'>&nbsp;</i>&nbsp;".convertdate($date)."</div>
</div>";
$topics .= "<div class='right_cat'>
<div class='face'>
<img class='img_face'
src='https://minotar.net/avatar/".getusername($creator)."/40.png'></div>
<div class='comments_cat'>
<div class='comments_top'>Comments</div>
<div class='comments'>".topicreplies($cid, $tid)."</div></div>
<div class='views_cat'>
<div class='views_top'>Views</div>
<div class='views'>".$views."</div></div>
</div></li>";
}
echo $topics;
} else {
echo "<div class='alert alert-danger text5'>There are no topics
available yet.</div>";
}
?>
</div>
</div>
</body>
</html>
</div`

No comments:

Post a Comment