Tag: php
-
how to handle dynamic multiple checkbox in php
<?php if($_SERVER[‘REQUEST_METHOD’]==’POST’) { $str=””; // if the chkbox selected then selected checkbox values are come otherwise its not come foreach($_POST[‘chkbox’] as $chkbox) { $str .=$chkbox.”,”; } echo $str; echo substr($str,0,-1);//remove last one char (, comma) from this string } ?> <!– suppose you have dynamic checkbox. Those comes from database . So, you can use…
-
Remove the elements from array in php
<?php $String_array=array(“a”,”b”,”c”,”d”); $string_search=”c”; echo “<pre>”; print_r($String_array); /* OUTPUT OF print_r($string_array); Array ( [0] => a [1] => b [2] => c [3] => d ) Now, We have to remove “c” value of element [2] from array */ unset($String_array[array_search($string_search, $String_array)]); /* * From Above code : * first search the element from the array using…
-
Rotate Image using Jquery & PHP
Many Library available for rotating the image object. But, here we are rotating the image object using Jquery, Ajax and PHP. Here using PHP GD library for rotating the image object. There are many options to rotate the image object. But, here we using simple method. Note: In this example We used jpeg format Image.…
-
Multi Dimensional array search in php
<?php function md_search($arr, $searched) { if (empty($searched) || empty($arr)) { return false; } foreach ($arr as $key => $value) { $exists = true; foreach ($searched as $skey => $svalue) { $exists = ($exists && IsSet($arr[$key][$skey]) && $arr[$key][$skey] == $svalue); } if($exists){ return $key; } } return false; } $arr = array(); $arr[] = array(‘color’=>’red’, ‘qty’=>3);…
-
how to use json in php?
//test.php <script type=”text/javascript” src=”http://code.jquery.com/jquery-2.1.0.min.js”></script> <input type=”button” name=”show” id=”show” value=”Click TO Show Data ” /> <br> Json Encode Data : <div id=”json_output” style=”border:#000 1px solid;width:337px;height:337px;overflow:auto”> </div> Json Output Data of output variable : <div id=”json_output_variable” style=”border:#000 1px solid;width:337px;height:337px;overflow:auto”> </div> <script type=”text/javascript”> $(“#show”).click(function (){ var datastr=’format=json&id=37′; $.ajax({ type:’POST’, data:datastr, url:’json.php’, success:function(html) { $(“#json_output”).html(html); var obj=JSON.parse(html);//decode the json…
-
what is the diffrence between echo ‘$a’, echo “$a” and echo $a?
$a=”Hello”; echo $a; // hello echo ‘$a’; // $a echo “$a”; // hello
-
what is the difference between $a and $aa?
$a=’hello’; $$a = ‘php’; $$$a=’world’; echo “$a ${$a} ${${$a}}”; Output : ==>hello php world More Information : http://www.php.net/manual/en/language.variables.variable.php
-
How to read html table tag in php?
<?php // new dom object $dom = new DOMDocument(); //load the html $html = $dom->loadHTMLFile(“test.html”); //discard white space $dom->preserveWhiteSpace = false; //the table by its tag name $tables = $dom->getElementsByTagName(‘table’); //get all rows from the table $rows = $tables->item(0)->getElementsByTagName(‘tr’); // loop over the table rows foreach ($rows as $row) { // get each column by…
-
how to working with two database in php/mysql?
//connection file //tested in php 5.3.5 & mysql 5.5.8 //make sure database username & database host are same at same place… $host=”localhost”; $dbnm=’db1′; $dbunm=’root’; $dbpass=”; $conn=mysql_connect($host,$dbunm,$dbpass); $db=mysql_select_db($dbnm,$conn); //==================================================================// $host_=”localhost”; $dbnm_=’db2′; $dbunm_=’root’; $dbpass_=”; $conn_=mysql_connect($host_,$dbunm_,$dbpass_); mysql_select_db($dbnm_,$conn_) or die(mysql_error()); //============== Example =============================// $sql=”select * from db1.test”; $re=mysql_query($sql) or die(mysql_error()); $sql_=”select * from db2.test”; $re_=mysql_query($sql_); //join query between two database’s tables….…
