Hello friends! In the last section I had told you about the function called mysql_fetch_array(). Today let us see the example based on that. Suppose that a webpage is there where you are taking some inputs from user, now that input is to be shown to authorize person right? For that only we use mysql_fetch_array() function, this function fetches the value array from the database. How to use this function?
In this application you can see that names of the employee are just displayed. This a dynamic page where data is coming from database. How to do this?
Firstly you should have to write a SELECT SQL command for selecting database. After that you have to declare a variable, and store this mysql_fetch_array() in that variable. In fact you have to store the SQL command in a variable. Now, how to declare a variable in PHP? We declare variable C programming language as “int a;” here we will not declare the like this. We will just use the $ sign the name of the variable that’s it. Now, how to fetch the values from the database? For this you have to use while loop. Write a statement according to your choice, for this you have to create your own logic. Hope this much knowledge is enough. If face any problem please feel free to ask.
PLACE OF KNOWLEDGE
Its a knowledge base blog.Where people can to know more about Website design.And i hope to get some jobs in PHP and Mysql
Friday, June 25, 2010
Tuesday, June 22, 2010
Hello Friends!!
Today lets talk about mysql_fetch_array()
mysql_fetch_array() is a function used in MySQL.While developing applications on PHP, it neccessary to have a good knowledge about the structured query language too.This mysql_fetch_array() is a function of SQl,basically a command. It returns an array that corresponds to the fetched row and moves the internal data pointer ahead. Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. The type of returned array depends on how result_type is defined. By using MYSQL_BOTH (default), you'll get an array with both associative and number indices. Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works). Let me explain you with an example.
Example. mysql_fetch_array() with MYSQL_NUM
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Name: %s", $row[0], $row[1]);
}
mysql_free_result($result);
?>
Example. mysql_fetch_array() with MYSQL_ASSOC
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("ID: %s Name: %s", $row["id"], $row["name"]);
}
mysql_free_result($result);
?>
Example. mysql_fetch_array() with MYSQL_BOTH
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("ID: %s Name: %s", $row[0], $row["name"]);
}
mysql_free_result($result);
?>
There is one more function that is mysql_fetch_row() . IT fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
mysql_data_seek():- moves the internal row pointer of the MySQL result associated with the specified result identifier to point to the specified row number. The next call to a MySQL fetch function, such as mysql_fetch_assoc(), would return that row.
I think this much knowledge is enough. I'll show an application on this tomorrow. Guys Keep commenting on my blog. You can get a lot of knowledge on this blog. And knowledge is very important in life. See you tomorrow.
Today lets talk about mysql_fetch_array()
mysql_fetch_array() is a function used in MySQL.While developing applications on PHP, it neccessary to have a good knowledge about the structured query language too.This mysql_fetch_array() is a function of SQl,basically a command. It returns an array that corresponds to the fetched row and moves the internal data pointer ahead. Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. The type of returned array depends on how result_type is defined. By using MYSQL_BOTH (default), you'll get an array with both associative and number indices. Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works). Let me explain you with an example.
Example. mysql_fetch_array() with MYSQL_NUM
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Name: %s", $row[0], $row[1]);
}
mysql_free_result($result);
?>
Example. mysql_fetch_array() with MYSQL_ASSOC
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("ID: %s Name: %s", $row["id"], $row["name"]);
}
mysql_free_result($result);
?>
Example. mysql_fetch_array() with MYSQL_BOTH
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("ID: %s Name: %s", $row[0], $row["name"]);
}
mysql_free_result($result);
?>
There is one more function that is mysql_fetch_row() . IT fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
mysql_data_seek():- moves the internal row pointer of the MySQL result associated with the specified result identifier to point to the specified row number. The next call to a MySQL fetch function, such as mysql_fetch_assoc(), would return that row.
I think this much knowledge is enough. I'll show an application on this tomorrow. Guys Keep commenting on my blog. You can get a lot of knowledge on this blog. And knowledge is very important in life. See you tomorrow.
Saturday, June 19, 2010
As I told you yesterday, that today I will show another application with which you can apply for leave on line. So let’s see how it is done.
Yesterday we learned to make an application with which user can register there attendance online. I told you that with that one more application is added which allow you for applying leave. You have add a link on the attendance application page, so when ever any user sign in. it means u get a id i.e., an unique number. because you kept a record of all username and password. So it quite obvious that you would have maintained an extra field called id. from there you will get the id records so you use it and make page for user. Its up to that you make a dynamic page or static. but i advise you make dynamic page. As i made it. where you can ask user what kind of leave he want? For many days, he/she wanted to be on leave? etc., keep a submit button. And when user clicks that submit button that all record will go into the database. After That you make page for the authorized who will sanctioned the leave. For That you have use a command in PHP, which is called my_fetch_array(). I tell you about this tomorrow. Till Then keep reading my Blog. And keep commenting too.
Yesterday we learned to make an application with which user can register there attendance online. I told you that with that one more application is added which allow you for applying leave. You have add a link on the attendance application page, so when ever any user sign in. it means u get a id i.e., an unique number. because you kept a record of all username and password. So it quite obvious that you would have maintained an extra field called id. from there you will get the id records so you use it and make page for user. Its up to that you make a dynamic page or static. but i advise you make dynamic page. As i made it. where you can ask user what kind of leave he want? For many days, he/she wanted to be on leave? etc., keep a submit button. And when user clicks that submit button that all record will go into the database. After That you make page for the authorized who will sanctioned the leave. For That you have use a command in PHP, which is called my_fetch_array(). I tell you about this tomorrow. Till Then keep reading my Blog. And keep commenting too.
Friday, June 18, 2010
A very good afternoon to you all. So as I said yesterday, that from today onwards I’ll start sharing my knowledge on PHP and MySql and on Website Designing with you all, so lets start.
First of all we have to understand what is PHP? Acronym for "PHP: Hypertext Preprocessor". The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Don't be afraid reading the long list of PHP's features. You can jump in, in a short time, and start writing simple scripts in a few hours. Although PHP's development is focused on server-side scripting, you can do much more with it. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others. PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, and many others. I think this much knowledge is enough, but if you want more knowledge you can ask me.
Today I’ll show you an application and tell you how it is created. So lets start. For every organization it is most important to make a record of attendance of every employee working. But how to do is the question? You can make the record on a Copy. But how many pages will you waste for this. Let us build small application for this where individual can sign in and register their attendance for the day. So, without wasting time let me show you that application.
So let’s start with login page. In this application login page is very important because in this case every individual attendance will be recorded. For creating login page you have first creating database in MySQL. Where you will store the username and password. You can name database according to your choice, but remember the name. You have to create a registration page using html, with this registration page you will register username and password.Each person should have unique username and password. You have to create three field or tupples in your database, username, password and id. You should have to allot primary key to id field and you can also make it auto increment. With username and password, user will sign in and can register for the day. Remember when he register his/her attendance he/she is recording their in time. And after registering there in time, next time when they sign in they will see the out time page, where they have to register there out time. You guys were confused, how this could happen? Yes it’s possible; you have to write small code for this. In fact you have to check from the database that the person who logged in has made registered earlier or not, a small SQL code for searching from database. So if the person has not registered earlier he/she will see the in time page and if he/she has registered earlier, then out time page will be displayed to him. One more feature is also added to it, i.e. leave application page. It’s a feature where you will get to apply for leave online.
I’ll tell you about this application tomorrow. So don’t forget to read my blog tomorrow. And if anything you didn’t understand in this section you are free to question. See you tomorrow. And please leave your comments too. Have a nice day.
First of all we have to understand what is PHP? Acronym for "PHP: Hypertext Preprocessor". The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Don't be afraid reading the long list of PHP's features. You can jump in, in a short time, and start writing simple scripts in a few hours. Although PHP's development is focused on server-side scripting, you can do much more with it. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others. PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, and many others. I think this much knowledge is enough, but if you want more knowledge you can ask me.
Today I’ll show you an application and tell you how it is created. So lets start. For every organization it is most important to make a record of attendance of every employee working. But how to do is the question? You can make the record on a Copy. But how many pages will you waste for this. Let us build small application for this where individual can sign in and register their attendance for the day. So, without wasting time let me show you that application.
So let’s start with login page. In this application login page is very important because in this case every individual attendance will be recorded. For creating login page you have first creating database in MySQL. Where you will store the username and password. You can name database according to your choice, but remember the name. You have to create a registration page using html, with this registration page you will register username and password.Each person should have unique username and password. You have to create three field or tupples in your database, username, password and id. You should have to allot primary key to id field and you can also make it auto increment. With username and password, user will sign in and can register for the day. Remember when he register his/her attendance he/she is recording their in time. And after registering there in time, next time when they sign in they will see the out time page, where they have to register there out time. You guys were confused, how this could happen? Yes it’s possible; you have to write small code for this. In fact you have to check from the database that the person who logged in has made registered earlier or not, a small SQL code for searching from database. So if the person has not registered earlier he/she will see the in time page and if he/she has registered earlier, then out time page will be displayed to him. One more feature is also added to it, i.e. leave application page. It’s a feature where you will get to apply for leave online.
I’ll tell you about this application tomorrow. So don’t forget to read my blog tomorrow. And if anything you didn’t understand in this section you are free to question. See you tomorrow. And please leave your comments too. Have a nice day.
Thursday, June 17, 2010
Hey! Friends First of all i would like to welcome you all on my blog. Friends after a long thinking session, finally i have decide to start share my knowledge on PHP And MySql with you guys. Actually I got craze in website after my projects which I did for my final year of my college. Which is also called as minor and major project. Their i made whole application for an organisation that project got selected too, and they started running on their servers. And that craze went on increasing. So guys from today you will find extra ordinary work done by me on PHP and MySql . I have decided start my small business in website design too. I am hoping to get some work through this. So from today onwards I am gonna post my works. and screen shots of my work.
Subscribe to:
Posts (Atom)