SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Incrementing for each page that is in a database using JavaScript

    I am wanting to increment 0707185109 for each page that is in a database table. Each incremented number should be able to be displayed later on in the code. I also need to be to determine which incremented number belongs to what page. Can someone please help me with the above? Thanks in advance.

    This is as far I have got with coding the above:
    Code PHP:
    require "config.php";
    $query = mysql_query("SELECT COUNT(page_title) FROM pages") or die ("Could not query because: ".mysql_error());
    // count how many pages (page_title) there are
    while($row = mysql_fetch_array($query)){
    	$count = $row['COUNT(page_title)'];
    }
    Code JavaScript:
    // first increment 0707185109
    var num = <?php echo $count; ?>;
    for (var i=0707185109; i<num; i++) {
    	// store the increment in a variable
    	mm_0 = document.write(i + "_0");
    }
    However the code is not working for me.

  2. #2
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey

    You should store the values into an array e.g

    Code JavaScript:
    // first increment 0707185109
    var num = <?php echo $count; ?>;
    var mm_0 = new Array(); //make mm_0 an array
    var j = 0; //array counter
    for (var i=0707185109; i<num; i++) {   
          // store the increment in a variable    
          mm_0[j] = i + "_0";
          j++;
    }
    I would not advise using document.write unless you want to rewrite the entire page! It will clear whatever content you had previously scripted.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •