Jump to content

Update issue, i think!


a1amattyj

Recommended Posts

Hello,

So what this php code does, it counts of which how many "rows" use the same "db"(database)..

 

Now where it echos the values :

echo 'Total Forums: ';
echo $num_rows;
echo '<br />';

it echos the correctly:

Database ID: 1

Total Forums: 3

Total Posts: 3

Total Members: 3

Total Topics: 3

OKAY . . .

 

Database ID: 2

Total Forums: 1

Total Posts: 1

Total Members: 1

Total Topics: 1

OKAY . . .

 

it echoes the "Total Forums: X" correct.

 

But at the bottom of the code(full code below)..

 

$query = "UPDATE multi_db SET forums = {$num_rows} WHERE id = '$dbidd'";
$result = mysql_query($query) or die(mysql_error());

 

It only updates the first, and sets forums to 3 and leaves the second db blank, where it should set it to 1, as seen in the echo..

 

Any ideas? Its giving me a headache lol.

 

 

Thanks

 

Full code if needed:

 

Now Updating <b>Databases</b> . . .
<br /><br /><br />
<?php
require('../multi_operations/db_connect.php');

$get_dbs = mysql_query("SELECT * FROM multi_db");
while($row = mysql_fetch_array($get_dbs)){

$dbidd = $row['id'];

$multi_forums2 = mysql_query("SELECT sum(posts) FROM multi_forums WHERE db = '$dbidd'") or die(mysql_error());
$row3 = mysql_fetch_array($multi_forums2);
$totaldbposts = $row3["sum(posts)"];

$multi_forums2 = mysql_query("SELECT sum(members) FROM multi_forums WHERE db = '$dbidd'") or die(mysql_error());
$row3 = mysql_fetch_array($multi_forums2);
$totaldbmembers = $row3["sum(members)"];

$multi_forums2 = mysql_query("SELECT sum(topics) FROM multi_forums WHERE db = '$dbidd'") or die(mysql_error());
$row3 = mysql_fetch_array($multi_forums2);
$totaldbtopics = $row3["sum(topics)"];

$result = mysql_query("SELECT * FROM multi_forums WHERE db = '$dbidd'");
$row = mysql_fetch_array($result);

$num_rows = mysql_num_rows($result);

echo 'Database ID: ';
echo $dbidd;
echo '<br />';
echo 'Total Forums: ';
echo $num_rows;
echo '<br />';
echo 'Total Posts: ';

if($totaldbposts == ''){
echo "0";
}else{
echo $totaldbposts;
}

echo '<br />';
echo 'Total Members: ';

if($totaldbmembers == ''){
echo "0";
}else{
echo $totaldbmembers;
}

echo '<br />';
echo 'Total Topics: ';

if($totaldbtopics == ''){
echo "0";
}else{
echo $totaldbtopics;
}
echo '<br />';
echo '<span style="color:green; font-weight:bold">OKAY . . .</span>';
echo '<br />';
echo '<br />';

if($totaldbposts == ''){
$query = "UPDATE multi_db SET posts = 0 WHERE id = '$dbidd'";
$result = mysql_query($query) or die(mysql_error());
}else{
$query = "UPDATE multi_db SET posts = {$totaldbposts} WHERE id = '$dbidd'";
$result = mysql_query($query) or die(mysql_error());
}

if($totaldbmembers == ''){
$query = "UPDATE multi_db SET members = 0 WHERE id = '$dbidd'";
$result = mysql_query($query) or die(mysql_error());
}else{
$query = "UPDATE multi_db SET members = {$totaldbmembers} WHERE id = '$dbidd'";
$result = mysql_query($query) or die(mysql_error());
}

if($totaldbtopics == ''){
$query = "UPDATE multi_db SET topics = 0 WHERE id = '$dbidd'";
$result = mysql_query($query) or die(mysql_error());
}else{
$query = "UPDATE multi_db SET topics = {$totaldbtopics} WHERE id = '$dbidd'";
$result = mysql_query($query) or die(mysql_error());
}

$query = "UPDATE multi_db SET forums = {$num_rows} WHERE id = '$dbidd'";
$result = mysql_query($query) or die(mysql_error());


}
?>

Link to comment
https://forums.phpfreaks.com/topic/105639-update-issue-i-think/
Share on other sites

Ive tired:

 

 

<?php
require('../multi_operations/config_inc.php');

$result = mysql_query("SELECT * FROM multi_db");

while($result = mysql_query("SELECT * FROM multi_db")){


$dbidd = $row['id'];

$num_rows = mysql_num_rows($result);


$query = "UPDATE multi_db SET forums = '{$num_rows}' WHERE id = '$dbidd'";
$result = mysql_query($query) or die(mysql_error());

}

?>

 

It updates them correct, just never page never stops after that..

Link to comment
https://forums.phpfreaks.com/topic/105639-update-issue-i-think/#findComment-541372
Share on other sites

It updates them correct, just never page never stops after that..

 

Of course it never stops because the call to mysql_query() your using as the expression to evaluate in your while never equals false.

 

Try...

 

<?php

require('../multi_operations/config_inc.php');

if ($result = mysql_query("SELECT * FROM multi_db")) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      $dbidd = $row['id'];
      $num_rows = mysql_num_rows($result);
      $query = "UPDATE multi_db SET forums = '{$num_rows}' WHERE id = '$dbidd'";
      $result = mysql_query($query) or die(mysql_error());
    }
  }
}

?>

 

And please, you need to indent your code so it is readable.

Link to comment
https://forums.phpfreaks.com/topic/105639-update-issue-i-think/#findComment-541380
Share on other sites

<?php

require('../multi_operations/config_inc.php');

if ($result = mysql_query("SELECT * FROM multi_db")) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      $dbidd = $row['id'];
      $num_rows = mysql_num_rows($result);
      $query = "UPDATE multi_db SET forums = '{$num_rows}' WHERE id = '$dbidd'";
      $result = mysql_query($query) or die(mysql_error());
    }
  }
}

?>

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/azxo/public_html/multi_control/cron395.php on line 319

 

And please, you need to indent your code so it is readable.

 

Thank you and advice taken!

Link to comment
https://forums.phpfreaks.com/topic/105639-update-issue-i-think/#findComment-541382
Share on other sites

My fault.

 

<?php

require('../multi_operations/config_inc.php');

if ($result = mysql_query("SELECT * FROM multi_db")) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      $dbidd = $row['id'];
      $num_rows = mysql_num_rows($result);
      $query = "UPDATE multi_db SET forums = '{$num_rows}' WHERE id = '$dbidd'";
      if (!mysql_query($query)) {
        die(mysql_error());
      }
    }
  }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/105639-update-issue-i-think/#findComment-541384
Share on other sites

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.