Tuesday, August 25, 2015

get current url query string and change then redirect. (modifying URL in PHP)

lets say your current url is
abcd.com/index.php?r=employee_list&search=sudhir&l1=0&l2=5

where l1= limit 1
and  l2= limit 2

you want to make pagination and want to change the limit 1 value.

code

$_GET['l1']=6;
$queryString = http_build_query($_GET, '', '&');

now  your query is r=employee_list&search=sudhir&l1=6&l2=20

header ("Location: http://abcd.com/".$queryString ); // redirect to same page with new range

Sunday, August 23, 2015

how to find total number of record with limit parameter in mysql

#1          
  $stmt = $this->link->prepare("SELECT *,(SELECT COUNT(*) FROM clients) total_count                  FROM clients LIMIT 0, 10");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rowcount = $rows[0]['total_count'];
echo $rowcount; // return total number of row
                print_r($rows);  // return data



#2

$query = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM table WHERE name LIKE 'a%' LIMIT 0,50");
$query_count = mysql_query("SELECT FOUND_ROWS()");
$result = mysql_fetch_array($query_count);
$total_num_rows = $result[0];

/* HERE IS YOUR CODE PARCING THE RESULTS OF MAIN QUERY */

#3 using PDO

 $query = $this->link->query("SELECT SQL_CALC_FOUND_ROWS * FROM clients LIMIT 0,50");
 $query_count = $this->link->query("SELECT FOUND_ROWS()");
 $result = $query_count->fetchAll(PDO::FETCH_ASSOC);
 $total_num_rows = $result[0];
 print_r($total_num_rows);

Wednesday, August 19, 2015

find any elemnts height and width in object formate using javascript

<code>
<script>
var ul = $('.TokensContainer');
var p=ul.outerWidth(Math.max(ul.width('').outerWidth()));
alert('height is - '+p[0]['clientHeight']);
console.log(p);
</script>
</code>
must check in console.log

Thursday, August 13, 2015

How to detect when that enter key is pressed inside a TextBox or somewhere else ?

How to detect when that enter key is pressed inside a TextBox or somewhere else ?




$('form input').live("keypress", function(e) {
        if (e.keyCode == 13) {
//put your logic here
             alert('enter key has been pressed inside the textbook');
            return false; // prevent the button click from happening
        }
});


Thursday, July 23, 2015

How to create customized unique id like YouTube video id


Dear friend,
Some time we need to generate unique id for your clietns. we can use mysql generator id if we need to use that Id in printing.

for example.
you are creating bill for your client. you need to mention client id. if you will enter client id -:1, it wont look good.

so i write some code to achieve this goal.

Code 1-: 

function idGenerator1($length) {
  $random = '';
  for ($i = 0; $i < $length; $i++) {
    $random .= chr(rand(ord('a'), ord('z')));
  }
  $random .= rand(0, 1) ? rand(0, 9) : chr(rand(ord('a'), ord('z')));
  return  strtoupper($random);
}