开发者

using sql rowcount in limit query

My Table looks like this:

id | Value
-----------
1  | High
2  | Medium
3  | Low
4  | Low

My php query looks like this:

    $sqlquery   = "select id from db_name order by id desc limit 3";  
    $fetchres   =  mysql_query($sqlquery);
    if(mysql_num_rows($fetchres)>0){
    while($result =  mysql_fetch_array($fetchres))  
    {   
    if($result['history']=='High'){?>

           <div style="background:#FF0000; width:50px; height:50px; vertical-align:middle;float:left;margin:0 10px 0 0"> </div>&nbsp;
    <?php } else if($result['history']=='Medium') {?>  
            <div style="background:#FF0; width:50px; height:50px; vertical-align:middle;float:left;margin:0 1开发者_如何学编程0px 0 0"> </div>&nbsp;
    <?php } else if($result['history']=='Low') {?>  
            <div style="background:#090; width:50px; height:50px; vertical-align:middle;float:left;margin:0 10px 0 0"> </div> &nbsp;

But it displays the results wrong

block 1 should be at block 3 and vice versa, block 2 stays where it currently is.

making sql query "asc" does not help, it only shows first 3 results and i need this to keep history of last three.

So my question is can you use something like rowcount within the sql query limit, if not how to correct the code to display it correctly.


In your SQL query yuo are selecting only id column select id from

Then you are comparing string values with non-existing index history from your result.

Correct this first and see if this will produce your desired result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜