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
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;
<? 
  }
?>

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.