javascript - Defining A Variable With the Result of the Previous, And Are There Better Ways To Go About It? -


i'm writing web page generates list of blog posts, along associated data (such timestamps , previews of articles), , i'm attempting generate unique variable every blogpost generation increments one.

in order this, i've created variable called "name" on line 59, , take string "dtartnum" , concatenate integer of loop, maximum of i, or variable $sqlindex (which index of number of articles in database).

on line 60, have variable want define result of variable name, , assign value of $sqlindex (with result_of_name being placeholder result of name each time it's defined). reason (based on other articles on stack overflow i've read) php executes during page load (roughly).

in line of logic, means php variables become inaccessible, , have procedural generated , stored locally php generates page.

later on, i'm planning on using ajax library i've found post variable page (which has yet created) act "id" (which primary key) rows in mysql database have (so recall row , associated information page). on other page, i'd have template , fill-in-the-blank mysql query waiting "id" of row page i've pasted above.

looking through stack overflow, i've found similar in bash, however, seeing languages syntactically , functionally different, couldn't find of application in js. not find closer js.

so, in summary, question this:

how define variable under "name" value of variable name? i.e. if name = "potato"; variable under potato = $sqlindex;

and, guess in extension

is there better way go this? there structurally improved? please let me know can use future projects.

the code in question towards bottom of heredoc, above commented-out block.

if need me add anything, let me know.

the code:

     <?php         $conn = new mysqli($servername, $username, $password, $db);         //check connection         if ($conn->connect_error){           die("error: ". $conn->connect_error);         }         else{           //nothing,         }         $rowcountsql= "select id writeups order id;";         if ($result=$conn->query($rowcountsql))           {           // return number of rows in result set           $rowcount=mysqli_num_rows($result);           }         ($sqlindex = 0; $sqlindex <= $rowcount; $sqlindex++){           if ($result = $conn->query("select * writeups limit ".$sqlindex.", 1;")){             if ($count = $result->num_rows){             //  echo "the row count query ",$count,"<br>";               while($row = $result->fetch_object()){               $titlecontent =  $row->title;               $writeupcontent = $row->body;               $rowdateandtime = $row->dateandtime;               $article_number = $sqlindex + 1;               echo $str=<<<article               <div class="article">                 <div class="titleanddate">                   <h2>$titlecontent</h2>                   <h3 class="dtartnum">written $rowdateandtime, article number $article_number</h3>                 </div>                 <div class="truncate">                   <p class="writeup">                     $writeupcontent                   </p>                   <a href="templatepage.php" onmouseenter="assigncookie()">read more...</a>                   <script>                   function assigncookie(){                     //total nr in list                    window.alert(document.getelementsbyclassname("article").length);                     //pos in list , definition of variable per button                     (i=0; i<=sqlindex;i++){                       var name = "dtartnum"+i;                       var result_of_name = $sqlindex;                       window.alert(result_of_name);//how work?                     }                   /* code developed later, suppose... need fix above first                     window.alert(dtartnum);                     var pattern = /article number \d{1,3}/;                       if(pattern.test(document.getelementsbyclassname(dtartnum).value)){                         window.alert(pattern.test(document.getelementsbyclassname(dtartnum).value));                       }                       else{                         window.alert(getelementsbyclassname(dtartnum).value);                       }*/                   }                   </script>                 </div>               </div>     article;               }             }           }         }         ?> 

this should it...

var name = "potato";  this[name] = $sqlindex;  alert(potato); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -