[thelist] Doh! question for MySQL

Adrian Fischer adrian at logo-logic.com
Wed Feb 14 04:05:17 CST 2001


I might be able to help...

$db = &dbconnect;
 $dbh=$db->prepare("SELECT COUNT(*) FROM tblDockets WHERE docPending<=0 AND
docClosed<=2 AND docAccountEnd >= " . int($current_time) . " ");
$dbh->execute();
($count) = $dbh->fetchrow_array();
&dbdisconnect($db);
$show=($count-5);
$db_query = "SELECT
docBusName,docStreet,docBusPhone,docState,docRegion,docSuburb FROM
tblDockets WHERE docPending<=0 and docClosed<=2 ORDER BY docId LIMIT $show,
$limit";
$db = &dbconnect;
 $dbh=$db->prepare($db_query);
$varReturnResult = $dbh->execute();
if ($varReturnResult)
  {
while ($varDBInfo = $dbh->fetchrow_arrayref) {
$a++;
if ($a<=$limit){
if ($i % 2 == 1) {
$config{'colortablebody'}=$config{'odd_row_color'}; }
else { $config{'colortablebody'}=$config{'even_row_color'}; }
$i++;
print "<TR
BGCOLOR=$config{'colortablebody'}><td>$$varDBInfo[0]</td><TD>$$varDBInfo[1]<
br>Phone: $$varDBInfo[2]<br>$$varDBInfo[5] $$varDBInfo[4]
$$varDBInfo[3]</TD></TR>";
  }##END WHILE LOOP
  }##END LIMIT
  }
$dbh->finish;
&dbdisconnect($db);

try this on for size....not sure how technically correct it is but it uses
count then deducts the number you want to display and then uses LIMIT to
display the last x number of records (in my case 5)  just change the 5 to a
10 and wam bam thank you mam......you have it done.

I look forward to someone who actually knows what there talking about
pointing out a more efficient way......hey , what can I say...I roll my
own....it aint pretty but it works...

HTH

Adrian Fischer

>
> The client wants to show on the front page the last ten items that were
sold...
>
> So I was thinking that I would write a query to pull the latest ten - but
I
> don't want to do it on a timestamp, in case nothing gets sold in
awhile.....
>
> thanks for your help
>
> -w
>






More information about the thelist mailing list