Jump to content

Some Bad Typing Somewhere :(


ckrudelux
 Share

Recommended Posts

Okay need some help somewhere in the code is something really wrong:

<?php	$select = mysql_query("SELECT * FROM category ORDER BY c_id DESC LIMIT " . (($page - 1) * 20) . ", 20");	while($row = mysql_fetch_array($select)){			$id = $row['c_id'];		$select1 = mysql_query("SELECT * FROM topic WHERE c_id='$id' ORDER BY t_id DESC");		$topics = mysql_num_rows($select1); //Echo is 22 and it should be 22		$row1 = mysql_fetch_array($select1);		$id1 = $row1['t_id'];				if($id1 == ''){		$id1 = 0;		}				$select2 = mysql_query("SELECT * FROM post WHERE t_id='$id1'");		$posts = mysql_num_rows($select2); //Echo is 0 but should be 7		$row2 = mysql_fetch_array($select2);		$user = $row2['u_id'];				$select3 = mysql_query("SELECT * FROM user WHERE u_id='$user'");		$row3 = mysql_fetch_array($select3);				$user = $row3['username'];				$topic = $row1['title'];	?>

Link to comment
Share on other sites

Are you getting any error messages?
No I don't :) it just don't write out the correct sum of row's :) got 7 rows with t_id 1.But then I echo $id1 I get 0 and 22 but they are on top of each other 0 and 22 under. :)
Link to comment
Share on other sites

Here is the hole page if it helps:

<?php$page = isset($_GET['page']) ? (int) $get_page : 1;$querystring = "";foreach ($_GET as $key => $value) {if ($key != "c" and $key != "t") $querystring .= "$key=$value&";}if(!isset($_GET['t']) and !isset($_GET['c'])){	//If nothing is set show category	?>	<p class="hp">		<a class="flink" href="">Forum</a>	</p>	<div class="htopicrow">		<div class="row">			Forum		</div>		<div class="forumtitle">			Forum Title		</div>		<div class="forumdescription">			Description		</div>		<div class="forumpostsandtopics">			Topics		</div>		<div class="forumpostsandtopics">			Posts		</div>		<div class="forumlast">			Last Poster		</div>	</div>	<?php	$select = mysql_query("SELECT * FROM category ORDER BY c_id DESC LIMIT " . (($page - 1) * 20) . ", 20");	while($row = mysql_fetch_array($select)){			$id = $row['c_id'];		$select1 = mysql_query("SELECT * FROM topic WHERE c_id='$id' ORDER BY t_id DESC");		$topics = mysql_num_rows($select1);				$row1 = mysql_fetch_array($select1);		$id1 = $row1['t_id'];				if($id1 == ''){		$id1 = 0;		}		echo $id1;		$select2 = mysql_query("SELECT * FROM post WHERE t_id='$id1'");		$posts = mysql_num_rows($select2);		$row2 = mysql_fetch_array($select2);		$user = $row2['u_id'];				$select3 = mysql_query("SELECT * FROM user WHERE u_id='$user'");		$row3 = mysql_fetch_array($select3);				$user = $row3['username'];				$topic = $row1['title'];	?>		<div class="htopicrow1">		<div class="forumtitle1">			<a class="flink" href="?<?php echo $querystring;?>c=<?php echo $row['c_id'];?>"><?php echo $row['title'];?></a>		</div>		<div class="forumdescription1">			<?php echo $row['description']; ?>		</div>		<div class="forumpostsandtopics1">			<?php echo $topics; ?>		</div>		<div class="forumpostsandtopics1">			<?php echo $posts; ?>		</div>		<div class="forumlast1">			<div class="split"><a class="flink" href="?<?php echo $querystring;?>u=<?php echo $row2['u_id']; ?>"><?php echo $user;?></a></div>			<div class="split">In: <a class="flink" href="?<?php echo $querystring;?>t=<?php echo $id1; ?>"><?php echo $topic; ?></a></div>		</div>	</div>	<?php		}	$query = mysql_query("SELECT * FROM category");	$pages1 = mysql_num_rows($query);	$pages1 = ceil($pages1 / 20);	$querystring1 = "";	foreach ($_GET as $key => $value) {		if ($key != "page") $querystring1 .= "$key=$value&";	}	if(isset($_GET['page']) and $get_page > 1){ 	$sta = "href=\"?{$querystring1}page=1\""; 	$pre = $get_page - 1; 	$pre = "href=\"?{$querystring1}page={$pre}\"";	}else { 	$sta = ""; 	$pre = "";	}	if(!isset($_GET['page']) and $pages1 == !0 or $pages1 == !0 and $get_page < $pages1){		if(!isset($_GET['page'])){			$nex = 2;		}else {			$nex = $get_page + 1;		}	$nex = "href=\"?{$querystring1}page={$nex}\"";	$end = "href=\"?{$querystring1}page={$pages1}\""; 	}else {	$nex = "";	$end = "";	}	if($pages1 > 1){	?>	<div id="pagebar">	<a <?php echo $sta; ?>>< Start</a> <a <?php echo $pre ?>>< Föregående</a>	<?php	for ($i = 1; $i <= $pages1; $i++) {		echo "<a " . ($i == $page ? "class=\"selected\" " : "");		echo "href=\"?{$querystring1}page=$i";		echo "\">$i</a> ";	}	?>	<a <?php echo $nex; ?>>Nästa ></a> <a <?php echo $end ?>>Slutet ></a>	</div>	<?php	}}else if(isset($_GET['c']) and !isset($_GET['t'])){	//if category is set show topics in the category	$id = $_GET['c'];	$selectl = mysql_query("SELECT * FROM category WHERE c_id=$id");	$rowl = mysql_fetch_array($selectl);	?>	<p class="hp">		<a class="flink" href="?<?php echo $querystring;?>">Forum</a> > <a class="flink" href="?<?php echo "$querystring";?>c=<?php echo $_GET['c']?>"><?php echo $rowl['title'];?></a>	</p>	<div class="htopicrow">		<div class="row">			<?php echo $rowl['title'];?>		</div>		<div class="topicicon">		</div>		<div class="topictitle">			Topic Title		</div>		<div class="topicstarter">			Topic Starter		</div>		<div class="topicrepliesandviews">			Replies		</div>		<div class="topicrepliesandviews">			View's		</div>		<div class="topiclast">			Last Poster		</div>	</div>	<?php		$c_id = $_GET['c'];	$select = mysql_query("SELECT * FROM topic WHERE c_id='$c_id' ORDER BY date DESC LIMIT " . (($page - 1) * 20) . ", 20");	while($row = mysql_fetch_array($select)){				$user = $row['u_id'];		$select1 = mysql_query("SELECT * FROM user WHERE u_id='$user'");		$row1 = mysql_fetch_array($select1);		$user = $row1['username'];				$last = $row['t_id'];		$select2 = mysql_query("SELECT * FROM post WHERE t_id='$last'");		$posts = mysql_num_rows($select2);		$posts = $posts - 1;		if($posts < 0){		$posts = 0;		}		$row2 = mysql_fetch_array($select2);		$last = $row2['u_id'];				$select3 = mysql_query("SELECT * FROM user WHERE u_id='$last'");		$row3 = mysql_fetch_array($select3);		$last = $row3['username'];					?>	<div class="htopicrow2">		<div class="topicicon2">			Ic		</div>		<div class="topictitle2">			<a class="flink" href="?<?php echo $querystring;?>t=<?php echo $row['t_id'];?>"><?php echo $row['title']; ?></a>		</div>		<div class="topicstarter2">			<a class="flink" href="index.php?u=<?php echo $row['u_id'];?>"><?php echo $user;?></a>		</div>		<div class="topicrepliesandviews2">			<?php echo $posts;?>		</div>		<div class="topicrepliesandviews2">			<?php echo $row['views'];?>		</div>		<div class="topiclast2">			<a class="flink" href="index.php?u=<?php echo $row['u_id'];?>"><?php echo $last;?></a>		</div>	</div>	<?php	}	$query = mysql_query("SELECT * FROM topic WHERE c_id='$c_id'");	$pages1 = mysql_num_rows($query);	$pages1 = ceil($pages1 / 20);	$querystring1 = "";	foreach ($_GET as $key => $value) {		if ($key != "page") $querystring1 .= "$key=$value&";	}	if(isset($_GET['page']) and $get_page > 1){ 	$sta = "href=\"?{$querystring1}page=1\""; 	$pre = $get_page - 1; 	$pre = "href=\"?{$querystring1}page={$pre}\"";	}else { 	$sta = ""; 	$pre = "";	}	if(!isset($_GET['page']) and $pages1 == !0 or $pages1 == !0 and $get_page < $pages1){		if(!isset($_GET['page'])){			$nex = 2;		}else {			$nex = $get_page + 1;		}	$nex = "href=\"?{$querystring1}page={$nex}\"";	$end = "href=\"?{$querystring1}page={$pages1}\""; 	}else {	$nex = "";	$end = "";	}	if($pages1 > 1){	?>	<div id="pagebar">	<a <?php echo $sta; ?>>< Start</a> <a <?php echo $pre ?>>< Föregående</a>	<?php	for ($i = 1; $i <= $pages1; $i++) {		echo "<a " . ($i == $page ? "class=\"selected\" " : "");		echo "href=\"?{$querystring1}page=$i";		echo "\">$i</a> ";	}	?>	<a <?php echo $nex; ?>>Nästa ></a> <a <?php echo $end ?>>Slutet ></a>	</div>	<?php	}}else if(!isset($_GET['c']) and isset($_GET['t'])){	//if topic is set show the post for the topic?><p class="hp">	<?php		$t_id = $_GET['t'];		$tselect = mysql_query("SELECT * FROM topic WHERE t_id='$t_id'");		$topic = mysql_fetch_array($tselect);		$c_id = $topic['c_id'];		$cselect = mysql_query("SELECT * FROM category WHERE c_id='$c_id'");		$category = mysql_fetch_array($cselect);	?>	<a class="flink" href="?<?php echo $querystring;?>">Forum</a> > <a class="flink" href="index.php?<?php echo $querystring;?>c=<?php echo $c_id; ?>"><?php echo $category['title'];?></a> > <a class="flink" href="index.php?<?php echo $querystring;?>t=<?php echo $t_id; ?>"><?php echo $topic['title'];?></a></p><?php$t_id = $_GET['t'];$select = mysql_query("SELECT * FROM post WHERE t_id='$t_id' ORDER BY date LIMIT " . (($page - 1) * 6) . ", 6");while($row = mysql_fetch_array($select)){	$u_id = $row['u_id'];	$select1 = mysql_query("SELECT * FROM user WHERE u_id='$u_id'");	$row1 = mysql_fetch_array($select1);	$user = $row1['username'];?><div class="row">	<div class="hpost"><a class="flink" href="index.php?u=<?php echo $row['u_id'];?>"><?php echo $user;?></a></div> <div class="right"><?php echo $row['date'];?></div></div><div class="fposttext">	<?php echo $row['message'];?></div><div class="row">	<div class="right"><a class="flink" href="">Replay</a> <a class="flink" href="">Edit</a> <a class="flink" href="">Delete</a></div></div><div class="space"></div><?php}$query = mysql_query("SELECT * FROM post WHERE t_id='$t_id'");$pages1 = mysql_num_rows($query);$pages1 = ceil($pages1 / 6);$querystring1 = "";foreach ($_GET as $key => $value) {	if ($key != "page") $querystring1 .= "$key=$value&";}if(isset($_GET['page']) and $get_page > 1){ $sta = "href=\"?{$querystring1}page=1\""; $pre = $get_page - 1; $pre = "href=\"?{$querystring1}page={$pre}\"";}else { $sta = ""; $pre = "";}if(!isset($_GET['page']) and $pages1 == !0 or $pages1 == !0 and $get_page < $pages1){	if(!isset($_GET['page'])){		$nex = 2;	}else {		$nex = $get_page + 1;	}$nex = "href=\"?{$querystring1}page={$nex}\"";$end = "href=\"?{$querystring1}page={$pages1}\""; }else {$nex = "";$end = "";}if($pages1 > 1){?><div id="pagebar"><a <?php echo $sta; ?>>< Start</a> <a <?php echo $pre ?>>< Föregående</a><?phpfor ($i = 1; $i <= $pages1; $i++) {	echo "<a " . ($i == $page ? "class=\"selected\" " : "");	echo "href=\"?{$querystring1}page=$i";	echo "\">$i</a> ";}?><a <?php echo $nex; ?>>Nästa ></a> <a <?php echo $end ?>>Slutet ></a></div><?php}}?>

Link to comment
Share on other sites

Print out the various database queries so you can see what's happening. The numbers are correct for the queries that you're sending, you're probably not sending the queries you think you are.
Okay so I just come up with that nothing is wrong and everything is doing what it's suppose to do. It's just me miss reading and there for miss thinking the obvious.What it does is echoing number of post what belongs to the topic and not all the number of post for the group :) :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...