NinethSense oWnZ mE!: Praveen’s drawing book

Choose a Topic:

Fri
25
Apr '08

How PHP can help you improve your PHP coding skills?

By default you will have below setting in php.ini file:

error_reporting = E_ALL & ~E_NOTICE

This means, show all error except notices and coding standard warnings

Comment/remove it and and use only E_ALL in your php.ini file.

error_reporting = E_ALL

This you can achieve through your php source files also. But you will not remember to add this all time. I bet.
Thu
21
Feb '08

SQL Server 2005 Driver for PHP

SQL Server 2005 Driver for PHP CTP (Community Technology Preview - February 2008) is avaialble for download.

Click here to download.



You can visit the SQL Server 2005 Driver for PHP Team Blog at http://blogs.msdn.com/sqlphp/
Wed
16
Jan '08

Random quotes with PHP

I wrote a quick program for displaying random quotes in my forum signatures ;)
I share the code with you below

	// Random Quotes with PHP
	// Praveen - ninethsense
	// 16 January 2008
	
	header(“Content-type: image/png”);
	$file = file(“quotes.txt”);
	$txt = $file[rand(1, count($file)-1)];
	$txt = substr($txt,0,strlen($txt)-2);
	$im = imagecreate((strlen($txt)*8),15);
	$bgcolor = imagecolorallocate($im, 230, 230, 230);
	imagecolortransparent($im,$bgcolor);
	$col = imagecolorallocate($im, 0, 0, 0);
	imagestring($im, 2, 0, 0, $txt, $col);
	imagepng($im);
	imagedestroy($im);


Here is the demo: (try refresh)

http://www.ninethsense.com/quote/quote.php
Thu
15
Nov '07

punBB plugin - Remove Users

I wrote a punBB plugin for one of my forum. This administrator plugin allows you to remove multiple users along with their posts. You can download the plugin from http://www.ninethsense.com/content/view/57/51/
Fri
5
Oct '07

Dynamic varialbes from text file - PHP

This code snippet demonstrates how to read a resource file and convert them to php variables:

< ?_php
$arr = file(“resource.txt”);
foreach ($arr as $key => $value) {
	$arr = split(\t,$value); // tab delimeted. You can use any.
	$$arr[0] = $arr[1];
}
	
//Example - "name" is a word in text tile with ‘tab’ delimeted sample text. 
echo $name;
?>


Sample resource.txt file: (tab delimeted)
 
txt_title	hello world
txt_message	this is a message
name	Contact
Fri
1
Jun '07

Download any file from ASP.NET

You know, some formats (txt, gif etc.) will be shown on the browser rather than downloading when we try. Below is the script which will help you to download any file.


 
        Response.Clear();
        Response.AddHeader(“Content-disposition”, “attachment; filename=<filename>”);
        Response.WriteFile(“C:\</filename><filename>”);
        Response.End();
</filename>


The same logic is used in any server language.
Tue
29
May '07

Microsof Access Database (MDB) from PHP

This code demonstrates how to access a Microsoft Access Database (MDB) from PHP. Here I used PHP 5 for testing.


 
< ?_php
 
/* This example shows how to open and do operations on a Microsoft Access Database using PHP odbc functions */
 
$db_connection = odbc_connect(“DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=E:\root\php\DataBase.mdb”, “ADODB.Connection”, “password”, “SQL_CUR_USE_ODBC”);
 
echo “<hr><b>Show all tables</b><br /><br />”;
$result = odbc_tables($db_connection);
 
while (odbc_fetch_row($result)) {
    if(odbc_result($result,“TABLE_TYPE”)==“TABLE”) {
        echo “<br />” . odbc_result($result,“TABLE_NAME”);
    }
} 
echo “<hr /><b>SELECT code, comment from Degree</b><br /><br />”;
 
$res = odbc_exec($db_connection,“SELECT *FROM Degree”);
 
 
 
 
 
$i = 0;
while (odbc_fetch_row($res)) {
	$arr = odbc_fetch_array($res,$i);
	echo “<br />” . $arr[“code”] . “, “. $arr[“comment”];
	$i++;
}
 
echo “<br /><br /><b>Number of rows = $i</b><br /><br />”;
 
odbc_close($db_connection);
?>
 
Tue
22
May '07

Choosing the right programming language

My students used to ask me “which programming language is the best?” and “which programming language I must learn?”. But the truth is – one cannot give an accurate answer for this. If somebody answers to this question simply - like C++ or Java, I will say he is a frog living inside a well. He may be giving this answer from his experience and knowledge, which is very less.


Check my latest article at : http://ninethsense.com/content/view/51/55/
Thu
25
May '06

Dynamic loading of content in a Dropdown box - without Ajax - Part II

This is same as my previous blog “Dynamic loading of content in a Dropdown box - without Ajax - Part I”, but I have used PHP with MySQL connectiviry for doing this.
 
  <select name=“cmbBusiCategory” id=“cmbBusiCategory” onChange=“ChangeValues()”>
   </select><br /><br />
  <select name=“cmbSubCategory” id=“cmbSubCategory”>
   </select>
< ?_php
	require_once “db_common.inc”;
	db_connect();
	$res = mysql_query(“select * from category where parent_id=0 and language_id=1″);
	$i=0;
	echo “<script language=’javascript’>\n;
 
	while($row = mysql_fetch_assoc($res)){
		echo “cmbBusiCategory.options[$i] =  new Option(”“.$row[”name“].”“);\n;
		echo “cmbBusiCategory.options[$i].value = “ . $row[“id”] . “;\n;
		
		$s1[$i] = $row[“id”]; 
		
		$res2 = mysql_query(“select * from category where parent_id=”.$row[“id”].” and language_id=1″);
		
		echo “menu”.$row[“id”] . “= new Array();\n;
		$j = 0;
		while($row2 = mysql_fetch_assoc($res2)){
			echo “menu”.$row[“id”] .“[”.$j.“]” .“=”” . $row2[”name“] . ““;\n;
			$j++;
		}
		
		$i++;
	}
 
	echo “function ChangeValues() {\n;
	echo “submenu = new Array();\n;
	echo “cmbSubCategory.options.length = 0;\n;
	echo “switch (cmbBusiCategory.value) {\n;
	for($i=0;$i< count($s1);$i++) {
		echo “case “” . $s1[$i] . ““:” . “submenu = menu” . $s1[$i] .“;break;”;
	}
	echo “}\n;
	echo “for (i=0;i<submenu.length;i++) {\n;
	echo “cmbSubCategory.options[i] =  new Option(submenu[i]);\n;
	echo “cmbSubCategory.options[i].value =  i;\n;
	echo “}\n;
	echo “}\n;
	echo “ChangeValues();”;
	echo “</script>”;
?>
 
Tue
21
Mar '06

Simple Paging feature with PHP and MySQL

This is not a full-featured code, but you can develop it to one.
Simple Paging feature with PHP and MySQL
 
< _?php
	$db = mysql_connect(“localhost”,“root”);
	mysql_select_db(“test”);
 
	$pagesize = 2;
	$res = mysql_query(“select *from test”);
	$totalrecs = mysql_num_rows($res);
	if (!isset($firstrec)) $firstrec = 0;	
	if 	(isset($_REQUEST[‘action’])) {
		$firstrec = $_REQUEST[‘firstrec’];
		switch ($_REQUEST[‘action’]) {
			case “prev”: 
				if ($firstrec > 0)
					$firstrec-= $pagesize ; 
				break;
			case “next”: 
				if ($firstrec < $totalrecs-$pagesize ) 
					$firstrec+=$pagesize; 
				break;
		}
	}
 
	$res = mysql_query(“select *from test limit “ . $firstrec . “, “ . $pagesize);
	
	while ($row = mysql_fetch_assoc($res)) {
		echo “<br>” . $row[“id”] . ” “ . $row[“name”];
	}
?>
<br /><br />
<table width=“475″ border=“1″>
  <tr>
    <td width=“60″><a href=“/index.php?firstrec=< ?=$firstrec ?>&action=prev”>Prev</a></td>
    <td width=“327″ align=“center”>
< _?php
		$res = mysql_query(“select *from test”);
		for ($i=0;$i< (mysql_num_rows($res)/$pagesize);$i++) {
			if ($firstrec== $i*$pagesize) 
				echo “<b>” . $i . ” | “ ;
			else
				echo “<a href=’”.$_SERVER[‘PHP_SELF’].“?firstrec=” . ($i*$pagesize) .“&action=number’>$i</a> | “ ; 
		}
?>		
	</td>
    <td width=“66″><a href=“/index.php?firstrec=< ?=$firstrec ?>&action=next”>Next</a></td>
  </tr>
</table>
The CodeProject Microsoft Developer Network Official ASP.NET Forums Microsoft .NET Framework Community Microsoft Most Valuable Professional Kidoos forums Microsoft Visual Studio Developer Home Professional Information Technology Solutions Microsoft Research Home Trivandrum Microsoft Users Group Community Website