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**********

      }

 

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) )

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.