Jump to content

Storing an increment in a variable


cturner

Recommended Posts

I am wondering if someone could please tell me how I could store an increment in a variable? I need to be able to display that variable later on in my code. Thanks in advance.

 

This is as far as I have got:

<?php
// php code is here
require "config.php";
$query = mysql_query("SELECT COUNT(page_title) FROM pages") or die ("Could not query because: ".mysql_error());
//$num_rows = mysql_num_rows($query);
// count how many pages (page_title) there are
while($row = mysql_fetch_array($query)){
$count = $row['COUNT(page_title)'];
}
?>
// javascript code is here
var num = <?php echo $count; ?>;
for (var i=0707185109; i<num; i++) {
document.write(i);
}

The above code doesn't work for me. It is not printing the increment.

Link to comment
https://forums.phpfreaks.com/topic/63978-storing-an-increment-in-a-variable/
Share on other sites

Try it this way.
<?php
  // php code is here
  require "config.php";

  $query = mysql_query("SELECT COUNT(page_title) AS cnt FROM pages") or die ("Could not query because: ".mysql_error());
  $row = mysql_fetch_array($query);
  $count = isset($row['cnt']) ? $row['cnt'] : 0;

  if ($count > 707185109) {
?>
for (var i = 707185109; i < <?php echo $count; ?>; ++i) 
  document.write(i);
delete i;
<? 
  }
?>

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.