Jump to content

[SOLVED] php database


dezkit

Recommended Posts

i wanna do it so that if there is more than 10 entries in the database, there will be a "2" on the bottom of the page to show like there is another page of entries. for example there are 5 entries in the database, and it doesnt show anything on the bottom, if there are more than 10, say 11, then it will show "2" at the bottom and it will show the entry

Link to comment
Share on other sites

oh wow, this pagination is screwing me up. can somebody please please please form a pagination out of this please. :P

 

<h2 class="main"><span>Matches</span></h2>
<div class="cbox matches">
<div>
	<?
	$q = mysql_query("SELECT * FROM `matches` ORDER BY id DESC");
	$matches = mysql_num_rows($q);
	if($matches) {
	?>
   <? 
   echo "
  <p style='font-size: 14px;'>
	<b>$clanname</b> <br />$wins-$losses-$ties
   </p>";
   ?>
	<table cellspacing="0" cellpadding="2">
	<?
	$i = 0;
	while($r = mysql_fetch_array($q)) {
		$i += 1;
		$winner = split("-",$r['score']);
		if($winner[0] > $winner[1]) {
			$status = "<td class=\"win\">Won</td>";
		} else if($winner[0] < $winner[1]) {
			$status = "<td class=\"loss\">Loss</td>";
		} else {
			$status = "<td class=\"tie\">Tie</td>";
		}
		?>
		<tr class="row<?=($i&1)?>">
			<td>Extinguish <font style="font-size:8pt; font-weight:bold; color: #888888;">vs</font> <?=$r['team2']?></td>
			<td class="score"><?=$r['score']?></td>
			<?=$status?>
		</tr>
		<?if($r['info'] != "") { ?>
		<tr class="row<?=($i&1)?>">
<td colspan="3" class="comments"><i>
HLTV Demo: <a href="demos/<?=$r['info']?>">download</a>
</i></td>
		</tr>
		<? }
	}
	?></table><?
	} else {
		echo "We haven't played any matches yet!";
	}
	?>
</div>
<center>
<font size="-1" color=white>
THIS IS WHERE THE 1 2 3 4 5 ETC HAS TO BE
</font><br>
</center>
</div>



Link to comment
Share on other sites

Very messy code, if you don't mind me saying. :P

 

<h2 class="main"><span>Matches</span></h2>
<div class="cbox matches">
<div>
	<?php
		//HOW MAN MATCHES PER PAGE?
		$matchesPerPage = 10;

		//NOW WE GET THE PAGE THEY ARE VIEWING
		if(!isset($_GET['page'])){
			$page = 1;
		}else{
			$page = $_GET['page'];
		}

		$totalMatches = mysql_num_rows(mysql_query("SELECT * FROM `matches`"));
		$totalPages = ceil($totalMatches/$matchesPerPage);

		if($page > $totalPages){
			//They are trying to view a page out of the range
			$page = $totalPages;
		}

		//This gets the number where we start from when limiting in our MySQL query
		$from = ($matchesPerPage * $page) - $matchesPerPage;

		$q = mysql_query("SELECT * FROM `matches` ORDER BY id DESC LIMIT {$from}, {$matchesPerPage}");
		$matches = mysql_num_rows($q);
		if($matches > 0){
			echo "<p style='font-size: 14px;'><b>{$clanname}</b> <br />{$wins}-{$losses}-{$ties}</p>";
		?>
		<table cellspacing="0" cellpadding="2">
			<?
			$i = 0;
	while($r = mysql_fetch_array($q)) {
		$i += 1;
		$winner = split("-",$r['score']);
		if($winner[0] > $winner[1]) {
			$status = "<td class=\"win\">Won</td>";
		} else if($winner[0] < $winner[1]) {
			$status = "<td class=\"loss\">Loss</td>";
		} else {
			$status = "<td class=\"tie\">Tie</td>";
		}
		?>
		<tr class="row<?=($i&1)?>">
			<td>Extinguish <font style="font-size:8pt; font-weight:bold; color: #888888;">vs</font> <?=$r['team2']?></td>
			<td class="score"><?=$r['score']?></td>
			<?=$status?>
		</tr>
		<?if($r['info'] != "") { ?>
		<tr class="row<?=($i&1)?>">
<td colspan="3" class="comments"><i>
HLTV Demo: <a href="demos/<?=$r['info']?>">download</a>
</i></td>
		</tr>
		<? }
	}
	?></table><?
	} else {
		echo "We haven't played any matches yet!";
	}
	?>
</div>
<center>
<font size="-1" color=white>
<?php
	for($p = 1; $p < $totalPages; $p++){
		if($p == $page){
			echo "<b>{$p}</b> ";
		}else{
			echo "<a href='yourpagelink.php?page={$p}'>{$p}</a> ";
		}
	}
?>
</font><br>
</center>
</div>

 

Hopefully I didn't miss anything.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.