Richzilla Posted May 16, 2007 Share Posted May 16, 2007 I'm trying to show the most recent downloads added to my site and then ordering them by the last 5. The code below doesn't return any results. Any ideas on what i'm doing wrong? $query = "SELECT * FROM Mixes WHERE 'download1'!=NULL ORDER BY 'id' DESC "; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < '5') { $download1=mysql_result($result,$i,"download1"); $id=mysql_result($result,$i,"id"); $dj=mysql_result($result,$i,"dj"); $rave=mysql_result($result,$i,"event"); $date=mysql_result($result,$i,"date"); ?> <? echo $dj ?><br> <? echo $event ?><br> <? echo $date ?><br> <p align='right'>--------------------</p> <p class="main_text" align="right"><span class="time_main_text_small"> <? $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/51656-solved-using-select-and-where-and-ordering-results-issues/ Share on other sites More sharing options...
MadTechie Posted May 16, 2007 Share Posted May 16, 2007 you need a field for timestamping i used lastDL $query = "SELECT * FROM Mixes WHERE 'download1'!=NULL ORDER BY 'lastDL' DESC limit 0,5"; Revised: <?php $query = "SELECT * FROM Mixes WHERE 'download1'!=NULL ORDER BY 'date' DESC limit 0,5"; $result=mysql_query($query); $num=mysql_numrows($result); while ($row = FetchAssoc($result,MYSQL_NUM)) $download1=$row["download1"]; $id=$row["id"]; echo "{$row["dj"]}<br>"; echo "{$row["event"]}<br>"; echo "{$row["date"]}<br>"; } ?> <p align='right'>--------------------</p> <p class="main_text" align="right"><span class="time_main_text_small"> <?php } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/51656-solved-using-select-and-where-and-ordering-results-issues/#findComment-254437 Share on other sites More sharing options...
kathas Posted May 16, 2007 Share Posted May 16, 2007 try using something like this to get the resuts <?php while ( ($res = mysql_fetch_array($result)) && ($i < 5) ) { $download1 = $res['download']; // same for the rest... $i++; } ?> It is faster than mysql_result... Link to comment https://forums.phpfreaks.com/topic/51656-solved-using-select-and-where-and-ordering-results-issues/#findComment-254440 Share on other sites More sharing options...
Richzilla Posted May 16, 2007 Author Share Posted May 16, 2007 Thanks for the responses. You're right i need to timestamp the downloads. I'll get cracking on it. Link to comment https://forums.phpfreaks.com/topic/51656-solved-using-select-and-where-and-ordering-results-issues/#findComment-254473 Share on other sites More sharing options...
Richzilla Posted May 16, 2007 Author Share Posted May 16, 2007 is ok to use this syntax to add the timestamp into a new column in my database? $_SERVER['REQUEST_TIME']; $query = ("UPDATE Mixes SET submitter = '$sub' , download1 = '$dl1' , download2 = '$dl2' , download3 = '$dl3' , download4 = '$dl4' , timestamp = 'date(U)' WHERE id = '$mix'"); I've tried this and its not working. Link to comment https://forums.phpfreaks.com/topic/51656-solved-using-select-and-where-and-ordering-results-issues/#findComment-254508 Share on other sites More sharing options...
MadTechie Posted May 16, 2007 Share Posted May 16, 2007 try timestamp = now() Link to comment https://forums.phpfreaks.com/topic/51656-solved-using-select-and-where-and-ordering-results-issues/#findComment-254527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.