Skip to main content

Posts

Looping through the MySql result set using php

Looping through the MySQL result set using mysqli_fetch_array function in php. *Note: $con is DB connection object. //Executing the sql query and storing result into $query variable. $query = mysqli_query($con,"select * from user_coins where date >= '$calDate' AND `isBonusCalculated`='0' "); //Checking if result set having rows more than 0. if(mysqli_num_rows($query)>0){      // looping th' the result set using mysqli_fetch_array function.     while($row=mysqli_fetch_array($query)){         echo  $row['userid'];         echo $row['balance'];     } } else { echo "No data found"; }

Creating and maintainng transaction log file using php.

 Create and maintain the transaction logs in text file using php.  *Note:  1. log.txt should be created manually & proper path to be added into $file variable. 2. This file will concatenate the new content at the end of file.   //Defining the file path. You can add full file path if its in other directory. $file = 'log.txt'; $timeStamp = date("Y-m-d H:i:s");  // Open the file and store existing content into $fileContent variable. $fileContent = file_get_contents($file);  // Append a new log to the $fileContent variable. $fileContent .= "transaction happened at-- $timeStamp \n"; // add the content to file. file_put_contents($file, $fileContent);

Simple copy to clipboard button using javascript.

Simple click to copy button to copy value of textbox to clipboard.   //Add this function inside head tag <script>     function copyText() {         /* Get the text field */         var copyText = document.getElementById("myInput");         /* Select the text field */         copyText.select();         /* Copy the text inside the text field */         document.execCommand("copy");         /* Alert the copied text */         alert("Copied");         }     </script> //Inside html file <textarea value="" id="myInput" rows="1" cols="75">This value will be copies</textarea>  //Button to trigger copy action <button onc...