cturner Posted August 8, 2007 Share Posted August 8, 2007 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 More sharing options...
nogray Posted August 9, 2007 Share Posted August 9, 2007 make sure your number is bigger than 0707185109 or the for loop won't run Link to comment https://forums.phpfreaks.com/topic/63978-storing-an-increment-in-a-variable/#findComment-318963 Share on other sites More sharing options...
gurroa Posted August 9, 2007 Share Posted August 9, 2007 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 https://forums.phpfreaks.com/topic/63978-storing-an-increment-in-a-variable/#findComment-319304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.