Jump to content

[SOLVED] looping a table and updating it while looping


DataRater

Recommended Posts

PHP 5 MySQL 5

 

Basically I have one connection doing a select and print loop

and a second doing an update which increments the count of the times it is displayed.

 

The problem is the value of count is not being incremented when it comes back from the database. So that makes me look in the database and sure enough it isn't. So I'm wondering if the two connections are fighting one another and I would like a solution.

 

  $Connection1 = @mysqli_connect(  'host', 'user', 'pw','db'  );

    $sql = "SELECT *  FROM Cars";

    $ResultSet1  = mysqli_query($Connection1, $sql );

    mysqli_data_seek($ResultSet1,0);

    while (  list($id,$name, $manufacturer, $model, $count ) = mysqli_fetch_row($ResultSet1) )

      {

      $general_query_count++;

     

 

      $sql = "UPDATE Cars SET general_query_count=".$general_query_count.$Space."WHERE id ='".$id."'";

      $Connection2 = @mysqli_connect(  'host', 'user', 'pw','db'  );

      $ResultSet2  = mysqli_query($Connection2, $sql );

     

   

    if (!is_null($name)){          $name =                    nl2br(htmlspecialchars($name))."<br />";}

    if (!is_null($manufacturer)){ $manufacturer =        nl2br(htmlspecialchars($manufacturer))."<br />";}

    f (!is_null($model)){            $model =                  nl2br(htmlspecialchars($model))."<br />";}

 

********* Print the data**********

      }

 

Link to comment
Share on other sites

I've solved it. The while(list( doesn't have sufficient elements for the * in the select statement. Duhhhhhhh

 

 

$sql = "SELECT *  FROM Cars";

    $ResultSet1  = mysqli_query($Connection1, $sql );

    mysqli_data_seek($ResultSet1,0);

    while (  list($id,$name, $manufacturer, $model, $count ) = mysqli_fetch_row($ResultSet1) )

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.