1 record in database but 2 records were selected??

They have: 164 posts

Joined: Nov 2001

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
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 == 0 || $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.

They have: 601 posts

Joined: Nov 2001

Haven't had time to look ar your message, but one thing did hit me in the first few lines. Your MySQL query looks a bit icky.

You should really enclose a number of AND or OR statements in parenthesis. i.e. the following chunk should be in parenthesis:

... WHERE (flag=1 AND status='a' AND cat_ID='$cat_ID') ...

Didn't look at the rest, sorry. Will look when I have more time tomorrow.

- wil

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Parenthesis are not crucial in that query, they are all AND statements and can only be interpreted one way. Depending who you talk to, it can be considered a good habit.

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 601 posts

Joined: Nov 2001

I just think it's good practice. Otherwise you may find yourself with undesired results. It also improves on readability, too.

But I am an avid fan of use strict;.

- wil

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.