Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End php mysql update query limit?

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #44964
    RajkumarLA
    Member

    **Table:** cquestions
    cqid, cqtext, showdate.

    I want to update ‘showdate’ field to tomorrows date..

    **database:**

    cqid cqtext showdate
    200 q1 2013-05-22
    201 q2 0000-00-00
    202 q3 0000-00-00

    the idea is to display only one question everyday. showdate is compared with the current date and display the first question q1. the starting date only store in db. now i want to update only the next row (q2)’s showdate to tomorrows date. next day wen q2 is displayed q3 will be updated to tomorrows date.
    today q1 displayed. db is like this.

    cqid cqtext showdate
    200 q1 2013-05-22
    201 q2 2013-05-23
    202 q3 0000-00-00

    tomorrow q2 displayed. then db
    cqid cqtext showdate
    200 q1 2013-05-22
    201 q2 2013-05-23
    202 q3 2013-05-24
    203 q4 0000-00-00

    **my code:**

    $today=date(“Y/m/d”);
    $tomorrow= date(“Y-m-d”, strtotime(“tomorrow”));
    echo “

    “;
    $sql=”SELECT * FROM cquestions where showdate= ‘$today’ limit 1″;
    $result=mysql_query($sql);
    while ($row = mysql_fetch_array($result)) {
    $cqid=mysql_result($result,”cqid”);
    $update1=”update cquestions set showdate=’$tomorrow’ where showdate=’0000-00-00′ and cqid!=’$cqid’ order by cqid limit 1″;
    mysql_query($update1);

    echo “

    ” . $row . “

    “;
    $sql2=”SELECT * FROM canswers where cqid=”.$row;
    $result2=mysql_query($sql2);
    while($row2=mysql_fetch_assoc($result2)){
    echo ““.$row2; }
    /*echo ““;*/
    }
    echo”“;
    echo “

    “;
    ?>

    this code update the next row, but the problem is its executed every time page loads and update the next row… i want to execute the update query only once for the day. how to do it?

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.