Find the Factorial of number in 2 ways using PHP

Iterative way of finding factorial of a given number

<?php
function fact($number)
{  
  $factorial = 1;
  for($k=1;$k&<=$number;$k++)
  {
    $factorial = $factorial *$k;
  }
return $factorial;
}
echo "Factorial ".fact(5);
?>

Recursive way of finding factorial of a given number

<?php
 function fact($number)
  {
   if($number<=1)
     {return 1;}
   else
    {return $number*factorial($number-1);}
  }
 echo "Factorial ".fact(5);
?>

How to find the length of an associative array in javascript

Associative array is an array with named indexes. In Javascript, there is no concept called associative arrays. In javascript we call them as objects.

Below is an example to find the length of the object.

var employee = [];
employee['first name'] = 'Raju';
employee['name'] = 'Raghu';
employee['age'] = 28;
var length = Object.keys(employee).length;

How to fetch and display values from database (MySQL) using php

<?php
  $con = mysqli_connect("localhost", "username","pswd","dbname");
    // Check connection
  if (mysqli_connect_errno())
  {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  else
  {
    $query ="SELECT * FROM employee_table ORDER BY ID DESC";  
    $result = mysqli_query($con, $query); 
    while($row = mysqli_fetch_array($result))
   { 
     echo "<table><tr><th>firstname</th><th>lastname</th><th>gender</th></tr><tr><td>".$row['frame']."</td>".$row["lname"]."<td>".$row['gender']."</td></tr></table>";  
  }
}
?>

How to concatenate strings in javascript

<html>
<script type = "text/javascript">
function function1()
{
 var string1 = "First string";
 var string2 = "Second string";
 var string3 = string1.concat(string2);
 document.getElementById("str").innerHTML = "concatenated string" + string3;
}
</script>
<body>
 <div id="str"></div>
 <button onClick = "function1()">Click here</button>
</body>
</html>

How to load and retrieve values from the existing NetSuite search

var array1=new Array();
var search1=search.load
({ id:'searchid'});
// Run paged version of search with 1000 results per page
var myData = search1.runPaged({
  "pageSize": 1000
});
myData.pageRanges.forEach(function(pageRange){
  // Fetch the results on the current page
  var myPage1 = myData.fetch({index: pageRange.index});
  // Iterate over the list of results on the current page 
  myData.data.forEach(function(result1){      
  // Process the individual result    
  var columns=result1.columns;
array1.push([result1.getValue(columns[0]),result1.getValue(columns[1]),result1.getValue(columns[2]),result1.getValue(columns[4]),result1.getValue(columns[5])]);
});
});     
log.audit("array length",array1.length);    

How to set sublist value of the record

var cRecord = scriptContext.newRecord;
var itemcount = theRecord.getLineCount({sublistId: 'item'});
for ( var k=0; (itemcount >= 0) && (k < itemcount); k++ )
 {
  cRecord.setSublistValue
  ({
   sublistId: "item",
   fieldId: "location",
   value: "location1",
   ignoreFieldChange: true,
   fireSlavingSync: true,
   line: k
 });
}

How to create search using Suite script

var arrFilters = [
 search.createFilter
 ({
   name : 'tranid',
   operator : search.Operator.EQUALTO,
   values :  11111 //this is internal id which we want to search
 }),
 search.createFilter
 ({ 
  name : 'isinactive',
  operator : search.Operator.IS, 
 values :  'F'    
 })
]; 
var arrColumns = [
 search.createColumn({name : 'internalid'}),
 search.createColumn({name : 'itemid'}) 
];    
var search1 = search.create({
  type : search.Type.TRANSFER_ORDER,
  columns : arrColumns,
  filters : arrFilters
 });  
var results = search1.run();
results.each(function(result){
 log.debug('Result', result.id);
}); 
                        
Design a site like this with WordPress.com
Get started