Hello.
Well its a simple questions, not much to explain.
Im using PHP to display information from a Sql database in tables.
http://toplist2.ulmb.com/
But that isn't what it is supposed to look like.
It is supposed to look like this:
http://cod5server.com.net.sc/index.php
Here is my code:
(This code will repeat everything that is below it, i don't know why.
<?php
require "connect.php";
//max displayed per page
$per_page = 10;
//get start variable
$start = $_GET['start'];
//count records
$result=mysql_query("SELECT COUNT(*) FROM data") or die( mysql_error() );
$record_count = mysql_result($result , 0);
//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal
if (!$start)
$start = 0;
//display data
$get = mysql_query("SELECT * FROM data ORDER BY votes DESC LIMIT $start, $per_page");
$G=$start;
while ($row = mysql_fetch_assoc($get))
{
if (strlen($row['sdetail']) > 10) // if len is more than 10
{ // shorten it and add trailing dots.
$sdetail = substr($row['sdetail'], 0, 100) . "...";
}
else // len is less than 10, use original description.
{
$sdetail = $row['sdetail'];
}
// get data
$sname = $row['sname'];
$svotes = $row['votes'];
$id = $row['ID'];
$G++;
?>
<div id="toplist">
<table id="table">
<tr>
<th width="10%">Rank</th>
<th width="10%">Name</th>
<th width="10%">Description</th>
<th width="10%">Votes</th>
</tr>
<tr>
<td><p>#<?php echo $G; ?></p></td>
<td><?php echo $sname; ?></td>
<td><?php echo " $sdetail"; ?></td>
<td><?php echo $svotes; ?></td>
</tr>
<tr>
</table>
</div>
<?php
}
echo "<center>";
//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;
//show prev button
if (!($start<=0))
echo "<a href='viewtoplist.php?start=$prev'>Prev </a>";
//show page numbers
//set variable for first page
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page)
{
if ($start!=$x)
echo "[<a href='viewtoplist.php?start=$x'>$i </a>]";
else
echo "[<a href='viewtoplist.php?start=$x'><b>$i </b></a>]";
$i++;
}
//show next button
if (!($start>=$record_count-$per_page))
echo "<a href='viewtoplist.php?start=$next'>Next</a>";
echo "</center>";
?>
Thats the code of the toplist.
Now this is the code that displays the information:
<?php
require "connect.php";
//max displayed per page
$per_page = 10;
//get start variable
$start = $_GET['start'];
//count records
$result=mysql_query("SELECT COUNT(*) FROM data") or die( mysql_error() );
$record_count = mysql_result($result , 0);
//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal
if (!$start)
$start = 0;
//display data
$get = mysql_query("SELECT * FROM data ORDER BY votes DESC LIMIT $start, $per_page");
$G=$start;
while ($row = mysql_fetch_assoc($get))
{
if (strlen($row['sdetail']) > 10) // if len is more than 10
{ // shorten it and add trailing dots.
$sdetail = substr($row['sdetail'], 0, 100) . "...";
}
else // len is less than 10, use original description.
{
$sdetail = $row['sdetail'];
}
// get data
$sname = $row['sname'];
$svotes = $row['votes'];
$id = $row['ID'];
$G+
?>
As you can see that code is ABOVE the header. This is what is causing it (I assume)
But your probably saying, why can't you just put this above the tables:
<tr>
<td><p>#<?php echo $G; ?></p></td>
<td><?php echo $sname; ?></td>
<td><?php echo " $sdetail"; ?></td>
<td><?php echo $svotes; ?></td>
</tr>
This just results in..Bad..
It shows the first row in the DB but everything else is just text with no table and its bad.
So any help please?