Page 1 of 1

problem with code

Posted: Fri Jul 24, 2009 8:06 pm
by dawiva
The following code calls the information from the data base and puts it on a chart, it is a list of ads.
The only problem is: the las ad published goes at the end of the chart.
And what i need is that last ad published goes above in the chart, in the first row of the table.
The code calls the info: 1,2,3,4,5,6 and i need it calls it: 6,5,4,3,2,1.
In this way, the first ads published will be at the end as any website of classifieds.
Can you help me? Pleeease.

<?php
$conn = connect();
$showrecs = 20;
$pagerange = 10;

$page = @$_GET["page"];
if (!isset($page)) $page = 1;

select();


mysql_close($conn);
?>

<?php function select()
{
global $a;
global $showrecs;
global $page;

$res = sql_select();
$count = sql_getrecordcount();
if ($count % $showrecs != 0) {
$pagecount = intval($count / $showrecs) + 1;
}
else {
$pagecount = intval($count / $showrecs);
}
$startrec = $showrecs * ($page - 1);
if ($startrec < $count) {mysql_data_seek($res, $startrec);}
$reccount = min($showrecs * $page, $count);
?>


<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Employment</td></tr>
<tr><td>Ads shown <?php echo $startrec + 1 ?> - <?php echo $reccount ?> of <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<?php showpagenav($page, $pagecount); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="2" width="100%">
<tr>

<td class="hr" width="30%">Subject</td>

<td class="hr" width="70%">Ad</td>
</tr>
<?php
for ($i = $startrec; $i < $reccount; $i++)
{
$row = mysql_fetch_assoc($res);
$style = "dr";
if ($i % 2 != 0) {
$style = "sr";
}
?>


<tr>

<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["name_classi"]) ?></td>

<td class="<?php echo $style ?>" colspan="4"><?php echo htmlspecialchars($row["add_class"]) ?></td>
</tr>
<tr>
<td colspan="2"> <hr size="1" noshade></td>
</tr>
<?php
}
mysql_free_result($res);
?>
</table>

Re: problem with code

Posted: Fri Jul 24, 2009 8:38 pm
by jackpf
Use DESC in the order of your query.