SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict joyce's Avatar
    Join Date
    Aug 2001
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    1 record in database but 2 records were selected??

    i'm retrieving a record from database. below the record, i have a yes and no button, where i can let user click and then count the number of yes and no.

    everything works fine, but when i start to click the yes or no button, my record ,becomes two records. i only have one record in my database, but two same record was displayed.

    this is the code:
    PHP Code:
    function admin_view($cat_ID)
    {
        global 
    $review_obj$cat$subcat$title$flag$desc$image$cat_ID$cate$subcate$newrows;
        global 
    $url_site$url_image$font_face$font_color;
        
    //**********************Retrieve data from admin_review********************
        
    $result mysql_query("SELECT ID, date, cat, rate, title, review, flag, cat_ID, mod_ID, status FROM review WHERE flag=1 AND status='a' AND cat_ID='$cat_ID' ORDER BY date DESC");

        
    $numrows mysql_num_rows($result);
        
        
        
    //***************************view admin_review*******************************
        
    if ($numrows 0)
        {
            
    //echo "<tr><td>";
            
            
            
    echo"<table width=100% border=0 cellpadding=1 cellspacing=1>";
            echo 
    "<tr><td><font face=\"$font_face\" size=2 color=\"$font_color\"><b>Administrator's Review</b></font></td></tr>";
        
        }else
            
    $rows=0;
        
        while (
    $temp mysql_fetch_array($result))
        {    
            
    $date display_date($temp['date']);
            
    $ID $temp['ID'];
            
    $cat $temp['cat'];
            
    $star $temp['rate'];
            
    $title $temp['title'];
            
    $review $temp['review'];
            
    $cat_ID $temp['cat_ID'];
            
    $mod_ID $temp['mod_ID'];
            
    $status $temp['status'];

            
    $yes count_review('a',$ID,'y');
            
            
    $no count_review('a',$ID,'n');

            if (
    $yes == '')
                
    $yes 0;
            
            if (
    $no == '')
                
    $no 0;

            
    $total $yes $no;
            
            if (
    $total != 0
            {
                echo 
    "<tr><td><font face=\"$font_face\" size=1>$yes of $total people found the following review helpful:</font></td></tr>";
            }
            
            echo 
    "<tr><td>";
            
    display_star($star);
            echo 
    "<font face=\"$font_face\" size=1><b>&nbsp;&nbsp;&nbsp;$title,</b></font><font face=\"$font_face\" size=1>&nbsp;$date</font></td></tr>";
            echo 
    "<tr><td><font face=\"$font_face\" size=1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            
    $word explode(" "$review);
            
    $number 0;
            
    $row 0;
            
    $flat 0;
            
    $newrow=0;
            for (
    $j=0;$j<count($word) ;$j++)
            {
                
    $number += strlen($word[$j]);

                if (
    $j == || $newrows == 1)
                    echo 
    $word[$j];
                else 
                {
                    echo 
    " ".$word[$j];
                    
    $newrows 0;
                }

                if (
    $number 58)
                {
                    echo 
    "<br>";
                    echo 
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    
    $number 0;
                    
    $row++;
                    
    $newrow 1;
                }
                if (
    $row == 10)
                {
                    
    $flat 1;
                    break;
                }

            }
            if (
    $flat)
            {
                echo 
    "<font face=\"$font_face\" size=1>...<a href=\"$url_site/template/index.php?ID=$ID&cat=$cat&title=$title&review=$review&image=$image&flag=$flag&status=a&a=1\">more details</a></font>";
            }
            
            echo 
    "</font></td></tr>";
            echo 
    "<tr><td>&nbsp;</td></tr>";
            echo 
    "<tr><td><font face=\"$font_face\" size=1>Do you find this review useful:&nbsp;";
            echo 
    "<a href=\"$url_site/template/index.php?ID=$ID&status=a&cflag=y&image=$imgpath&cat_cat=$cat&title=$title&review=$review&cat_ID=$cat_ID\"><img src='$url_image/template/image/yes.gif' border=0 align=middle></a>&nbsp;";
            echo 
    "<a href=\"$url_site/template/index.php?ID=$ID&status=a&cflag=n&image=$imgpath&cat_cat=$cat&title=$title&review=$review&cat_ID=$cat_ID\"><img src='$url_image/template/image/no.gif' border=0 align=middle></a>";
            echo 
    "</td></tr>";
            
        } 
    //endfor
        
    if ($numrows 0)
        {
            echo 
    "</td></tr>";
            echo 
    "</table>";
            
        }
        

    pls help. thanks.

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2001
    Location
    Earth
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've looked at the code and it looks correct. Have you just checked what the result of:

    PHP Code:
    $numrows mysql_num_rows($result); 
    Maybe just add a echo $numrows just to validate the rowcount?

    Is it possible that this function is somehow getting called twice?

    Frank
    http://www.serverexpert.com/ Discuss servers and the software that makes them work.
    http://www.webmasters-resources.com/ Resources for webmasters.

  3. #3
    Free me php klassicd's Avatar
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why

    it seems like your not finishing all yoru if, else and elseif statements. You sometimes forget to put you } at the end. Or you forget to start them with a { . Is there a reason your not?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •