tag:blogger.com,1999:blog-57250164077435835112026-04-17T00:37:20.638-07:00Sukesh Balachandrans blogThis blog is to publish my small ideas...Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.comBlogger36125tag:blogger.com,1999:blog-5725016407743583511.post-50507037343251953152019-07-21T01:59:00.000-07:002019-07-22T01:33:13.900-07:00Django Docker Installation<div dir="ltr" style="text-align: left;" trbidi="on"> This blog is to explain Django&nbsp; Docker installation. Docker is a software platform to create, deploy and manage virtualized application containers on a common operating system, with an ecosystem of allied tools.<br /> <br /> First follow these steps to install Docker in Ubuntu.<br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -<br /> <br /> sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"<br /> <br /> sudo apt-get update<br /> <br /> sudo apt-get install -y docker-ce</div> <br /> <br /> Next, install Docker Compose by running these<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose<br /> <br /> sudo chmod +x /usr/local/bin/docker-compose</div> <br /> <br /> Next we are going to install Django in Docker.<br /> <br /> Create a directory named <b>docker_first</b> somewhere in your home directory.<br /> Create a file named <b>Dockerfile</b> in it. Add the following lines to it and save.<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> FROM python:3<br /> ENV PYTHONUNBUFFERED 1<br /> RUN mkdir /code<br /> WORKDIR /code<br /> COPY requirements.txt /code/<br /> RUN pip install -r requirements.txt<br /> COPY . /code/</div> <br /> <br /> <br /> Create a file named <b>requirements.txt</b> in the same location. Add the following lines into it.<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> Django&gt;=2.0,&lt;3.0<br /> psycopg2&gt;=2.7,&lt;3.0</div> <br /> <br /> Create another file named <b>docker-compose.yml</b><br /> Add the following code into it<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> version: '3'<br /> <br /> services:<br /> &nbsp; db:<br /> &nbsp; &nbsp; image: postgres<br /> &nbsp; web:<br /> &nbsp; &nbsp; build: .<br /> &nbsp; &nbsp; command: python manage.py runserver 0.0.0.0:8000<br /> &nbsp; &nbsp; volumes:<br /> &nbsp; &nbsp; &nbsp; - .:/code<br /> &nbsp; &nbsp; ports:<br /> &nbsp; &nbsp; &nbsp; - "8000:8000"<br /> &nbsp; &nbsp; depends_on:<br /> &nbsp; &nbsp; &nbsp; - db</div> <br /> <br /> <br /> Next, create a Django project by run this<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> sudo docker-compose run web django-admin startproject composeexample .</div> <br /> <br /> Run this command to change the file permissions<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> sudo chown -R $USER:$USER .</div> <br /> <br /> Edit the <b>composeexample/settings.py</b> file. Copy following lines in place of DATABASES<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> DATABASES = {<br /> &nbsp; &nbsp; 'default': {<br /> &nbsp; &nbsp; &nbsp; &nbsp; 'ENGINE': 'django.db.backends.postgresql',<br /> &nbsp; &nbsp; &nbsp; &nbsp; 'NAME': 'postgres',<br /> &nbsp; &nbsp; &nbsp; &nbsp; 'USER': 'postgres',<br /> &nbsp; &nbsp; &nbsp; &nbsp; 'HOST': 'db',<br /> &nbsp; &nbsp; &nbsp; &nbsp; 'PORT': 5432,<br /> &nbsp; &nbsp; }<br /> }</div> <br /> <br /> Add 'localhost' in ALLOWED_HOSTS in the same settings.py. It will look like this<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> ALLOWED_HOSTS = ['localhost']</div> <br /> <br /> Run the following command in the docker_first directory<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> sudo docker-compose up</div> <br /> <br /> Now open <b>http://localhost:8000</b> to check the installation. Thank you<br /> <br /> Watch the video tutorial here (Click the gear icon and select video quality to 1080p HD, then click the full screen button for good quality)<br /> <br /> Go to this link to subscribe to my YouTube channel to stay updated:-&nbsp;<a href="https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw" style="color: #00997f;">https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw&nbsp;</a><br /> <br /> <br /> <iframe allowfullscreen="allowfullscreen" height="349" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" src="https://www.youtube.com/embed/YOYYUe1h1vI" style="text-align: center;" webkitallowfullscreen="webkitallowfullscreen" width="600"> </iframe> <br /> <br /></div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com1tag:blogger.com,1999:blog-5725016407743583511.post-7639127958795113792018-09-16T05:48:00.002-07:002018-09-16T05:52:47.281-07:00Load initial data into Django model<div dir="ltr" style="text-align: left;" trbidi="on"> <b>T</b>his article explains pre-populating or seeding the core tables in django with initial data. It may be helpful to insert tables like status,employee types automatically while port source code from one place to another. Example situations like copy code from development server to production server. You can provide this&nbsp; initial data with migrations or fixtures.<br /> <br /> Here I am explaining about load data using fixtures. A fixture is a collection of data that Django knows how to import into a database. Fixtures can be written as JSON, XML or YAML formats. This tutorial is based on JSON fixture. This tutorial is writing in django 2 but it works fine with django 1.11 also. I am using Ubuntu 16.<br /> <br /> These are the steps ,first create a file named <b>fixtures.json</b> then write the data in json format, then run the command to write this data into database.<br /> <br /> First, we need a django project. For that, create a directory named <b>my_proj</b> somewhere in your home directory. Open that folder, then open a terminal window in that location. Then run these commands to install Django.<br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> virtualenv -p python3 env<br /> source env/bin/activate<br /> pip install Django </div> <br /> <br /> Then create a project named my_proj and app named my_app by run following commands<br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> django-admin startproject my_proj .<br /> django-admin startapp my_app</div> <br /> <br /> For detailed tutorial about installing Django locally, then create a project go to this link:- <a href="http://newprograminglogics.blogspot.com/2018/02/install-python-3-and-set-up-local.html" style="color: #00997f;">http://newprograminglogics.blogspot.com/2018/02/install-python-3-and-set-up-local.html</a><br /> <br /> Open my_proj/my_proj/settings.py then add&nbsp; <b>'my_app' </b>to the <b>INSTALLED_APPS</b> section. Now it will look like this<br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> INSTALLED_APPS = [<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.admin',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.auth',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.contenttypes',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.sessions',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.messages',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.staticfiles',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'my_app'<br /> ]</div> <br /> <br /> The project is configured now. We need to create two sample models named <b>Status</b> and <b>Employee_type</b>.<br /> For this add the following code in <b>my_proj/my_proj/my_app/models.py</b><br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> class Status(models.Model):<br /> &nbsp; &nbsp; name = models.CharField(max_length=200)<br /> &nbsp; &nbsp; meta_name = models.CharField(max_length=200)<br /> <br /> &nbsp; &nbsp; class Meta:<br /> &nbsp; &nbsp; <span style="white-space: pre;"> </span>db_table = 'status'<br /> <br /> <br /> <br /> class Employee_type(models.Model):<br /> &nbsp; &nbsp; name = models.CharField(max_length=200)<br /> &nbsp; &nbsp; meta_name = models.CharField(max_length=200)<br /> <br /> &nbsp; &nbsp; class Meta:<br /> &nbsp; &nbsp; <span style="white-space: pre;"> </span>db_table = 'employee_type'</div> <br /> <br /> Run these commands to create the actual tables in the database.<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> python manage.py makemigrations<br /> python manage.py migrate</div> <br /> <br /> Create a directory named <b>fixtures</b> in <b>my_proj/my_proj/my_app</b> directory. Then create a file named <b>fixtures.json</b> inside this directory.<br /> Open this file and paste the following code in it<br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> <br /> [<br /> &nbsp; {<br /> &nbsp; &nbsp; "model": "my_app.Status",<br /> &nbsp; &nbsp; "pk": 1,<br /> &nbsp; &nbsp; "fields": {<br /> &nbsp; &nbsp; &nbsp; "name": "Pending",<br /> &nbsp; &nbsp; &nbsp; "meta_name": "pending"<br /> &nbsp; &nbsp; }<br /> &nbsp; },<br /> &nbsp; {<br /> &nbsp; &nbsp; "model": "my_app.Status",<br /> &nbsp; &nbsp; "pk": 2,<br /> &nbsp; &nbsp; "fields": {<br /> &nbsp; &nbsp; &nbsp; "name": "Approved",<br /> &nbsp; &nbsp; &nbsp; "meta_name": "approved"<br /> &nbsp; &nbsp; }<br /> &nbsp; },<br /> &nbsp; {<br /> &nbsp; &nbsp; "model": "my_app.Status",<br /> &nbsp; &nbsp; "pk": 3,<br /> &nbsp; &nbsp; "fields": {<br /> &nbsp; &nbsp; &nbsp; "name": "Rejected",<br /> &nbsp; &nbsp; &nbsp; "meta_name": "rejected"<br /> &nbsp; &nbsp; }<br /> &nbsp; },<br /> <br /> <br /> &nbsp; {<br /> &nbsp; &nbsp; "model": "my_app.Employee_type",<br /> &nbsp; &nbsp; "pk": 1,<br /> &nbsp; &nbsp; "fields": {<br /> &nbsp; &nbsp; &nbsp; "name": "Admin",<br /> &nbsp; &nbsp; &nbsp; "meta_name": "admin"<br /> &nbsp; &nbsp; }<br /> &nbsp; },<br /> &nbsp; {<br /> &nbsp; &nbsp; "model": "my_app.Employee_type",<br /> &nbsp; &nbsp; "pk": 2,<br /> &nbsp; &nbsp; "fields": {<br /> &nbsp; &nbsp; &nbsp; "name": "Staff",<br /> &nbsp; &nbsp; &nbsp; "meta_name": "staff"<br /> &nbsp; &nbsp; }<br /> &nbsp; }<br /> ]</div> <br /> <br /> <br /> Look into the json data each element contains three fields named model,pk,fields. As the name says they are the model name, id of table row and fields of the table row respectively. In the model field the my_app represents the app name Status,Employee_type are the models.<br /> <br /> Our fixture is ready now. Run this command to insert this fixture to the tables we created earlier<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> python manage.py loaddata fixtures.json</div> <br /> <br /> Here we are using sqlite db so open db.sqlite3 file in <b>my_proj</b> directory using a sqlite browser software.<br /> Check the status and employee_type tables. The values provided in the fixtures.json is inserted into the tables.<br /> <br /> You can download the example source code from here:-<br /> <a href="https://dl.dropboxusercontent.com/s/dhrqxgkjuzlwze6/my_proj.zip%EF%BB%BF" style="color: #00997f;">https://dl.dropboxusercontent.com/s/dhrqxgkjuzlwze6/my_proj.zip</a><br /> <br /> Watch the video tutorial here (Click the gear icon and select video quality to 1080p HD, then click the full screen button for good quality)<br /> <br /> Go to this link to subscribe to my YouTube channel to stay updated:- <a href="https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw" style="color: #00997f;">https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw&nbsp;</a><br /> <br /> <iframe allowfullscreen="allowfullscreen" height="349" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" src="https://www.youtube.com/embed/3ryK7e7mFJE" style="text-align: center;" webkitallowfullscreen="webkitallowfullscreen" width="600"> </iframe> </div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com1tag:blogger.com,1999:blog-5725016407743583511.post-31433735093781074842018-08-02T12:32:00.003-07:002018-08-05T01:18:26.429-07:00Django jwt authentication example with angular 5<div dir="ltr" style="text-align: left;" trbidi="on"> When thinking about token authentication for our rest apis first think coming to our mind is JWT. JSON Web Token or JWT is a JSON-based open standard for creating access tokens that can use for purposes like rest api authentication.<br /> <br /> This article contains a django application structure with jwt authentication, angular 5 and bootstrap 4 in front end.&nbsp; This example uses django rest framework to create rest apis, and django-rest-framework-jwt for jwt authentication.<br /> <br /> This example uses renowned professional angular 5 admin template SB admin. So it can be used as a starting point for your small or big scale projects. This example app will work fine with both Django 2 and 1.11 versions. I am using Ubuntu 16 for creating this example.<br /> <br /> You can download the source code from this link:-<br /> <a href="https://dl.dropboxusercontent.com/s/bd7bv2agd8y04q2/admin_proj.zip" style="color: #00997f;">https://dl.dropboxusercontent.com/s/bd7bv2agd8y04q2/admin_proj.zip</a><br /> <br /> Follow these steps to configure the example.<br /> Download and extract the project. Then open a terminal window in the root directory of the project.<br /> <br /> First, we need to create a virtual environment to run our project<br /> <br /> For Django 1.11 run this command<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> virtualenv env </div> <br /> <br /> For Django 2 run this command<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> virtualenv -p python3 env</div> <br /> <br /> Then run the following command to activate the virtual environment<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> source env/bin/activate</div> <br /> <br /> Read this article for detailed description about creating virtual enviornments:- <a href="http://newprograminglogics.blogspot.com/2018/02/install-python-3-and-set-up-local.html" style="color: #00997f;">http://newprograminglogics.blogspot.com/2018/02/install-python-3-and-set-up-local.html</a><br /> <br /> After that install django and related packages by run these commands<br /> <br /> For Django 1.11<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> pip install certifi==2018.4.16<br /> pip install Django==1.11<br /> pip install django-cors-headers==2.4.0<br /> pip install djangorestframework==3.8.2<br /> pip install djangorestframework-jwt==1.11.0<br /> pip install PyJWT==1.6.4<br /> pip install pytz==2018.5</div> <br /> <br /> For Django 2<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> pip install certifi==2018.4.16<br /> pip install Django==2.0.7<br /> pip install&nbsp; django-cors-headers==2.3.0<br /> pip install djangorestframework==3.8.2<br /> pip install djangorestframework-jwt==1.11.0<br /> pip install PyJWT==1.6.4<br /> pip install pytz==2018.5</div> <br /> <br /> Then run these to migrate database<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> python manage.py makemigrations <br /> python manage.py migrate</div> <br /> <br /> Run this command to start django development server<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> python manage.py runserver</div> <br /> <br /> Make sure that the django development server is running at 8000 port.<br /> Our backend is configured now.<br /> <br /> Now open <b>front_end</b> directory in the project folder<br /> open a terminal in that directory then run<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> npm install</div> <br /> Have any problems while install packages then use <b>sudo</b><br /> <br /> After all packages installed run<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> ng serve</div> <br /> <br /> Now the front end is available at <b>http:127.0.0.1:4200</b><br /> Open this in any browser. Click the register button, then create a user.<br /> You can see the dashboard. Now start to add your custom functionalities.<br /> <br /> Watch the video tutorial here&nbsp;<b>(Click the gear icon and select video quality to 1080p HD, then click the full screen button for good quality)</b><br /> <b><br /></b> Go to this link to subscribe to my YouTube channel to stay updated:-&nbsp;<a href="https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw" style="color: #00997f;">https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw</a><br /> <br /> <iframe allowfullscreen="allowfullscreen" height="349" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" src="https://www.youtube.com/embed/62WaIAGhlVc" style="text-align: center;" webkitallowfullscreen="webkitallowfullscreen" width="600"> </iframe><br /> <b><br /></b></div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com4tag:blogger.com,1999:blog-5725016407743583511.post-12725595193389875352018-06-23T09:04:00.012-07:002021-12-21T00:11:29.662-08:00Integrate bootstrap template in Django 2<div dir="ltr" style="text-align: left;" trbidi="on"> This article explains how to integrate a bootstrap&nbsp; template in Django. I am using renowned bootstrap admin template SBAdmin in this tutorial.This tutorial is written in Ubuntu 16.04.<br /> <br /> Watch the demo here:- <b>(Click the gear icon and select video quality to 1080p HD, then click the full screen button for good quality)</b><br /> <b><br /></b> Go to this link to subscribe to my YouTube channel to stay updated:-&nbsp;<a href="https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw" style="color: #00997f;">https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw</a><br /> <br /> <iframe allowfullscreen="allowfullscreen" height="349" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" src="https://www.youtube.com/embed/qHqh26paLaI" style="text-align: center;" webkitallowfullscreen="webkitallowfullscreen" width="600"> </iframe><br /> <br /> A bootstrap theme may have many dependencies like bootstrap library, jquery and other javascript plugins and css files.<br /> So integrate these all to a Django project is something tricky.<br /> <br /> We need to load the dependent libraries as static files. Then create parent templates for admin pages and normal pages. Copy body sections of each page in the template, then paste it into equivalent pages in our project. Then set view functions and urls correctly. I am explaining all these steps in this tutorial.<br /> To download the full source file go to end of the tutorial.<br /> <br /> First, create a directory named <b>admin_proj </b>somewhere in your home directory. Open that folder, then open a terminal window in that location. Then run these commands to install Django.<br /> <br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> virtualenv -p python3 env<br /> source env/bin/activate<br /> pip install Django</div> <br /> Then create a project named <b>admin_proj</b> and app named <b>admin_app</b> by run following commands<br /> <br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> django-admin startproject admin_proj .<br /> django-admin startapp admin_app</div> <br /> For detailed tutorial about installing Django locally, then create a project go to this link:-&nbsp;<a href="http://newprograminglogics.blogspot.com/2018/02/install-python-3-and-set-up-local.html" style="color: #00997f;">http://newprograminglogics.blogspot.com/2018/02/install-python-3-and-set-up-local.html</a><br /> <br /> Open admin_proj/admin_proj/settings.py then add&nbsp; 'admin_app' to the INSTALLED_APPS section.</div><div dir="ltr" style="text-align: left;" trbidi="on"> <br /> Next open admin_proj/admin_proj/urls.py.<br /> Add an <b>include</b> keyword in the line from django.urls import path<br /> <br /> Now it will look like<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> from django.urls import path,include</div> <br /> Add this line in the urlpatterns section<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> path('admin_app/', include('admin_app.urls')) </div> <br /> <br /> Now download SBAdmin 2 template files from this link, <a href="https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/archive/gh-pages.zip">https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/archive/gh-pages.zip</a><br /> Then extract the zip file.<br /> <br /> It is the time to load these template files to our Django project as static files.<br /> For this check following line is included in the INSTALLED_APPS section of admin_proj/admin_proj/settings.py<br /> <b>'django.contrib.staticfiles'</b><br /> <br /> Then check this line is exist in the same settings.py file<br /> <b>STATIC_URL = '/static/'</b><br /> <br /> Go to this link, for the detailed tutorial about load static files: -&nbsp; <a href="http://newprograminglogics.blogspot.com/2018/03/load-static-files-in-django-20.html" style="color: #00997f;">http://newprograminglogics.blogspot.com/2018/03/load-static-files-in-django-20.html</a><br /> <br /> Then create a folder named <b>static</b> in admin_app folder.<br /> Create a folder named <b>admin_app</b> inside it. Then copy vendor,dist,data directories from the extracted SBAdmin directory to admin_proj/admin_app/static/admin_app directory.<br /> Now the static directory will look like this<br /> ├── migrations<br /> ├── static<br /> │&nbsp; &nbsp;└── admin_app<br /> │&nbsp; &nbsp; &nbsp; &nbsp;├── data<br /> │&nbsp; &nbsp; &nbsp; &nbsp;├── dist<br /> │&nbsp; &nbsp; &nbsp; &nbsp;└── vendor<br /> <br /> All js and css files are now in correct location. Now we can create some templates to display.<br /> <br /> In the admin_app folder, create a folder named <b>templates</b> Create another folder named <b>admin_app</b> in it. I am going to create two base templates. One for admin pages with sidebar and header and another for login and regular pages without sidebar and header. Create a file named admin.html<br /> <br /> Now the templates directory will look like this<br /> <br /> ├── migrations<br /> ├── static<br /> ├── templates<br /> │&nbsp; &nbsp;└── admin_app<br /> │&nbsp; &nbsp; &nbsp; &nbsp;├── admin.html<br /> <br /> <br /> Open index.html in pages directory of downloaded SBAdmin theme. Copy and paste the contents to admin.html. Delete the content inside the div with id "page-wrapper".<br /> <br /> Now add the code inside "page-wrapper" div.<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> {% block content %}{% endblock %}</div> <br /> <br /> Our admin template is ready now. Now we can create a child html file to consume&nbsp; this template.<br /> Create a file named dashboard.html in the same location of admin.html. Once again open index.html in pages directory of downloaded SBAdmin theme. Copy the content inside "page-wrapper" div and paste to dashboard.html<br /> <br /> Then add these line in top of the same file.<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> {% extends "admin_app/admin.html" %}<br /> {% block content %}</div> <br /> <br /> Add this code at the bottom of the file<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> {% endblock %}</div> <br /> Now we are going to change the source url of script files.<br /> ../vendor/jquery/jquery.min.js should change to<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> {% static 'admin_app/vendor/jquery/jquery.min.js' %}</div> <br /> <br /> Similarly ../data/morris-data.js should change to<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> {% static 'admin_app/data/morris-data.js' %}</div> <br /> <br /> Do this for all js files and css files. You should add this line in the top of the file<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> {% load static %}</div> <br /> <br /> Copy all scripts into &lt;head&gt; section. Keep only common scripts and css like jquery.js and bootstrap.js in admin.html. Move other scripts like morris-data.js into dashboard.html. Because it is only needed on the dashboard page.<br /> <br /> Add the same code at the top of dashboard.html also<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> {% load static %}</div> <br /> <br /> Then change the sidebar menu urls like this {% url 'admin_app:index' %} in admin.html.<br /> This will create a url to localhost:8000/admin_app .We hadn't created any urls yet, but we will create it later.<br /><br /> <br /> Now we have created an admin.html template and a file named dashboard.html which consume the admin.html.<br /> In the same way you can create equivalent pages for every page in the downloaded theme like buttons.html,forms.html, flot.html, gridhtml,icons.html etc.<br /> <br /> In the same manner create another template named front_end.html and page named login.html from login.html page of downloaded theme.<br /><br /> <br /> Open admin_proj/admin_app/views.py. Then add this code<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> def index(request):<br /> &nbsp; &nbsp; return render(request, 'admin_app/dashboard.html')</div> <br /> <br /> This means the view function named index return the contents of dashboard.html. Similarly create functions for all other pages we created earlier.</div><div dir="ltr" style="text-align: left;" trbidi="on"><br /> Now create a file named urls.py in the same location of views.py, then add these code<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> from django.urls import path<br /> <br /> from . import views<br /> <br /> app_name = 'admin_app'<br /> urlpatterns = [<br /> &nbsp; &nbsp; path('', views.index, name='index')<br /> ]</div> <br /> <br /> In this code path('', views.index, name='index') means that call to root url should call the index function in views.py.<br /> Similarly, connect all views functions to equivalent urls.<br /> <br /> Done we have successfully integrated a bootstrap template to Django. Now run python manage.py runserver, the open http:localhost:8000/admin_app in any browser.<br /> <br />If you don't have time to execute all the steps mentioned&nbsp; above you can buy the example source&nbsp; code from here:-&nbsp;<span style="color: #04ff00;">&nbsp;<a href="https://payhip.com/b/I3sTL">https://payhip.com/b/I3sTL</a></span><br /> <br /> After download completed, extract the folder to somewhere on your computer, then open a terminal window inside the extracted project directory. Then run the following commands<br /> <div style="background: rgb(204, 255, 255); border-radius: 8px; border: 2px solid rgb(0, 0, 0); padding: 10px 40px;"> virtualenv -p python3 env<br /> <br /> source env/bin/activate<br /> <br /> pip install django<br /> <br /> python manage.py runserver</div> <br /> <br /> Then open <b>http://127.0.0.1:8000/admin_app</b> in any browser.<br /> <br /> <br /></div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com9tag:blogger.com,1999:blog-5725016407743583511.post-80570964474463081182018-05-01T00:16:00.002-07:002018-08-14T11:59:46.716-07:00Django chat application<div dir="ltr" style="text-align: left;" trbidi="on"> <div dir="ltr" style="text-align: left;" trbidi="on"> This article is about how to create a chat application or chat server using Django 2.0. This chat system depends Python 3 and Django restframework to create rest apis. Jquery ajax is using to call the api from the client side. I am using Ubuntu 16.04 to create this tutorial.<br /> <br /> You can download the example source code from here:- <a href="https://dl.dropboxusercontent.com/s/obt4u4udlt30k8w/chatproj.zip">https://dl.dropboxusercontent.com/s/obt4u4udlt30k8w/chatproj.zip</a><br /> <br /> After download completed, extract the folder to somewhere on your computer, then open a terminal window inside the extracted project directory. Then run the following commands to create a virtual environment and activate.<br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> virtualenv -p python3 env<br /> <br /> source env/bin/activate</div> <br /> <br /> For complete details about create a virtual environment read this article:- <a href="http://newprograminglogics.blogspot.com/2018/02/install-python-3-and-set-up-local.html">http://newprograminglogics.blogspot.com/2018/02/install-python-3-and-set-up-local.html</a><br /> <br /> Then install Django by run this command<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> pip install django</div> <br /> <br /> Then install Django rest framework<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> pip install djangorestframework</div> <br /> <br /> Then run these commands to create migrations<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> python manage.py makemigrations chatapp<br /> <br /> python manage.py migrate</div> <br /> <br /> All configurations completed. Now start the server using this command<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> python manage.py runserver</div> <br /> <br /> To check the functionality open http://127.0.0.1:8000/index in any browser<br /> For reduce complexity I am not using a user login. You can simply login to chat by using your name or nickname without any log up process.<br /> <br /> Enter your name like John , Peter in the From text box. Open the same url http://127.0.0.1:8000/index in another tab, type another name in it.<br /> You can see the online users in the right column. Click one of the Names, you can see a chat box is opened. You can write messages in it and send to the selected user.</div> <br /> Watch the video tutorial <b>(Click the gear icon and select video quality to 1080p HD, then click the full screen button for good quality)</b><br /> <b><br /></b> Go to this link to subscribe to my YouTube channel to stay updated:-&nbsp;<a href="https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw" style="color: #00997f;">https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw</a><br /> <br /> <iframe allowfullscreen="allowfullscreen" height="349" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" src="https://www.youtube.com/embed/J9KmyZM99Tg" style="text-align: center;" webkitallowfullscreen="webkitallowfullscreen" width="600"> </iframe><br /> <br /></div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com20tag:blogger.com,1999:blog-5725016407743583511.post-69468449944342794012018-03-06T10:45:00.002-08:002018-08-14T12:00:24.543-07:00Load static files in django 2.0<div dir="ltr" style="text-align: left;" trbidi="on"> This article is about how to serve static files in Django 2.0. Static files means javascript libraries like jquery, css files or images.<br /> Jquery is an essential part of modern web development. When we use the templating system of django we need to do some steps to include jquery to it.<br /> Sometimes you may try to access the static files by some methods it may not work properly and ends up in a 404 error.<br /> <br /> I am explaining the process with an example application. This example includes a button. When click in it it will show an image.<br /> <br /> This tutorial assumes that you have created a virual enviorment and django 2 project with mysite and app with myapp were created.<br /> To read about how to create a virtual enviornment and install django go this link:- <a href="http://newprograminglogics.blogspot.com/2018/02/install-python-3-and-set-up-local.html" style="color: blue;">Install Python 3 and Set Up a Local Programming Environment</a><br /> <br /> Open mysite/mysite/settings.py. Paste following line in the INSTALLED_APPS section<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> 'myapp.apps.MyappConfig'</div> <br /> <br /> Then check following line is included in the INSTALLED_APPS section<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> 'django.contrib.staticfiles' </div> <br /> <br /> Then check this line is exist in the same settings.py file<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> STATIC_URL = '/static/' </div> <br /> <br /> Then create a folder named <b>static</b> in myapp folder.<br /> Create a folder named <b>myapp</b> inside it.<br /> Download jquery and an image in this folder.<br /> <br /> Then in the myapp folder create a folder named <b>templates</b><br /> Create another folder named <b>myapp</b> in it<br /> Then create a file named <b>index.html</b> in it<br /> Then paste the following code in it<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> {% load static %}<br /> &lt;!DOCTYPE html&gt;<br /> &lt;html&gt;<br /> &lt;body&gt;<br /> &lt;img width="400px" height="300px" style="display:none;" id="img" src="{% static 'myapp/flower.jpg' %}"/&gt;<br /> &lt;br/&gt;<br /> &lt;input type="button" value="Show Image" id="btn"/&gt;<br /> &lt;script src="{% static 'myapp/jquery-3.3.1.min.js' %}"&gt;&lt;/script&gt;<br /> &lt;script&gt;<br /> $(document).ready(function(){<br /> <span style="white-space: pre;"> </span>$('#btn').click(function(){<br /> &nbsp; &nbsp; &nbsp; &nbsp; $('#img').show();<br /> <span style="white-space: pre;"> </span>});<br /> });<br /> &lt;/script&gt;<br /> &lt;/body&gt;<br /> &lt;/html&gt; </div> <br /> Don't forget to add the line&nbsp; <b>{% load static %}</b> in the top of the page.<br /> In this code {% static 'myapp/flower.jpg' %} flower.jpg can replace with the image you downloaded in the static folder.<br /> Also in {% static 'myapp/jquery-3.3.1.min.js' %} jquery-3.3.1.min.js can replace with your jquery version.<br /> <br /> Open the file myapp/views.py<br /> Paste the following code in it<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> def index(request):<br /> &nbsp; &nbsp; return render(request, 'myapp/index.html') </div> <br /> <br /> Create a file named<b> urls.py</b> in myapp folder<br /> Then paste the following code in it<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> from django.urls import path<br /> <br /> from . import views<br /> <br /> urlpatterns = [<br /> &nbsp; &nbsp; path('', views.index, name='index')<br /> ] </div> <br /> <br /> Next open Open mysite/mysite/urls.py.<br /> Add an <b>include</b> keyword in the line<br /> from django.urls import path<br /> <br /> Now it will look like<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> from django.urls import path,include </div> <br /> <br /> Add this line in the urlpatterns section<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> path('myapp/', include('myapp.urls')) </div> <br /> <br /> Then run the command in mysite folder<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> python manage.py runserver </div> <br /> Note that you must restart the development server in order to access static files.<br /> Now open the url http://127.0.0.1:8000/myapp in any browser.It will show a button saying Show Image. Click it will show the image.<br /> <br /> Watch the video tutorial <b>(Click the gear icon and select video quality to 1080p HD, then click the full screen button for good quality)</b><br /> <br /> Go to this link to subscribe to my YouTube channel to stay updated:-&nbsp;<a href="https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw" style="color: #00997f;">https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw</a><br /> <br /> <iframe allowfullscreen="allowfullscreen" height="349" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" src="https://www.youtube.com/embed/xAjOK3mKtKU" style="text-align: center;" webkitallowfullscreen="webkitallowfullscreen" width="600"> </iframe><br /> <br /> You can download the example app from here:&nbsp;<a href="https://dl.dropboxusercontent.com/s/zjssc3xgpzmxqnd/mysite.zip" style="color: blue;">https://dl.dropboxusercontent.com/s/zjssc3xgpzmxqnd/mysite.zip</a></div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com3tag:blogger.com,1999:blog-5725016407743583511.post-34197930654292980722018-02-11T04:05:00.001-08:002018-05-12T08:23:27.351-07:00Install Python 3 and Set Up a Local Programming Environment then install Django locally on Ubuntu 16.04<div dir="ltr" style="text-align: left;" trbidi="on"> This article is about installing python 3 virtual environment on Ubuntu 16.04. If you are looking to set up a python 3 development environment, this&nbsp; tutorial will help you.<br /> <br /> First install python 3 by run these commands in the terminal<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> sudo apt-get install python3.5</div> <br /> Then install pip3 the python package manager by running <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> sudo apt-get install python3-pip </div> <br /> Then install virtualenv package <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> sudo pip3 install virtualenv </div> <br /> Then create a directory named <b>my_proj</b> which is our project name in your home directory. Then open a terminal window in that directory. Run the following command to create a virtual environment<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> virtualenv -p python3 env </div> <br /> Then run this command to activate the virtual environment<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> source env/bin/activate </div> <br /> Our virtual environment is activated now. To check it run <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> which python3 </div> <br /> It will give the result&nbsp; &nbsp; <b>/home/sukesh/sukesh/python/my_proj/env/bin/python3</b><br /> <br /> To install Django 2 run this <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> pip install Django </div> <br /> Note that pip, and python commands can be used in our virtual environment instead of pip3 and python3.<br /> <br /> &nbsp;Run this to check django <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> python -m django --version </div> <br /> It will give result&nbsp; &nbsp;<b>2.0.5</b><br /> <br /> Create a sample project by run this. Don't forget the trailing dot(.)<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> django-admin startproject my_proj . </div> <br /> Our project is created now. Run this to create an app<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> django-admin startapp my_app </div> <br /> Now we need to add the created app to our project. For that open <b>my_proj/my_proj/settings.py</b>, then add <b>'my_app' </b>to the&nbsp;<b>INSTALLED_APPS</b> section. Our&nbsp;INSTALLED_APPS will looks like this<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> INSTALLED_APPS = [<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.admin',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.auth',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.contenttypes',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.sessions',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.messages',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'django.contrib.staticfiles',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'my_app'<br /> ] </div> <br /> <br /> You have finished. To start the development server run <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> python manage.py runserver </div> <br /> Our server has started now. To check this open this url in any browser:-&nbsp; <b>http://127.0.0.1:8000 </b><br /> <br /> Watch this video tutorial&nbsp;<b>(Click the gear icon and select video quality to 1080p HD, then click the full screen button for good quality)</b><iframe allowfullscreen="allowfullscreen" height="349" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" src="https://www.youtube.com/embed/mOrOTgciLLw" style="text-align: center;" webkitallowfullscreen="webkitallowfullscreen" width="600"> </iframe><br /> <b><br /></b> Thank You</div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com5tag:blogger.com,1999:blog-5725016407743583511.post-28263450305084606492018-01-31T10:10:00.000-08:002018-08-14T12:01:04.769-07:00Chat application using a database table in PHP - Part 3<div dir="ltr" style="text-align: left;" trbidi="on"> This is the third update of Chat application using a database table in PHP.<br /> This article is the continution of a simple chat application in PHP or web chat application using live chat rest api.<br /> <br /> Previous articles were solution to your doubts like how to create a php chat room or php chat server, or php chat app or php chat box or php chat system.&nbsp;This time I have created rest api for chat.Rest apis using json so now I can call it a json chatbot, json chat server, json chat room or collectively json chat php script.<br /> <br /> By using rest api we can separate back end and front end into separate sections. So implement this chat to other platforms like android will become easy.<br /> <br /> <!--Before going through my php chat application source code you can see this PHP chat application demo here.<br /> <br /> Please open this same page in another tab or another browser to test the chat application.<br /> For reduce complexity I am not using a user login. You can simply login to chat by using your name or nick Name without any log up process.<br /> <br /> Enter your name like Xwe , Yrt , Zty&nbsp; in the From text box.You can see the online users in the right column. Click one of the Names, you can see a chat box is opened. You can write messages in it and send to the selected user.<br /> <iframe height="400" src="https://funbuzzzz.blogspot.com/2018/01/chat-redirect-part-3.html" width="100%"></iframe>--> You can download the complete zip file from this link:-<br /> <a href="https://dl.dropboxusercontent.com/s/8jsal21eo73xrl6/openchat_part3.zip">https://dl.dropboxusercontent.com/s/8jsal21eo73xrl6/openchat_part3.zip</a><br /> <br /> To know how to install and use watch this video.&nbsp;&nbsp;<b>(Click the gear icon and select video quality to 1080p HD, then click the full screen button for good quality)</b><br /> <b><br /></b> Go to this link to subscribe to my YouTube channel to stay updated:-&nbsp;<a href="https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw" style="color: #00997f;">https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw</a><br /> <br /> <iframe allowfullscreen="allowfullscreen" height="349" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" src="https://www.youtube.com/embed/7b5mypJ0IJs" style="text-align: center;" webkitallowfullscreen="webkitallowfullscreen" width="600"> </iframe> Here is the source code for chat application in php<br /> Here have two files index.php and back.php<br /> <br /> <b><u>&nbsp;code</u></b><br /> <b><u>&nbsp;index.php</u></b><br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> &lt;html&gt;<br /> &lt;head&gt;<br /> <span style="white-space: pre;"> </span><br /> &lt;/head&gt;<br /> &lt;body&gt;<br /> <span style="white-space: pre;"> </span>&lt;table width="100%" height="100%" border="1" align="center" valign="center"&gt;<br /> <span style="white-space: pre;"> </span>&lt;tr&gt;&lt;td colspan="2" height="6%"&gt;&lt;h3&gt;Chat Window&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;<br /> <span style="white-space: pre;"> </span>&lt;tr&gt;&lt;td colspan="2" height="6%"&gt; From(Your Name or Id):&amp;nbsp;&amp;nbsp;&lt;input type="text" name="sender" id="sender"&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;<br /> <span style="white-space: pre;"> </span>&lt;tr&gt;&lt;td width='85%'&gt;<br /> <span style="white-space: pre;"> </span>&lt;div id="chat_view" &gt;<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>&amp;nbsp;<br /> <span style="white-space: pre;"> </span>&lt;/div&gt;<br /> <span style="white-space: pre;"> </span>&lt;/td&gt;<br /> <span style="white-space: pre;"> </span>&lt;td&gt;<br /> <span style="white-space: pre;"> </span>&lt;div&gt;Online Users&lt;/div&gt;<br /> <span style="white-space: pre;"> </span>&lt;ul id="users"&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>&lt;/ul&gt;<br /> <span style="white-space: pre;"> </span>&lt;/td&gt;<br /> <span style="white-space: pre;"> </span>&lt;/tr&gt;<br /> &lt;/table&gt;<br /> &lt;div id="chat_list"&gt;&lt;/div&gt;<br /> &lt;style type="text/css"&gt;<br /> .chat_box{<br /> <span style="white-space: pre;"> </span>border-style:solid;<br /> <span style="white-space: pre;"> </span>border-width:medium;<br /> <span style="white-space: pre;"> </span>width:200px;<br /> <span style="white-space: pre;"> </span>height:310px;<br /> <span style="white-space: pre;"> </span>float:left;<br /> <span style="white-space: pre;"> </span>margin-left:2px;<br /> <br /> }<br /> #msg{<br /> <span style="white-space: pre;"> </span>width:200px;<br /> <span style="white-space: pre;"> </span>height:200px;<br /> <span style="white-space: pre;"> </span>overflow:auto;<br /> }<br /> #new_msg_text<br /> {<br /> <span style="white-space: pre;"> </span>width:200px;<br /> <span style="white-space: pre;"> </span>height:50px;<br /> <span style="white-space: pre;"> </span>resize: none;<br /> }<br /> #close_button{<br /> <span style="white-space: pre;"> </span>width:20px;<br /> <span style="white-space: pre;"> </span>height:20px;<br /> <span style="white-space: pre;"> </span>padding-left:2px;<br /> }<br /> #users{<br /> <span style="white-space: pre;"> </span>list-style: none;<br /> <span style="white-space: pre;"> </span>padding:0px;<br /> }<br /> &lt;/style&gt;<br /> <br /> &lt;script type="text/javascript" src="./jquery.1.11.1.js"&gt;&lt;/script&gt;<br /> &lt;script type="text/javascript"&gt;<br /> <span style="white-space: pre;"> </span>$(document).ready(function(){<br /> <span style="white-space: pre;"> </span>window.setInterval(function() {<br /> <span style="white-space: pre;"> </span>viewMsg();<br /> <span style="white-space: pre;"> </span>viewOnlineUsers();<br /> <span style="white-space: pre;"> </span>createNewChatBox();<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>},1000);<br /> <span style="white-space: pre;"> </span>});<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>function creatNewBox(receiver)<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>var newbox ="&lt;div class='chat_box' id='chat_box_"+receiver+"'&gt;"+<br /> <span style="white-space: pre;"> </span>"&lt;div id='chat_header'&gt;&lt;input type='text' style='width:180px;' name='receiver[]' READONLY value='"+receiver+"' id='receiver'&gt;&lt;span onclick='closeWindow($(this))'&gt;X&lt;/span&gt;&lt;/div&gt;"+<br /> <span style="white-space: pre;"> </span>"&lt;div&nbsp; height='20%' id='msg' &gt;"+<br /> <span style="white-space: pre;"> </span>"&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;"+<br /> <span style="white-space: pre;"> </span>"&lt;div id='newmsg'&gt;&lt;textarea rows='4' cols='10' id='new_msg_text'&gt;&amp;nbsp;&lt;/textarea&gt;&lt;/div&gt;"+<br /> <span style="white-space: pre;"> </span>"&lt;div&gt;&lt;input type='button' value='Send' id='btn' onclick='saveMsg($(this))'&gt;&lt;/div&gt;"+<br /> <span style="white-space: pre;"> </span>"&lt;/div&gt;";<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>return newbox;<br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>function createNewChatBox()<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>var sender=$("#sender").val();<br /> <span style="white-space: pre;"> </span>$.ajax({<br /> <span style="white-space: pre;"> </span>type: 'GET',<br /> <span style="white-space: pre;"> </span>url: 'back.php?opt=get_chat&amp;sender='+sender,<br /> <span style="white-space: pre;"> </span>success: function(data){<br /> <span style="white-space: pre;"> </span>if(data.status==true)<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>$('#chat_list').html('');<br /> <span style="white-space: pre;"> </span>data.data.users.forEach(function(user,index){<br /> <span style="white-space: pre;"> </span>if(user.sender!='')<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>$('#chat_list').append("&lt;input type='text' name='chat_users[]' value='"<br /> <span style="white-space: pre;"> </span>+user.sender+"'&gt;");<br /> <span style="white-space: pre;"> </span>viewBox(user.sender);<br /> <span style="white-space: pre;"> </span>}&nbsp; &nbsp; <br /> <span style="white-space: pre;"> </span>});<br /> <br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span>}<span style="white-space: pre;"> </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> <span style="white-space: pre;"> </span>});<br /> <br /> <span style="white-space: pre;"> </span>}<br /> <br /> <span style="white-space: pre;"> </span>function viewBox(receiver)<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>if($.trim($("#sender").val())==$.trim(receiver))<br /> <span style="white-space: pre;"> </span>return;<br /> <span style="white-space: pre;"> </span>$(document).ready(function(){<br /> <span style="white-space: pre;"> </span>var flag=false;<br /> <span style="white-space: pre;"> </span>$("input[name='receiver[]']").each(function(){<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>if($(this).val()==receiver)<br /> <span style="white-space: pre;"> </span>{flag=true;}<br /> <span style="white-space: pre;"> </span>});<br /> <span style="white-space: pre;"> </span>if(flag==false)$("#chat_view").append(creatNewBox(receiver));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> <span style="white-space: pre;"> </span>});<br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>function viewOnlineUsers()<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>var sender=$("#sender").val();<br /> <span style="white-space: pre;"> </span>$.ajax({<br /> <span style="white-space: pre;"> </span>type: 'GET',<br /> <span style="white-space: pre;"> </span>url: 'back.php?opt=view_users&amp;sender='+sender,<br /> <span style="white-space: pre;"> </span>success: function(data){<br /> <span style="white-space: pre;"> </span>if(data.status==true)<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>$('#users').html('');<br /> <span style="white-space: pre;"> </span>data.data.users.forEach(function(user,index){<br /> <span style="white-space: pre;"> </span>if(user.user_id!='')<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>$('#users').append("&lt;li&gt;&lt;a onclick=\"viewBox('"+user.user_id+"')\"&gt;"<br /> <span style="white-space: pre;"> </span>+user.user_id+"&lt;/a&gt;&lt;/li&gt;");<br /> <span style="white-space: pre;"> </span>}&nbsp; &nbsp; <br /> <span style="white-space: pre;"> </span>});<br /> <br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>});<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span>function closeWindow(obj)<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>obj.parent().parent().remove();<br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>function viewMsg()<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>var sender=$("#sender").val();<br /> <span style="white-space: pre;"> </span>$("input[name='receiver[]']").each(function(){<br /> <span style="white-space: pre;"> </span>var receiver=$(this).val();<br /> <span style="white-space: pre;"> </span>$.ajax({<br /> <span style="white-space: pre;"> </span>type: 'GET',<br /> <span style="white-space: pre;"> </span>url: 'back.php?opt=view_msg&amp;sender='+sender+"&amp;receiver="+receiver,<br /> <span style="white-space: pre;"> </span>success: function(data){<br /> <span style="white-space: pre;"> </span>if(data.status==true)<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>$("#chat_box_"+receiver).find("#msg").html('');<br /> <span style="white-space: pre;"> </span>data.data.messages.forEach(function(message,index){<br /> <span style="white-space: pre;"> </span>if(message.user_id!='' &amp;&amp; message.msg!='')<br /> <span style="white-space: pre;"> </span>{<br /> <span style="white-space: pre;"> </span>$("#chat_box_"+receiver).find("#msg").append("&lt;table&lt;tr&gt;"<br /> <span style="white-space: pre;"> </span>+"&lt;td&gt;"+message.user_id+": "+message.msg+"&lt;/td&gt;"<br /> <span style="white-space: pre;"> </span>+"&lt;/tr&gt;&lt;/table&gt;");<br /> <span style="white-space: pre;"> </span>}&nbsp; &nbsp; <br /> <span style="white-space: pre;"> </span>});<br /> <br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>});<br /> <span style="white-space: pre;"> </span>});<br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>function saveMsg(obj)<br /> <span style="white-space: pre;"> </span>{<br /> <br /> <span style="white-space: pre;"> </span>var receiver=obj.parent().parent().find("#receiver").val();<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>var sender=$("#sender").val();<br /> <span style="white-space: pre;"> </span>if(sender=='') return false;<br /> <span style="white-space: pre;"> </span>var msg=obj.parent().parent().find("#new_msg_text").val();<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>$.ajax({<br /> <span style="white-space: pre;"> </span>type: 'POST',<br /> <span style="white-space: pre;"> </span>url: 'back.php?opt=save',<br /> <span style="white-space: pre;"> </span>data: {"receiver":receiver,"sender":sender,"msg":msg},<br /> <span style="white-space: pre;"> </span>success: function(){<br /> <span style="white-space: pre;"> </span>obj.parent().parent().find("#new_msg_text").val('');<br /> <span style="white-space: pre;"> </span>}<br /> <span style="white-space: pre;"> </span><br /> <span style="white-space: pre;"> </span>});<br /> <span style="white-space: pre;"> </span>}<br /> &lt;/script&gt;<br /> <br /> &lt;/body&gt;<br /> &lt;/html&gt;</div> <br /> <br /> <b><u>back.php</u></b><br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> &lt;?php<br /> extract($_POST);<br /> extract($_GET);<br /> $con = new mysqli('localhost', 'root', 'password','chat_db');<br /> <br /> switch ($opt)<br /> {<br /> &nbsp; &nbsp; case "save":&nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; $stmt = $con-&gt;prepare("INSERT INTO chat (sender,receiver,msg,time) values(?,?,?,NOW())");<br /> &nbsp; &nbsp; $stmt-&gt;bind_param("sss", $sender, $receiver, $msg);<br /> &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; break;<br /> <br /> &nbsp; &nbsp; case "view_msg":<br /> &nbsp; &nbsp; $result=array('status'=&gt;false,'data'=&gt;array());&nbsp; <br /> &nbsp; &nbsp; $stmt = $con-&gt;prepare("SELECT chat.*,users.user_id FROM chat&nbsp; LEFT JOIN users ON users.user_id=chat.sender"<br /> &nbsp; &nbsp; &nbsp; &nbsp; ." WHERE (receiver= ? AND sender= ? )"<br /> &nbsp; &nbsp; &nbsp; &nbsp; ." OR (receiver= ? AND sender= ? ) ORDER BY time");<br /> &nbsp; &nbsp; $stmt-&gt;bind_param("ssss", $sender, $receiver, $receiver, $sender);<br /> &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; $r = $stmt-&gt;get_result();<br /> &nbsp; &nbsp; $messages=array();<br /> &nbsp; &nbsp; while ($row = $r-&gt;fetch_assoc()) {<br /> &nbsp; &nbsp; &nbsp; &nbsp; $messages[]=$row;<br /> &nbsp; &nbsp; }<br /> &nbsp; &nbsp; $result['status']=true;<br /> &nbsp; &nbsp; $result['data']['messages']=$messages;<br /> &nbsp; &nbsp; header('content-type:application/json');<br /> &nbsp; &nbsp; echo json_encode($result);<br /> &nbsp; &nbsp; break;<br /> &nbsp; <br /> &nbsp; &nbsp; case "get_chat":<br /> &nbsp; &nbsp; $result=array('status'=&gt;false,'data'=&gt;array());&nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; $stmt = $con-&gt;prepare("SELECT DISTINCT&nbsp; sender from chat ".<br /> &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; WHERE receiver= ? AND AddTime(time, '00:00:15')&gt;=NOW()");<br /> &nbsp; &nbsp; $stmt-&gt;bind_param("s", $sender);&nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; $r = $stmt-&gt;get_result();<br /> &nbsp; &nbsp; $users=array();<br /> &nbsp; &nbsp; while ($row = $r-&gt;fetch_assoc()) {<br /> &nbsp; &nbsp; &nbsp; &nbsp; $users[]=$row;<br /> &nbsp; &nbsp; }<br /> &nbsp; &nbsp; $result['status']=true;<br /> &nbsp; &nbsp; $result['data']['users']=$users;<br /> &nbsp; &nbsp; header('content-type:application/json');<br /> &nbsp; &nbsp; echo json_encode($result);<br /> &nbsp; &nbsp; break;<br /> &nbsp; <br /> &nbsp; &nbsp; case "view_users":<br /> &nbsp; &nbsp; $result=array('status'=&gt;false,'data'=&gt;array());<br /> &nbsp; &nbsp; $stmt = $con-&gt;prepare("SELECT count(*) as count FROM users WHERE user_id= ?");<br /> &nbsp; &nbsp; $stmt-&gt;bind_param("s", $sender);&nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; $r = $stmt-&gt;get_result();<br /> &nbsp; &nbsp; $row = $r-&gt;fetch_assoc();<br /> &nbsp; &nbsp; if($row['count']&gt;0)<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt = $con-&gt;prepare("UPDATE users SET last_visit=NOW() WHERE user_id= ?");<br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;bind_param("s", $sender);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; }<br /> &nbsp; &nbsp; else<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt = $con-&gt;prepare("INSERT INTO users (user_id,last_visit) values(?,NOW())");<br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;bind_param("s", $sender);<br /> &nbsp; &nbsp; }<br /> &nbsp; <br /> &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; $stmt = $con-&gt;prepare("SELECT * FROM users WHERE AddTime(last_visit, '00:00:15')&gt;=NOW()");<br /> &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; $r = $stmt-&gt;get_result();<br /> &nbsp; &nbsp; $users=array();<br /> &nbsp; &nbsp; while ($row = $r-&gt;fetch_assoc()) {&nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; $users[]=$row;<br /> &nbsp; &nbsp; }<br /> &nbsp; &nbsp; $result['status']=true;<br /> &nbsp; &nbsp; $result['data']['users']=$users;<br /> &nbsp; &nbsp; header('content-type:application/json');<br /> &nbsp; &nbsp; echo json_encode($result);<br /> &nbsp; <br /> &nbsp; &nbsp; break;<br /> }<br /> ?&gt;</div> <br /> Here I am using two Mysql tables namely chat and users<br /> <br /> <b><u>chat</u></b><br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg_H4BNdbQT9rUOTp1lac6-FsEBLCL1SAjS27KtSFq2C0pdG5WgF-FtNbw0Qoguqi1U8C6EvLMvd62j7EoqqsLFLlRA6vksWEpQK42iIK_AySwLmomUWNXbnR5i54p7g2Gu_aqPqo0A-ix/s1600/openchat_chat.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="118" data-original-width="153" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg_H4BNdbQT9rUOTp1lac6-FsEBLCL1SAjS27KtSFq2C0pdG5WgF-FtNbw0Qoguqi1U8C6EvLMvd62j7EoqqsLFLlRA6vksWEpQK42iIK_AySwLmomUWNXbnR5i54p7g2Gu_aqPqo0A-ix/s1600/openchat_chat.JPG" /></a></div> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <b><u>users</u></b><br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQLwgozE9AzsIjB_P0r2x9LbCLWOPNxTPpUwUVqengNRqU3D20othyxYGQbav7hLT42OLQ5SYS75DEBehWiWziYBCuTfSUzmDEXw07FSFlzwBn05gndxCZVb4aX_-ADSgGCTNkVTaVbxY/s1600/openchat_users.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="71" data-original-width="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQLwgozE9AzsIjB_P0r2x9LbCLWOPNxTPpUwUVqengNRqU3D20othyxYGQbav7hLT42OLQ5SYS75DEBehWiWziYBCuTfSUzmDEXw07FSFlzwBn05gndxCZVb4aX_-ADSgGCTNkVTaVbxY/s1600/openchat_users.JPG" /></a><br /> <br /> <br /> <br /> <br /> The query to make this tables<br /> <b><u>chat</u></b><br /> CREATE TABLE IF NOT EXISTS `chat` (<br /> &nbsp; `sender` varchar(255) DEFAULT NULL,<br /> &nbsp; `receiver` varchar(255) DEFAULT NULL,<br /> &nbsp; `msg` text,<br /> &nbsp; `time` datetime DEFAULT NULL<br /> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br /> <b><u><br /></u></b> <b><u>users</u></b><br /> CREATE TABLE IF NOT EXISTS `users` (<br /> &nbsp; `user_id` varchar(255) NOT NULL,<br /> &nbsp; `last_visit` datetime NOT NULL<br /> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br /> <br /> You can also read :- <a href="http://newprograminglogics.blogspot.com/2012/07/chat-application-using-database-table.html">Chat application using a database table in PHP - Part 1</a> <br /> <a href="http://newprograminglogics.blogspot.in/2018/01/chat-application-using-database-table.html">Chat application using a database table in PHP - Part 2</a> </div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-86213492631648569462018-01-13T21:00:00.001-08:002018-08-14T12:01:36.600-07:00Chat application using a database table in PHP - Part 2<div dir="ltr" style="text-align: left;" trbidi="on"> This is the second update of Chat application using a database table in PHP.<br /> This article is to describe a simple chat application in PHP or web chat application.<br /> <br /> This article will be a solution to all your doubts like how to create a php&nbsp;chat room or php&nbsp;chat server, or php&nbsp;chat app or php&nbsp;chat box or php&nbsp;chat system. I wrote a php&nbsp;chat script in previous blog now improving that php&nbsp;chat example with prepared statements.<br /> <br /> As you know using prepared statements it will become more secure. Because it can prevent SQL injection attacks.<br /> <br /> <!--Before going through my php chat application source code you can see this PHP chat application demo here.<br /> Please open this same page in another tab or another browser to test the chat application.<br /> For reduce complexity I am not using a user login. You can simply login to chat by using your name or nick Name without any log up process.<br /> <br /> <br /> Enter your name like Xwe , Yrt , Zty&nbsp; in the From text box.You can see the online users in the right column. Click one of the Names, you can see a chat box is opened. You can write messages in it and send to the selected user.<br /> <iframe height="400" src="https://funbuzzzz.blogspot.com/2018/01/chat-redirect-part-2.html" width="100%"></iframe>--> You can download the complete zip file from this link:-<br /> <a href="https://dl.dropboxusercontent.com/s/7td2j2jiahfpfw3/openchat_part2.zip">https://dl.dropboxusercontent.com/s/7td2j2jiahfpfw3/openchat_part2.zip</a><br /> To know how to install and use watch this video.&nbsp;&nbsp;<b>(Click the gear icon and select video quality to 1080p HD, then click the full screen button for good quality)</b><br /> <b><br /></b> Go to this link to subscribe to my YouTube channel to stay updated:-&nbsp;<a href="https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw" style="color: #00997f;">https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw</a><br /> <br /> <iframe allowfullscreen="allowfullscreen" height="349" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" src="https://www.youtube.com/embed/7b5mypJ0IJs" style="text-align: center;" webkitallowfullscreen="webkitallowfullscreen" width="600"> </iframe> Here is the source code for chat application in php<br /> &nbsp;Here have two files index.php and back.php<br /> <b><u><br /></u></b> <b><u>&nbsp;code</u></b><br /> <b><u>&nbsp;index.php</u></b><br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> &lt;html&gt;<br /> &nbsp; &nbsp; &lt;head&gt;<br /> &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &lt;/head&gt;<br /> &nbsp; &nbsp; &lt;body&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;table width="100%" height="100%" border="1" align="center" valign="center"&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;&lt;td colspan="2" height="6%"&gt;&lt;h3&gt;Chat Window&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;&lt;td colspan="2" height="6%"&gt; From(Your Name or Id):&amp;nbsp;&amp;nbsp;&lt;input type="text" name="sender" id="sender"&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;&lt;td width='85%'&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id="chat_view" &gt;<br /> &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp;&amp;nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id="users" name="users"&gt;Online Users&lt;/div&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;/table&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id="chat_list"&gt;&lt;/div&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;style type="text/css"&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .chat_box{<br /> border-style:solid;<br /> border-width:medium;<br /> width:200px;<br /> height:300px;<br /> float:left;<br /> <br /> }<br /> #msg{<br /> width:200px;<br /> height:200px;<br /> overflow:auto;<br /> }<br /> #new_msg_text<br /> {<br /> width:200px;<br /> height:50px;<br /> }<br /> #close_button{<br /> width:20px;<br /> height:20px;<br /> }<br /> .user_list{<br /> <br /> }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;/style&gt;<br /> &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;script type="text/javascript"&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(document).ready(function(){<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.setInterval(function() {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewMsg();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewOnlineUsers();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;createNewChatBox();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },1000);<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function creatNewBox(receiver)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var newbox ="&lt;div class='chat_box' id='chat_box_"+receiver+"'&gt;"+<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&lt;div id='chat_header'&gt;&lt;input type='text' name='receiver[]' READONLY value='"+<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; receiver+"' id='receiver'&gt;&lt;span onclick='closeWindow($(this))'&gt;X&lt;/span&gt;&lt;/div&gt;"+<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&lt;div&nbsp; height='20%' id='msg' &gt;"+<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;"+<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"&lt;div id='newmsg'&gt;&lt;textarea rows='4' cols='10' id='new_msg_text'&gt;&amp;nbsp;&lt;/textarea&gt;&lt;/div&gt;"+<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"&lt;input type='button' value='Send' id='btn' onclick='saveMsg($(this))'&gt;"+<br /> &nbsp; &nbsp; &nbsp; &nbsp; "&lt;/div&gt;";<br /> &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; return newbox;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function createNewChatBox()<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var sender=$("#sender").val();<br /> &nbsp; &nbsp; $("#chat_list").load('back.php?opt=get_chat&amp;sender='+sender);<br /> &nbsp; &nbsp; $("input[name='chat_users[]']").each(function(){<br /> &nbsp; <br /> viewBox($(this).val());<br /> });<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function viewBox(receiver)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($.trim($("#sender").val())==$.trim(receiver))<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(document).ready(function(){<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var flag=false;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("input[name='receiver[]']").each(function(){<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> if($(this).val()==receiver)<br /> {flag=true;}<br /> });<br /> &nbsp; &nbsp; &nbsp; &nbsp; if(flag==false)$("#chat_view").append(creatNewBox(receiver));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function viewOnlineUsers()<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var sender=$("#sender").val();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#users").load('back.php?opt=view_users&amp;sender='+sender);<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function closeWindow(obj)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.parent().parent().remove();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function viewMsg()<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var sender=$("#sender").val();<br /> $("input[name='receiver[]']").each(function(){<br /> var receiver=$(this).val();<br /> $("#chat_box_"+receiver).find("#msg").load('back.php?opt=view_msg&amp;sender='+sender+"&amp;receiver="+receiver);<br /> });<br /> }<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; function saveMsg(obj)<br /> &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var receiver=obj.parent().find("#receiver").val();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var sender=$("#sender").val();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var msg=obj.parent().find("#new_msg_text").val();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$.ajax({<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type: 'POST',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url: 'back.php?opt=save',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data: {"receiver":receiver,"sender":sender,"msg":msg},<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;success: function(){<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.parent().find("#new_msg_text").val('');<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});<br /> &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;/script&gt;<br /> &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &lt;/body&gt;<br /> &lt;/html&gt;<br /> <br /></div> <b><u>back.php</u></b><br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> &lt;?php<br /> extract($_POST);<br /> extract($_GET);<br /> $con = new mysqli('localhost', 'root', 'password','chat_db');<br /> <br /> switch ($opt)<br /> {<br /> &nbsp; &nbsp; case "save":&nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt = $con-&gt;prepare("INSERT INTO chat (sender,receiver,msg,time) values(?,?,?,NOW())");<br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;bind_param("sss", $sender, $receiver, $msg);<br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; break;<br /> <br /> &nbsp; &nbsp; case "view_msg":&nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt = $con-&gt;prepare("SELECT chat.*,users.user_id FROM chat&nbsp; LEFT JOIN users ON users.user_id=chat.sender"<br /> &nbsp; &nbsp; &nbsp; &nbsp; ." WHERE (receiver= ? AND sender= ? )"<br /> &nbsp; &nbsp; &nbsp; &nbsp; ." OR (receiver= ? AND sender= ? ) ORDER BY time");<br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;bind_param("ssss", $sender, $receiver, $receiver, $sender);<br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; &nbsp; &nbsp; $r = $stmt-&gt;get_result();<br /> &nbsp; &nbsp; &nbsp; &nbsp; while ($row = $r-&gt;fetch_assoc()) {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;table&gt;&lt;tr&gt;";<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;td&gt;".$row['user_id'].": ".$row['msg']."&lt;/td&gt;";<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;/tr&gt;&lt;/table&gt;";<br /> &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; break;<br /> &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; case "get_chat":&nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt = $con-&gt;prepare("SELECT DISTINCT&nbsp; sender from chat ".<br /> &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; WHERE receiver= ? AND AddTime(time, '00:00:15')&gt;=NOW()");<br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;bind_param("s", $sender);&nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; &nbsp; &nbsp; $r = $stmt-&gt;get_result();<br /> &nbsp; &nbsp; &nbsp; &nbsp; while ($row = $r-&gt;fetch_assoc()) {&nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;input type='text' name='chat_users[]' value='".$row['sender']."'&gt;";<br /> &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; break;<br /> &nbsp; <br /> &nbsp; &nbsp; case "view_users":<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stmt = $con-&gt;prepare("SELECT count(*) as count FROM users WHERE user_id= ?");<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;bind_param("s", $sender);&nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $r = $stmt-&gt;get_result();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $row = $r-&gt;fetch_assoc();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($row['count']&gt;0)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stmt = $con-&gt;prepare("UPDATE users SET last_visit=NOW() WHERE user_id= ?");<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;bind_param("s", $sender);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stmt = $con-&gt;prepare("INSERT INTO users (user_id,last_visit) values(?,NOW())");<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;bind_param("s", $sender);<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stmt = $con-&gt;prepare("SELECT * FROM users WHERE AddTime(last_visit, '00:00:15')&gt;=NOW()");<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $stmt-&gt;execute();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $r = $stmt-&gt;get_result();<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ($row = $r-&gt;fetch_assoc()) {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;table&gt;&lt;tr&gt;";&nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;td&gt;&lt;a onclick=\"viewBox('".$row['user_id']."')\"&gt;".$row['user_id']."&lt;/a&gt;&lt;/td&gt;";<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "&lt;/tr&gt;&lt;/table&gt;";<br /> &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; break;<br /> }<br /> ?&gt;</div> <br /> <br /> Here I am using two Mysql tables namely chat and users<br /> <b>chat</b><br /> <div class="separator" style="clear: both; text-align: left;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8f1UhPmiAb_ejZ-edwYTpaBPWWQ5skL6nCsqLjshjN-uV4TAj6nK8vPYYquv5XleHFF0OcSErs9mTKCiwEptoHXuwGOtjY1nZSRM8ecZYNerIe1a_yz6ngmNUo1QJHbZT4Qn9JUGjQZnV/s1600/openchat_chat.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="118" data-original-width="153" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8f1UhPmiAb_ejZ-edwYTpaBPWWQ5skL6nCsqLjshjN-uV4TAj6nK8vPYYquv5XleHFF0OcSErs9mTKCiwEptoHXuwGOtjY1nZSRM8ecZYNerIe1a_yz6ngmNUo1QJHbZT4Qn9JUGjQZnV/s1600/openchat_chat.JPG" /></a></div> <br /> <b>users</b><br /> <div class="separator" style="clear: both; text-align: left;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiOOqJo_85ZpKKZuP-sxmggX96wpNAyJhyphenhyphen5p4ueIY7fx7dMyXrerUCFZF8KjD74G5WohY8QbxT2Osb5nkZAlgGHKXRX1OgdeRKRqVFgqWXjurwDnj23PfFSuzy3grobpwJrJ_oAk3j5qOp/s1600/openchat_users.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="71" data-original-width="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiOOqJo_85ZpKKZuP-sxmggX96wpNAyJhyphenhyphen5p4ueIY7fx7dMyXrerUCFZF8KjD74G5WohY8QbxT2Osb5nkZAlgGHKXRX1OgdeRKRqVFgqWXjurwDnj23PfFSuzy3grobpwJrJ_oAk3j5qOp/s1600/openchat_users.JPG" /></a></div> <br /> The query to make this tables<br /> <b><u>chat</u></b><br /> CREATE TABLE IF NOT EXISTS `chat` (<br /> &nbsp; `sender` varchar(255) DEFAULT NULL,<br /> &nbsp; `receiver` varchar(255) DEFAULT NULL,<br /> &nbsp; `msg` text,<br /> &nbsp; `time` datetime DEFAULT NULL<br /> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br /> <br /> <b><u>users</u></b><br /> CREATE TABLE IF NOT EXISTS `users` (<br /> &nbsp; `user_id` varchar(255) NOT NULL,<br /> &nbsp; `last_visit` datetime NOT NULL<br /> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br /> <br /> <b>You can also read :- <a href="http://newprograminglogics.blogspot.com/2012/07/chat-application-using-database-table.html">Chat application using a database table in PHP - Part 1</a></b> <br /> <b><a href="http://newprograminglogics.blogspot.com/2018/01/chat-application-using-database-table_31.html">Chat application using a database table in PHP - Part 3</a></b> </div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-75632299149632593402014-05-31T02:07:00.001-07:002014-08-14T04:28:00.649-07:00Human Computer Interface introduction with calculator example<div dir="ltr" style="text-align: left;" trbidi="on"> <div style="display: none;"> human computer interaction,human computer interaction example,human computer interaction calculator ,artificial intelligence example,artificial intelligence calculator </div> <span style="font-size: large;">T</span>his article is to demonstrate a human computer interaction system with a calculator example.<br /> I am trying to reduce the GUI interface and make a human command mode to the system.Many of the researchers think that <b>human speak&nbsp; recognition</b> is the basic step of Human Computer Interaction (HCI).&nbsp;&nbsp; But I don't think so,because human speak recognition is a gigantic problem.<br /> Because the&nbsp; pronunciation and volume variation of each persion is varying and the slang are also different.<br /> <br /> But the easy way to give HCI commands to computer is by text medium.That is we can simply type the commands and execute the command.<br /> Here you can see the example HCI calculator:-<br /> <br /> <div style="border-style: solid; border-width: 1px; height: 300px; width: 600px;"> <table> <tbody> <tr><td align="center" colspan="2"><h3> HCI Calculator</h3> </td></tr> <tr> <td valign="top">Enter command </td> <td><textarea cols="50" id="command" rows="10"></textarea> </td> </tr> <tr> <td></td> <td align="center"><input onclick="evaluateComm();" type="button" value="Calculate" /> </td> </tr> <tr> <td></td> </tr> <tr> <td>Result </td> <td><input id="result" type="text" /> </td> </tr> </tbody></table> <script type="text/javascript"> var verb=Array(); verb[0]=Array('sum','add','addition','plus','+'); verb[1]=Array('difference','diff','minus','-'); verb[2]=Array('product','prod','multiply','*'); verb[3]=Array('quotient','div','division','/'); verb[4]=Array('clear','clean','empty','cls','clrscr'); function evaluateComm() { var command=new String(document.getElementById('command').value); if(command=='') return; var comm=Array(); var i,flag=0,op_index=0; command=command.replace('+',' plus '); command=command.replace('-',' minus '); command=command.replace('*',' prod '); command=command.replace('/',' div '); comm=command.trim().split(/\s+/); for(i=0;i<comm.length;i++) { res=analyseOne(comm[i]); if(res>=0) { flag=1; op_index=i; break; } } if(flag==1) { if(res!=4&&comm.length<3) { alert('Two operands and one operator required!!!!'); return; } var op=getOtherOperand(op_index); var output; switch(res) { case 0: output=Number(comm[op[0]])+Number(comm[op[1]]); break; case 1: output=Number(comm[op[0]])-Number(comm[op[1]]); break; case 2: output=Number(comm[op[0]])*Number(comm[op[1]]); break; case 3: output=Number(comm[op[0]])/Number(comm[op[1]]); break; case 4: document.getElementById('result').value=''; document.getElementById('command').value=''; return; break; } document.getElementById('result').value=output; } else { alert('Command does not match my occabulary.Please check spellings'); return; } } function getOtherOperand(res) { var arr=Array(); switch(res) { case 0: arr=Array(1,2); break; case 1: arr=Array(0,2); break; case 2: arr=Array(0,1); break; } return arr; } function analyseOne(str) { if(str=='') return -1; var i,j,flag=0,fflag=0; for(i=0;i<verb.length;i++) { for(j=0;j<verb[i].length;j++) { if(verb[i][j]==str.toLowerCase()) { flag=1; break; } } if(flag==1){ fflag=1;break;} } if(fflag==1) return i; else return -1; } </script> </div> <br /> <br /> This is a basic <b>calculator with addition,subtraction,multiplication and division</b>.&nbsp;&nbsp;&nbsp; But odd to regular calculators you can't see digit or operator buttons instead&nbsp; a<b> 'Enter command' &nbsp; </b>box and <b>'Calculate'</b> &nbsp; button. When you write <b>commands</b> in the box and click <b>calculate button</b> the result will display in the result text box.<br /> <br /> The command should have one operator and two operands.<br /> <br /> My first command is <b>' add 4 7 ' </b>. &nbsp;&nbsp; It mean find the sum of 4 and 7.<br /> You can see the screenshot here:-<br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkBI39f_hgQ0Fqw4wX2LN70h0msdTbaNxsXiwqx9CpjH1OfJFBBVKX3jUHSENQf5BeRxY6SPBlQ6amukSKsulXXo8u3eecsGQs07A8Ed2Mudol_q6OjBBwXdQ3wUTCmEfqx_p5hKxtVd3b/s1600/Untitled.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkBI39f_hgQ0Fqw4wX2LN70h0msdTbaNxsXiwqx9CpjH1OfJFBBVKX3jUHSENQf5BeRxY6SPBlQ6amukSKsulXXo8u3eecsGQs07A8Ed2Mudol_q6OjBBwXdQ3wUTCmEfqx_p5hKxtVd3b/s1600/Untitled.png" height="356" width="640" /></a></div> <br /> <br /> <br /> <br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOIYhOyZz69XMDS7c2uVUGb63JJoiDlGtRjMjcK8nVQjyNm8rYMe70iHKW-GxKQxzibQYUqv4COukrABu4nFP9iID7OqBAJuNogji0XU4PzHgbkuw9PQmYJsrzNYuJe5Wv9nI4ZT7KrJbt/s1600/Untitled.2png.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOIYhOyZz69XMDS7c2uVUGb63JJoiDlGtRjMjcK8nVQjyNm8rYMe70iHKW-GxKQxzibQYUqv4COukrABu4nFP9iID7OqBAJuNogji0XU4PzHgbkuw9PQmYJsrzNYuJe5Wv9nI4ZT7KrJbt/s1600/Untitled.2png.png" height="358" width="640" /></a></div> <span id="goog_524322066"></span><span id="goog_524322067"></span><br /> <br /> <br /> But the real beauty is where&nbsp; the command <b>4 add 7</b> also give the same result. <br /> Then&nbsp;<b> 4 7 add </b>give the same result.<br /> <b>&nbsp;addition 4 7&nbsp;</b>&nbsp; and<b> 4+7</b> has the same result<br /> <br /> <b>prod 4 3</b>&nbsp; give the result 12.<br /> The <b>clean ,&nbsp;&nbsp; cls</b>&nbsp;&nbsp;&nbsp; commands clear the results.<br /> <br /> Yes, more <b>flexible than GUI</b> and it is more related to <b>real life communication</b>.<br /> <br /> These are the commands I included in the calculators vocabulary.<br /> <table style="border-style: solid; border-width: 1px; width: 600px;"> <tbody> <tr style="background: #EBEBEB;"><td>Sum</td><td>Difference</td><td>Product</td><td>Quoetient</td><td>Clear</td></tr> <tr><td>add</td><td>difference</td><td>product</td><td>quotient</td><td>clear</td></tr> <tr><td>addition</td><td>diff</td><td>prod</td><td>div</td><td>clean</td></tr> <tr><td>plus</td><td>minus</td><td>multiply</td><td>division</td><td>empty</td></tr> <tr><td>+</td><td>-</td><td>*</td><td>/</td><td>cls</td></tr> <tr><td></td><td></td><td></td><td></td><td>clrscr</td></tr> </tbody></table> <br /> You can see the code here:<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> <u><b>calc.html&nbsp;</b></u><br /> <br /> <br /> &lt;html&gt;<br /> &lt;body&gt;<br /> &lt;table&gt;<br /> &lt;tr&gt;&lt;td colspan="2" align="center"&gt;&lt;h3&gt;HCI Calculator&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td valign="top"&gt;<br /> Enter command<br /> &lt;/td&gt;<br /> &lt;td&gt;<br /> &lt;textarea cols="50" rows="10" id="command"&gt;&lt;/textarea&gt;<br /> &lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;&amp;nbsp;&lt;/td&gt;<br /> &lt;td&nbsp; align="center"&gt;<br /> &lt;input type="button" value="Calculate" onclick="evaluateComm();"/&gt;<br /> &lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;&amp;nbsp;&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;<br /> Result<br /> &lt;/td&gt;<br /> &lt;td&gt;<br /> &lt;input type="text" id="result"/&gt;<br /> &lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;/table&gt;<br /> &lt;script type="text/javascript"&gt;<br /> var verb=Array();<br /> verb[0]=Array('sum','add','addition','plus','+');<br /> verb[1]=Array('difference','diff','minus','-');<br /> verb[2]=Array('product','prod','multiply','*');<br /> verb[3]=Array('quotient','div','division','/');<br /> verb[4]=Array('clear','clean','empty','cls','clrscr');<br /> <br /> <br /> <br /> function evaluateComm()<br /> { <br /> var command=new String(document.getElementById('command').value);<br /> if(command=='') return;<br /> var comm=Array();<br /> var i,flag=0,op_index=0;<br /> <br /> command=command.replace('+',' plus ');<br /> command=command.replace('-',' minus ');<br /> command=command.replace('*',' prod ');<br /> command=command.replace('/',' div ');<br /> <br /> comm=command.trim().split(/\s+/);<br /> for(i=0;i&lt;comm.length;i++)<br /> {<br /> res=analyseOne(comm[i]);<br /> if(res&gt;=0)<br /> {<br /> flag=1;<br /> op_index=i;<br /> break;<br /> }<br /> }<br /> if(flag==1)<br /> { <br /> if(res!=4&amp;&amp;comm.length&lt;3)<br /> {<br /> alert('Two operands and one operator required!!!!');<br /> return;<br /> }<br /> var op=getOtherOperand(op_index);<br /> var output;<br /> switch(res)<br /> {<br /> case 0:<br /> output=Number(comm[op[0]])+Number(comm[op[1]]);<br /> break;<br /> case 1:<br /> output=Number(comm[op[0]])-Number(comm[op[1]]);<br /> break;<br /> case 2:<br /> output=Number(comm[op[0]])*Number(comm[op[1]]);<br /> break;<br /> case 3:<br /> output=Number(comm[op[0]])/Number(comm[op[1]]);<br /> break;<br /> case 4:<br /> document.getElementById('result').value='';<br /> document.getElementById('command').value='';<br /> return;<br /> break;<br /> }<br /> document.getElementById('result').value=output;<br /> }<br /> else<br /> {<br /> alert('Command does not match my occabulary.Please check spellings');<br /> return;<br /> }<br /> }<br /> function getOtherOperand(res)<br /> {<br /> var arr=Array();<br /> switch(res)<br /> {<br /> case 0:<br /> arr=Array(1,2);<br /> break;<br /> case 1:<br /> arr=Array(0,2);<br /> break;<br /> case 2:<br /> arr=Array(0,1);<br /> break;<br /> }<br /> return arr;<br /> }<br /> <br /> function analyseOne(str)<br /> {<br /> if(str=='') return -1;<br /> var i,j,flag=0,fflag=0;<br /> for(i=0;i&lt;verb.length;i++)<br /> {<br /> for(j=0;j&lt;verb[i].length;j++)<br /> {<br /> if(verb[i][j]==str.toLowerCase())<br /> {<br /> flag=1;<br /> break;<br /> }<br /> }<br /> if(flag==1){ fflag=1;break;}<br /> }<br /> if(fflag==1)<br /> return i;<br /> else<br /> return -1;<br /> }<br /> &lt;/script&gt;<br /> &lt;/body&gt;<br /> &lt;/html&gt;<u><b> </b></u></div> <br /> Hope that you enjoy this code.More stuff on artificial intelligence and HCI is coming soon.Keep reading....</div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-40256516649289322352013-09-08T10:12:00.000-07:002013-12-16T03:22:30.139-08:00Encode form elements for ajax submit<div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-size: large;">H</span>i friends,<br /> Today my description is about submit form elements through ajax.Submit form through javascript can done using <i><b>submit()</b></i> method .<br /> But when&nbsp; try to submit a form through ajax we need to provide the name of elements and its value as data parameter in jquery $.ajax();<br /> <br /> We can done this like <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> var data='';<br /> data+='name='+$('#name').val()+'&amp;age='+$('#age').val();</div> <br /> <br /> But we can use jquery <i><b>serialize()</b></i> method we can do this all stuff in single step,like this:<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> var data=$('#frm').serialize(); </div> <br /> <br /> Example:<br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> &lt;form id="frm"&gt;<br /> &lt;input type="text" name="name"/&gt;<br /> &lt;input type="text" name="age"/&gt;<br /> &lt;input type="button" onclick="submitFrm();"/&gt;<br /> &lt;/form&gt;<br /> <br /> &lt;script type="text/javascript"&gt;<br /> function submitFrm()<br /> {<br /> var data=$('#frm').serialize();<br /> $.ajax({<br /> url:'action.php',<br /> data:data,<br /> type:'post',<br /> datatype:'html',<br /> success:function(){<br /> alert('success...');<br /> },<br /> error:function(){<br /> alert('error...');<br /> }<br /> });<br /> }<br /> &lt;/script&gt;</div> <br /> <br /> That is we can use <i><b>serialize()</b></i> to easy ajax form submit.<br /> If we want to add some additional parameters&nbsp; existing outside of the form,<br /> add them easily by using <i><b>'&amp;'</b></i> like this.<br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> var data=$('#frm').serialize();<br /> data+='&amp;teacher_name='+$('#teach_name').val();</div> <br /> Thank you.</div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-71087537889910545542012-07-24T10:08:00.001-07:002018-08-14T12:02:21.047-07:00Chat application using a database table in PHP<div dir="ltr" style="text-align: left;" trbidi="on"> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-size: large;">T</span>his article is to describe a simple chat application in php or web chat application.<br /> When think about how to create chat application in php&nbsp; we can understand that. <b>each</b> user accessing<br /> the webpage get a separate instance of the webpage and there have no direct<br /> connection between two users using the same page at the same time.So we can use<br /> a sql database to communicate with two users.<br /> <br /> &nbsp;&nbsp; Online chat application in php means a chat application using ajax or in othe words<br /> &nbsp;a jquery chat application.<br /> <br /> <!--&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Before go through the source code you can see a sample screen shot here<br /> &nbsp;Please open this same page in another tab or another browser to test the chat application.<br /> For reduce &nbsp;complexity I am not using a user login.You can simply login to chat by using your name or nick<br /> name without any <b>log up</b> process.<br /> <br /> <br /> Enter your name like Xwe , Yrt , Zty &nbsp;in the<b> From </b>text box.You can see the online users in the right column.Click one of the<br /> names , you can see a chat box is opened.You can write messages in it and send to the selected user.--></div> <!--<iframe height="400" src="https://funbuzzzz.blogspot.com/2018/01/chat-redirect-part1.html" width="100%"></iframe>--> <br /> <b>You can download the complete zip file fromthis link:-</b><br /> <a href="https://dl.dropboxusercontent.com/s/rv6aejvbqgphg61/openchat_part1.zip">https://dl.dropboxusercontent.com/s/rv6aejvbqgphg61/openchat_part1.zip</a><br /> To know how to install and use watch this video.&nbsp;&nbsp;<b>(Click the gear icon and select video quality to 1080p HD, then click the full screen button for good quality)</b><br /> <b><br /></b> Go to this link to subscribe to my YouTube channel to stay updated:-&nbsp;<a href="https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw" style="color: #00997f;">https://www.youtube.com/channel/UCxTp2yDew9m48Ch_hArOoYw</a><br /> <br /> <iframe allowfullscreen="allowfullscreen" height="349" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" src="https://www.youtube.com/embed/v-xSGNM-nJc" style="text-align: center;" webkitallowfullscreen="webkitallowfullscreen" width="600"> </iframe> Here is the source code for chat application in php<br /> &nbsp;Here have two files index.php and back.php<br /> <u><b>&nbsp;code</b></u><br /> <u><b>&nbsp;index.php</b></u><br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> &nbsp;&lt;html&gt;<br /> &nbsp;&nbsp;&nbsp; &lt;head&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &lt;/head&gt;<br /> &nbsp;&nbsp;&nbsp; &lt;body&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;table width="100%" height="100%" border="1" align="center" valign="center"&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;&lt;td colspan="2" height="6%"&gt;&lt;h3&gt;Chat Window&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;tr&gt;&lt;td colspan="2" height="6%"&gt; From(Your Name or Id):&amp;nbsp;&amp;nbsp;&lt;input type="text" name="sender" id="sender"&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;&lt;td width='85%'&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div id="chat_view" &gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/div&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/td&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div id="users" name="users"&gt;Online Users&lt;/div&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/td&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/table&gt;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div id="chat_list"&gt;&lt;/div&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;style type="text/css"&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .chat_box{<br /> border-style:solid;<br /> border-width:medium;<br /> width:200px;<br /> height:300px;<br /> float:left;<br /> <br /> }<br /> #msg{<br /> width:200px;<br /> height:200px;<br /> overflow:auto;<br /> }<br /> #new_msg_text<br /> {<br /> width:200px;<br /> height:50px;<br /> }<br /> #close_button{<br /> width:20px;<br /> height:20px;<br /> }<br /> .user_list{<br /> <br /> }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/style&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;script type="text/javascript"&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(document).ready(function(){<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.setInterval(function() {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewMsg();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewOnlineUsers();<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; createNewChatBox();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },1000);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function creatNewBox(receiver)<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var newbox ="&lt;div class='chat_box' id='chat_box_"+receiver+"'&gt;"+<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "&lt;div id='chat_header'&gt;&lt;input type='text' name='receiver[]' READONLY value='"+<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; receiver+"' id='receiver'&gt;&lt;img id='close_button' src='images/close_button.jpg' alt='X' onclick='closeWindow($(this))'/&gt;&lt;/div&gt;"+<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&lt;div&nbsp; height='20%' id='msg' &gt;"+<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;"+<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&lt;div id='newmsg'&gt;&lt;textarea rows='4' cols='10' id='new_msg_text'&gt;&amp;nbsp;&lt;/textarea&gt;&lt;/div&gt;"+<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&lt;input type='button' id='btn' onclick='saveMsg($(this))'&gt;"+<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&lt;/div&gt;";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return newbox;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; function createNewChatBox()<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;var sender=$("#sender").val();<br /> &nbsp;&nbsp;&nbsp; $("#chat_list").load('back.php?opt=get_chat&amp;sender='+sender);<br /> &nbsp;&nbsp;&nbsp; $("input[name='chat_users[]']").each(function(){<br /> &nbsp;&nbsp;&nbsp; <br /> viewBox($(this).val());<br /> });<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function viewBox(receiver)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if($.trim($("#sender").val())==$.trim(receiver))<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(document).ready(function(){<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; var flag=false;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; $("input[name='receiver[]']").each(function(){<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <br /> if($(this).val()==receiver)<br /> {flag=true;}<br /> });<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(flag==false)$("#chat_view").append(creatNewBox(receiver));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function viewOnlineUsers()<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var sender=$("#sender").val();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#users").load('back.php?opt=view_users&amp;sender='+sender);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function closeWindow(obj)<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; obj.parent().parent().remove();<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function viewMsg()<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var sender=$("#sender").val();<br /> $("input[name='receiver[]']").each(function(){<br /> var receiver=$(this).val();<br /> $("#chat_box_"+receiver).find("#msg").load('back.php?opt=view_msg&amp;sender='+sender+"&amp;receiver="+receiver);<br /> });<br /> }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function saveMsg(obj)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var receiver=obj.parent().find("#receiver").val();<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var sender=$("#sender").val();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var msg=obj.parent().find("#new_msg_text").val();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $.ajax({<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type: 'POST',<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url: 'back.php?opt=save',<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data: {"receiver":receiver,"sender":sender,"msg":msg},<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; success: function(){<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert("success");<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/script&gt;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &lt;/body&gt;<br /> &lt;/html&gt;</div> <br /> <br /> <u><b>back.php</b></u><br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> &lt;?php<br /> <br /> <br /> <br /> extract($_POST);<br /> extract($_GET);<br /> $con = mysql_connect('localhost', 'root', '');<br /> mysql_select_db('sukesh');<br /> switch ($opt) {<br /> &nbsp;&nbsp;&nbsp; case "save":<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $query = "INSERT INTO chat (sender,receiver,msg,time) values('" . $sender . "','" . $receiver . "','" . $msg . "',NOW()" . ")";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mysql_query($query, $con) or die("Error...");<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br /> <br /> &nbsp;&nbsp;&nbsp; case "view_msg":<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $query = "SELECT * FROM chat WHERE receiver='" . $sender. "' AND sender='".$receiver."'";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r = mysql_query($query, $con) or die("Error...");<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ($row = mysql_fetch_array($r)) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "&lt;table&gt;&lt;tr&gt;";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "&lt;td&gt;".$row['msg']."&lt;/td&gt;";<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "&lt;/tr&gt;&lt;/table&gt;";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case "get_chat":<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $query = "SELECT DISTINCT&nbsp; sender from chat ".<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "&nbsp; WHERE receiver='$sender' AND AddTime(time, '00:00:15')&gt;=NOW()";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo $query ;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r = mysql_query($query, $con) or die("Error...3");<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ($row = mysql_fetch_array($r)) {<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo "&lt;input type='text' name='chat_users[]' value='".$row['sender']."'&gt;";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case "view_users":<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $query = "SELECT count(*) as count FROM users WHERE user_id='".$sender."'";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r=mysql_query($query, $con) or die("Error...1");<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $row = mysql_fetch_array($r);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if($row['count']&gt;0)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $query = "UPDATE users SET last_visit=NOW() WHERE user_id='".$sender."'";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $query = "INSERT INTO users (user_id,last_visit) values('".$sender."',NOW())";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mysql_query($query, $con) or die("Error...2");<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $query = "SELECT * FROM users WHERE AddTime(last_visit, '00:00:15')&gt;=NOW()";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $r = mysql_query($query, $con) or die("Error...3");<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ($row = mysql_fetch_array($r)) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "&lt;table&gt;&lt;tr&gt;";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "&lt;td&gt;&lt;a onclick=\"viewBox('".$row['user_id']."')\"&gt;".$row['user_id']."&lt;/a&gt;&lt;/td&gt;";<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "&lt;/tr&gt;&lt;/table&gt;";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br /> }<br /> ?&gt;</div> <br /> <br /> Here I am using two Mysql tables namely chat and users<br /> <u><b>chat</b></u><br /> <span id="goog_586837277"></span><span id="goog_586837278"></span><br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgc01kfN3PzyDkKnPXaAvWJILc1yjSDs8YgW0KxlFzp8pxDoLDgiRx5NkT4b5-SHspYoTopthBXsQ71QBjA8ndfhP16OL2rFHqk_1ZvDvavpTZ4DjVnkdyEWPc1s0b9Vrog0W3Nd-HHDurJ/s1600/openchat_chat.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgc01kfN3PzyDkKnPXaAvWJILc1yjSDs8YgW0KxlFzp8pxDoLDgiRx5NkT4b5-SHspYoTopthBXsQ71QBjA8ndfhP16OL2rFHqk_1ZvDvavpTZ4DjVnkdyEWPc1s0b9Vrog0W3Nd-HHDurJ/s1600/openchat_chat.JPG" /></a></div> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <u><b>users</b></u><br /> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSX8rVG63bkCAc8ruWzCCrV-8-MuLFMlzBdu2-3_98T0hiBp-XuIH3qbEwUDqDTCaHR9wRg5PEmAf6mwj-PxtfbHiECZ_BARZzph701nWcQ02Or0-TWGY8DbJ6JolWdNnr8C74GaYh5xoC/s1600/openchat_users.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSX8rVG63bkCAc8ruWzCCrV-8-MuLFMlzBdu2-3_98T0hiBp-XuIH3qbEwUDqDTCaHR9wRg5PEmAf6mwj-PxtfbHiECZ_BARZzph701nWcQ02Or0-TWGY8DbJ6JolWdNnr8C74GaYh5xoC/s1600/openchat_users.JPG" /></a><br /> <br /> <br /> <br /> <br /> <br /> <b>The query to make this tables</b><br /> <u><b>chat</b></u><br /> CREATE TABLE IF NOT EXISTS `chat` (<br /> &nbsp; `sender` varchar(255) DEFAULT NULL,<br /> &nbsp; `receiver` varchar(255) DEFAULT NULL,<br /> &nbsp; `msg` text,<br /> &nbsp; `time` datetime DEFAULT NULL<br /> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br /> <br /> <u><b>users</b></u><br /> CREATE TABLE IF NOT EXISTS `users` (<br /> &nbsp; `user_id` varchar(255) NOT NULL,<br /> &nbsp; `last_visit` datetime NOT NULL<br /> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br /> <br /> <br class="Apple-interchange-newline" /> <span style="font-weight: 700;">You can also read :-&nbsp;</span><a href="http://newprograminglogics.blogspot.in/2018/01/chat-application-using-database-table.html" style="font-weight: 700;">Chat application using a database table in PHP - Part 2</a><br /> <div class="post-title entry-title" itemprop="name" style="font-weight: normal; text-align: left;"> </div> </div> Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com40tag:blogger.com,1999:blog-5725016407743583511.post-67819791308353009592012-06-25T10:12:00.000-07:002012-06-29T00:40:53.544-07:00Simple Game Using Jquery<div dir="ltr" style="text-align: left;" trbidi="on"> This article is to discuss about online game programming.In other words&nbsp; how to make a game <br /> in&nbsp; html . Nothing to think further the option is jquery.<br /> &nbsp;&nbsp;&nbsp; There are any jquery games examples are available in internet.But here I am <br /> introducing a free online ball game coded in jquery.This is padd and ball game.The padd<br /> move with mouse movement.We may save the ball from fall to the ground.I think<br /> this is a simple jquery game.<br /> <br /> You can see the working of game which I named Hit Ball before go through this <br /> jquery game source code.<br /> <br /> <br /> <iframe height="400" src="http://sukeshbr.byethost3.com/Blog_Works/hit_ball/g1.html" width="100%"></iframe> <b>&nbsp;</b><br /> <b>You can download the source code from here</b><br /> http://sukeshbr.byethost3.com/Blog_Works/hit_ball/hit_ball.zip <br /> <br /> <br /> Here have two html files g1.html and end.html.<br /> <br /> <u><b>Code</b></u><br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> <u><b>g1.html</b></u><br /> &lt;html&gt;<br /> &lt;head&gt;<br /> &lt;style type="text/css"&gt;<br /> *{&nbsp;&nbsp;&nbsp; margin: 0;<br /> &nbsp;&nbsp;&nbsp; padding: 0}<br /> #bar{<br /> position:absolute;<br /> left:200px;<br /> width:130px;<br /> height:20px;<br /> <br /> }<br /> #ball{<br /> position:absolute;<br /> left:270px;<br /> width:20px;<br /> height:20px;<br /> }<br /> #plain{<br /> width:97%;<br /> height:95%;<br /> border:10px solid #000000;<br /> background:#ccffff;<br /> }<br /> <br /> #block_red1{<br /> position:absolute;<br /> top:100px;<br /> left:50px;<br /> width:50px;<br /> height:25px;<br /> }<br /> #block_blue1{<br /> position:absolute;<br /> top:100px;<br /> left:100px;<br /> width:50px;<br /> height:25px;<br /> }<br /> #block_red2{<br /> position:absolute;<br /> top:100px;<br /> left:150px;<br /> width:50px;<br /> height:25px;<br /> }<br /> #block_pink1{<br /> position:absolute;<br /> top:100px;<br /> left:200px;<br /> width:50px;<br /> height:25px;<br /> }<br /> #block_blue2{<br /> position:absolute;<br /> top:100px;<br /> left:250px;<br /> width:50px;<br /> height:25px;<br /> }<br /> #block_pink2{<br /> position:absolute;<br /> top:100px;<br /> left:300px;<br /> width:50px;<br /> height:25px;<br /> }<br /> <br /> <br /> &lt;/style&gt;<br /> &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;<br /> &lt;script type="text/javascript"&gt;<br /> $(document).ready(function(){<br /> $("#bar").css("top", window.innerHeight-80);<br /> $("#ball").css("top", window.innerHeight-100);<br /> var click_stat=false;<br /> //Code to move bar<br /> $(document).mousemove(function(m){<br /> $("#body").css('cursor', 'none');<br /> if(m.pageX&gt;10&amp;&amp;m.pageX&lt;window.innerWidth-180)<br /> {<br /> $("#bar").css({"left":m.pageX});<br /> if(click_stat==false)<br /> $("#ball").css({"left":m.pageX+70});<br /> }<br /> });<br /> <br /> <br /> window.setInterval(function() {<br /> if(click_stat==true){<br /> var p = $("#ball");<br /> var position = p.position();<br /> var status=getStatus();<br /> if(status==1)<br /> {<br /> var tadd=getTAdd();<br /> var ladd=getLAdd();<br /> $("#ball").css({"top":position.top+tadd,"left":position.left+ladd});<br /> }<br /> else if(status==0)<br /> {<br /> alert("Game Over...");<br /> location.href="end.html";<br /> }<br /> else if(status==2)<br /> {<br /> alert("You Won...");<br /> location.href="end.html";<br /> }<br /> }<br /> },40);<br /> <br /> <br /> //code to detect initial click<br /> $(document).click(function(){<br /> <br /> $("#plain").css('cursor', 'none');<br /> click_stat=true;<br /> <br /> });<br /> });<br /> <br /> function getLAdd()<br /> {<br /> var ladd=0;<br /> var pball = $("#ball");<br /> var pbar = $("#bar");<br /> var bar_position = pbar.position();<br /> var ball_position = pball.position();<br /> <br /> if(ball_position.top&gt;=window.innerHeight-100)<br /> {<br /> if(ball_position.left-10&gt;=bar_position.left &amp;&amp; ball_position.left-10&lt;=bar_position.left+100 )<br /> &nbsp;{ladd=-2; }<br /> &nbsp;if(ball_position.left+10&lt;=bar_position.left+200&nbsp; &amp;&amp; ball_position.left+10&gt;=bar_position.left+100 )<br /> &nbsp;{ladd=2; }<br /> <br /> }<br /> <br /> if(ladd==0){ladd=getLAdd.ladd;}<br /> if(ball_position.left&lt;=15|| ball_position.left&gt;=window.innerWidth-40)<br /> ladd=-ladd;<br /> <br /> getLAdd.ladd=ladd;<br /> return ladd;<br /> }<br /> <br /> function getTAdd()<br /> {<br /> var tadd=0;<br /> var pball = $("#ball");<br /> var pbar = $("#bar");<br /> var ball_position = pball.position();<br /> var bar_position = pbar.position();<br /> if(ball_position.top&gt;=0 &amp;&amp; ball_position.top&lt;=11) tadd=5;<br /> if(ball_position.top&gt;=window.innerHeight-100) tadd=-5;<br /> if(ball_position.top&gt;75&amp;&amp;ball_position.top&lt;125)<br /> {<br /> <br /> if(($("#block_red1").length&gt;0) &amp;&amp; (ball_position.left+20&gt;50&amp;&amp;ball_position.left&lt;100))<br /> {<br /> tadd=-(getTAdd.tadd);<br /> $("#block_red1").remove();<br /> }<br /> <br /> if(($("#block_blue1").length&gt;0) &amp;&amp; (ball_position.left+20&gt;100&amp;&amp;ball_position.left&lt;150))<br /> {<br /> tadd=-(getTAdd.tadd);<br /> $("#block_blue1").remove();<br /> }<br /> if(($("#block_red2").length&gt;0) &amp;&amp; (ball_position.left+20&gt;150&amp;&amp;ball_position.left&lt;200))<br /> {<br /> tadd=-(getTAdd.tadd);<br /> $("#block_red2").remove();<br /> }<br /> if(($("#block_pink1").length&gt;0) &amp;&amp; (ball_position.left+20&gt;200&amp;&amp;ball_position.left&lt;250))<br /> {<br /> tadd=-(getTAdd.tadd);<br /> $("#block_pink1").remove();<br /> }<br /> if(($("#block_blue2").length&gt;0) &amp;&amp; (ball_position.left+20&gt;250&amp;&amp;ball_position.left&lt;300))<br /> {<br /> tadd=-(getTAdd.tadd);<br /> $("#block_blue2").remove();<br /> }<br /> if(($("#block_pink2").length&gt;0) &amp;&amp; (ball_position.left+20&gt;300&amp;&amp;ball_position.left&lt;350))<br /> {<br /> tadd=-(getTAdd.tadd);<br /> $("#block_pink2").remove();<br /> }<br /> }<br /> if(tadd==0){tadd=getTAdd.tadd;}<br /> getTAdd.tadd=tadd;<br /> return tadd;<br /> }<br /> <br /> function getStatus()<br /> {<br /> var stat;<br /> var pball = $("#ball");<br /> var pbar = $("#bar");<br /> var bar_position = pbar.position();<br /> var ball_position = pball.position();<br /> if(ball_position.top&gt;=bar_position.top-20)<br /> {<br /> if(ball_position.left+22&gt;=bar_position.left &amp;&amp; ball_position.left&lt;=bar_position.left+200)<br /> stat=1;<br /> else<br /> stat=0;<br /> }<br /> else stat=1;<br /> if(stat!=0&amp;&amp;($("#block_blue1").length==0)&amp;&amp;($("#block_blue2").length==0)<br /> &amp;&amp;($("#block_red1").length==0)&amp;&amp;($("#block_red2").length==0)<br /> &amp;&amp;($("#block_pink1").length==0)&amp;&amp;($("#block_pink2").length==0))<br /> stat=2;<br /> return stat;<br /> }<br /> &lt;/script&gt;<br /> <br /> &lt;/head&gt;<br /> &lt;body&gt;<br /> &lt;div id="plain"&nbsp; &gt;<br /> &lt;img id="block_red1" src="images/block_red.png"&gt;<br /> &lt;img id="block_blue1" src="images/block_blue.png"&gt;<br /> &lt;img id="block_red2" src="images/block_red.png"&gt;<br /> &lt;img id="block_pink1" src="images/block_pink.png"&gt;<br /> &lt;img id="block_blue2" src="images/block_blue.png"&gt;<br /> &lt;img id="block_pink2" src="images/block_pink.png"&gt;<br /> <br /> &lt;label id="name"&gt;&lt;h3&gt;Hit_ball By Sukesh B R&lt;/h3&gt;&lt;/label&gt;<br /> &lt;img id="bar"&nbsp; src="images/bar.png"&gt;<br /> &lt;img id="ball"&nbsp; src="images/ball.png"&gt;<br /> &lt;/div&gt;<br /> &lt;/body&gt;<br /> &lt;/html&gt;</div> <br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> <u><b>end.html</b></u><br /> &lt;html&gt;<br /> &lt;body&gt;<br /> &lt;h1&gt;Game Completed...&lt;/h1&gt;<br /> &lt;br&gt;<br /> &lt;a href="g1.html"&gt;Restart&lt;/a&gt;<br /> &lt;/body&gt;<br /> &lt;/html&gt;</div> <br /> <b>Code description</b><br /> <br /> &nbsp;Let we start from <i>g1.html.&nbsp;&nbsp; </i>In the body section I placed two images namely <i>bar</i> and <i>ball</i> .<br /> &nbsp;The images for this is in the image folder which can be download from above.You can see another<br /> &nbsp;four images.They are the bricks placed above the&nbsp; bar.<br /> <br /> &nbsp;&nbsp; In the css section , there are the code to position correctly the bricks , padd and ball.<br /> <br /> <br /> &nbsp; In the jquery section&nbsp; in the mousemove event the code to move the padd is written.m is<br /> the mouse object <b style="color: blue;">m.pageX</b><span style="color: blue;"> </span>gives the <i>x cordinate</i> of mouse pointer <b style="color: blue;">m.pageY</b><span style="color: blue;">&nbsp;</span> gives the <i>y cordinte </i>of <br /> mouse position.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Here we change only the left property of bar image with m.pageX.&nbsp; <br /> We wont change the y cordinate.Because we need to move the padd in horizontal direction<br /> only.<br /> <br /> <br /> <b style="color: blue;">&nbsp; window.setInterval()&nbsp; </b>is&nbsp; another event used to execute a particular block iteratively<br /> &nbsp; in a particular time interval.in this function&nbsp; <i><b>getTAdd()&nbsp;</b></i> is called to get the&nbsp;&nbsp; tadd which is added to the y position of the ball.<br /> &nbsp;<i><b> getLAdd()</b></i> is called to get the ladd which is added to the x position of the ball.<br /> &nbsp; <br /> &nbsp; The variable status returned from <i><b>getStatus()</b></i> determine that the game is active or<br /> &nbsp; game over or win in the game.<br /> &nbsp; <br /> &nbsp; <br /> &nbsp;In the functions <i><b>getTAdd(),getLAdd()</b></i> and <i><b>getStatus() </b></i>the ladd , tadd and <i>staus</i>&nbsp;&nbsp; is calculated<br /> by analysing the position of ball and padd.&nbsp; If the ball is hit the left half of padd the ladd&nbsp;&nbsp; will be +2.<br /> <br /> <br /> If the ball is hit the right half of padd the ladd will be -2.&nbsp; If the ball position come&nbsp;&nbsp; near to the walls the<i> ladd </i>is multiplied with -1. Thus the ladd change to opposite value.&nbsp; This will gives a good flow to ball.<br /> <br /> &nbsp; In the top when come near to the top wall or bricks the tadd is multiplied with minus.<br /> &nbsp; So the ball then move to <i>downward&nbsp; </i>direction.When ball come near to a brick this the <br /> &nbsp; brick will be removed using <b><i>remove()</i></b> method.<br /> &nbsp; <br /> &nbsp; This is only a brief description.Hope that you can understand the core.<br /> <br /> You can also read :-<br /> <h3 class="post-title entry-title" itemprop="name" style="font-weight: normal;"> <a href="http://newprograminglogics.blogspot.in/2011/12/play-wav-file-using-html.html"><span style="font-size: small;">Play wav file using HTML</span></a></h3> <div class="post-title entry-title" itemprop="name" style="font-weight: normal; text-align: left;"> <a href="http://newprograminglogics.blogspot.in/2012/06/very-simple-menu-using-jquery-beginners.html">Very simple Menu using Jquery Beginners Tutorial</a></div> <h3 class="post-title entry-title" itemprop="name" style="font-weight: normal;"> <span style="font-size: small;">&nbsp;</span></h3> </div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com1tag:blogger.com,1999:blog-5725016407743583511.post-45129538419274670322012-06-14T09:37:00.000-07:002012-07-01T21:40:11.836-07:00Very simple Menu using Jquery Beginners Tutorial<div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-size: large;">T</span>his&nbsp; article is to teach how to create <i style="color: blue;">drop down menu</i>&nbsp; in html.I am not going to design a<br /> graphical pull down menu.&nbsp; Instead I am trying to reveal the basic construction of pull down <br /> menu.<br /> <br /> &nbsp; When creating menus using jquery only the hiding and pop up of menu is handled by <b style="color: blue;">jquery</b><span style="color: blue;">.</span> The<br /> actual layout is created using&nbsp; <b>css</b>. Creating drop down menus in<i><span style="color: blue;"> css</span></i> means align a <b style="color: blue;">&lt;ul&gt; </b>and<br /> it's <b style="color: blue;">child &lt;ul&gt;</b><span style="color: blue;"> </span>using css,because the pull down menu is constructed using a &lt;ul&gt;.So code for <br /> creating menu in html includes css and jquery.<br /> <br /> You can see a demo of resultant menu here<br /> <br /> <br /> <div> <iframe height="100" src="http://sukeshbr.byethost3.com/Blog_Works/very_simple_menu/menu2.html" width="100%"></iframe> </div> <br /> <br /> <u><b>Code</b></u><br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> <br /> &lt;html&gt;<br /> &lt;head&gt;<br /> <br /> &lt;style type="text/css"&gt;<br /> <br /> *{&nbsp;&nbsp;&nbsp; margin: 0;<br /> &nbsp;&nbsp;&nbsp; padding: 0}<br /> &nbsp;&nbsp;&nbsp; #menu{<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; z-index:5;<br /> &nbsp;&nbsp;&nbsp; }<br /> a{<br /> text-decoration:none;<br /> }<br /> &nbsp;&nbsp;&nbsp; #menu li<br /> &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; float: left;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list-style: none;<br /> &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> <br /> &nbsp;&nbsp;&nbsp; #menu li a<br /> &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; display: block;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> <br /> <br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #menu li ul<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; position: absolute;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; display: none;<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #menu li ul li<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; float: none;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; display: inline<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> <br /> &lt;/style&gt;<br /> <br /> <br /> &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;<br /> &lt;script type="text/javascript"&gt;<br /> $(document).ready(function(){<br /> $("#menu &gt; li").mouseenter(function(){<br /> $(this).find('ul').css('display', 'inline');<br /> });<br /> <br /> $("#menu &gt; li").mouseleave(function(){<br /> $(this).find('ul').css('display', 'none');<br /> });<br /> });<br /> &lt;/script&gt;<br /> &lt;/head&gt;<br /> <br /> <br /> &lt;body&gt;<br /> &lt;ul id="menu"&gt;<br /> &lt;li&gt;&lt;a&gt;Menu1&lt;/a&gt;<br /> &lt;ul&gt;<br /> &lt;li&gt;&lt;a href="http://www.facebook.com"&gt;Facebook&lt;/a&gt;&lt;/li&gt;<br /> &lt;li&gt;&lt;a href="http://www.google.com"&gt;Google&lt;/a&gt;&lt;/li&gt;<br /> &lt;li&gt;&lt;a href="http://newprograminglogics.blogspot.com"&gt;My Blog&lt;/a&gt;&lt;/li&gt;<br /> &lt;/ul&gt;<br /> &lt;/li&gt;<br /> &lt;li&gt;<br /> &lt;a href="#"&gt;Menu2&lt;/a&gt;<br /> &lt;ul&gt;<br /> &lt;li&gt;&lt;a href="http://www.gmail.com"&gt;GMail&lt;/a&gt;&lt;/li&gt;<br /> &lt;li&gt;&lt;a href="http://www.twitter.com"&gt;Twitter&lt;/a&gt;&lt;/li&gt;<br /> &lt;/ul&gt;<br /> &lt;/li&gt;<br /> &lt;/ul&gt;&lt;br&gt;<br /> <br /> &lt;/body&gt;<br /> &lt;/html&gt;<br /> <br /> <br /></div> <br /> <u><b>Code description</b></u><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-size: large;">T</span>he pull down menu is actually a<i style="color: blue;">&nbsp; &lt;ul&gt;&nbsp; </i>that is <b><span style="color: blue;">unordered list</span></b>. Here in the &lt;body&gt; <br /> section I have placed a <b>&lt;ul&gt;</b>&nbsp;&nbsp; with <i><b>id="menu"</b></i>.&nbsp;&nbsp;&nbsp; As seen in the demo above in this page,<br /> here have two menus namely Menu1 and Menu2.<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This Menu1 and Menu2 are&nbsp; links(&lt;a&gt;) placed in&nbsp; &lt;li&gt; of &lt;ul&gt; with id="menu".&nbsp; Besides this link<br /> there have another <b>&lt;ul&gt;</b> in each<b> &lt;li&gt;</b>.&nbsp; The&nbsp; menu items are placed in the &lt;li&gt; of this child &lt;ul&gt;.<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This<b> &lt;ul&gt; </b>without applying&nbsp; css&nbsp; is displayed just like a list.&nbsp;&nbsp; But using some simple css<br /> commands we can convert it into a menu form. <br /> <br /> <b>*{&nbsp;&nbsp;&nbsp; margin: 0;</b><br /> <b>&nbsp;&nbsp;&nbsp; padding: 0}</b><br /> This code is for remove margin and padding from all elements.<br /> <br /> <br /> <br /> <b>#menu{</b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; z-index:5;</b><br /> <b>&nbsp;&nbsp;&nbsp; }</b><br /> <br /> Is used to place the menu above all elements in page.&nbsp;&nbsp;&nbsp; <br /> <br /> <br /> <br /> <br /> <b>a{</b><br /> <b>text-decoration:none;</b><br /> <b>} </b><br /> Is use to remove the under line from links.<br /> <br /> <br /> <br /> In the code segment :-<br /> <b>#menu li</b><br /> <b>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; float: left;</b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list-style: none;</b><br /> <b>&nbsp;&nbsp;&nbsp; </b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</b><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<span style="color: blue;">&nbsp;</span><i style="color: blue;"> float : left</i><span style="color: blue;">&nbsp;</span>&nbsp; place the li of ul side by side.In default it is from top to bottom,&nbsp; that is vertically.&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<i style="color: blue;"> list-style: none</i> removes the dots (.) from the front of each item.<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;<b> &nbsp;&nbsp;&nbsp; #menu li a</b><br /> <b>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; display: block;</b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</b><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Is for display each item as a block.<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<b>&nbsp; #menu li ul</b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; position: absolute;</b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; display: none;</b><br /> <b><br /></b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</b><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Here position: absolute is for place the menu items exactly&nbsp; below&nbsp; menu heading<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; irrespect&nbsp; of other elements in the page.<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<i style="color: blue;"> display: none</i> is for hide this contents initially.The menu items will be displayed only<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; after mouse entered in menu heading.<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>#menu li ul li</b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; float: none;</b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; display: inline</b><br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</b><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Here float: none is for remove the float to left property of child &lt;ul&gt;'s &lt;li&gt;, which is<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set in #menu li&nbsp;&nbsp; by<b>{&nbsp;&nbsp;&nbsp; float: left}</b><br /> <br /> <br /> Because here that does not require because the menu items should be displayed in&nbsp; vertical manner.<br /> <i style="color: blue;">display: inline</i> set the menu items vertically.<br /> &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The alignment of menu is over.Now we go through the <i>jquery</i>&nbsp; section which displays and hide<br /> &nbsp;&nbsp;&nbsp; the menu items.<br /> &nbsp;&nbsp;&nbsp; <br /> <b>&nbsp;&nbsp;&nbsp; $("#menu &gt; li").mouseenter(function(){</b><br /> <b>$(this).find('ul').css('display', 'inline');</b><br /> <b>});</b><br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This code will display the child ul,that is our menu items.The parent &lt;ul&gt;s &lt;li&gt;s<br /> <i style="color: blue;">mouseenter </i>event is defined with setting child &lt;ul&gt;'s display property to inline.Note <br /> that this is set to display:none initially in the css section.<b style="color: blue;">$(this).find(ul)</b><br /> will get the child element.&nbsp; .<b><i>css() </i></b>is a jquery library function used to change css<br /> property of certain elements.<br /> &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;One more thing&nbsp; remain is&nbsp; that we need to hide the menu item again when mouse &nbsp; is come out from the menu items.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; That is done by this code<br /> <b>&nbsp;&nbsp;&nbsp; &nbsp;</b><br /> <b>$("#menu &gt; li").mouseleave(function(){</b><br /> <b>$(this).find('ul').css('display', 'none');</b><br /> <b>});</b><br /> <b>});</b><br /> &nbsp;&nbsp;&nbsp;&nbsp; This is just like above code<i style="color: blue;">. mouseleave&nbsp;&nbsp; </i>event is used to detect the disappearence of mouse <br /> pointer.<i style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </i><span style="color: blue;"><b>$(this).find('ul')</b></span>&nbsp;&nbsp;&nbsp; will give the child &lt;ul&gt; then display : none is used <br /> to hide the menu items.<br /> <br /> Thus our simple menu is begin to work.<br /> <br /> You can also read :-<br /> <br /> <a href="http://newprograminglogics.blogspot.com/2012/06/simple-game-using-jquery.html">Simple Game Using Jquery</a><br /> <div class="post-title entry-title" itemprop="name" style="font-weight: normal; text-align: left;"> <a href="http://newprograminglogics.blogspot.in/2012/05/facebook-like-pop-up-window-using.html"><span style="font-size: small;">Facebook like pop up window using jquery</span></a></div> <div class="post-title entry-title" itemprop="name" style="font-weight: normal; text-align: left;"> <a href="http://newprograminglogics.blogspot.in/2011/12/introducing-ajax-with-simple-example.html">Introducing AJAX with a simple example program </a></div> </div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-54975882397335594032012-06-03T00:20:00.000-07:002012-06-03T00:32:15.117-07:00Delete non empty directory in php<div dir="ltr" style="text-align: left;" trbidi="on"> This article is to discuss how can delete any folder in php.Delete a directory in php is done by<br /> the method <b>rmdir()</b>.&nbsp; But it work only if the directory is empty.That is it can delete empty directories only.&nbsp;&nbsp;&nbsp; <br /> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; In php delete non empty directory is done by first delete contents of folder.<br /> That is delete all files in a folder.Then delete the empty directory using rmdir().<br /> <br /> This code will&nbsp; describe how can php remove non empty directory.&nbsp;&nbsp;&nbsp; <br /> <br /> <u><b>CODE</b></u><br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> &lt;?php<br /> &nbsp;&nbsp;<b>&nbsp; </b>del('new');<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function del($dir)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $result=array_diff(scandir($dir),array('.','..'));<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; foreach($result as $item)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp; if(!@unlink($dir.'/'.$item))<br /> &nbsp;&nbsp;&nbsp; del($dir.'/'.$item);<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rmdir($dir);<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; }<br /> <br /> ?&gt;</div> <br /> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Here I have defined a function with name<i><b> del()</b></i>.&nbsp;&nbsp; It has one parameter which is the&nbsp; name of the directory to be delete.Here my directory name is <i>'new'</i>.<br /> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In the&nbsp;&nbsp; <i><b>del()</b></i>&nbsp;&nbsp;&nbsp; function defenition<b>&nbsp;&nbsp; $result=array_diff(scandir($dir),array('.','..'));</b><br /> <b>scandir()</b>&nbsp;&nbsp; is used to get the name of all files and folders in the directory provided.<br /> <b>array_diff(..,array('.','..')) &nbsp; </b>is used to remove the default '.' and '..' folders.&nbsp; Then the remaining array is parsed using&nbsp; a&nbsp; foreach&nbsp; loop.<br /> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; First assume the item is a file.So delete it using <b>unlink()</b>.&nbsp; If <b>unlink()</b> returns false&nbsp; the item will be a directory.&nbsp; So <b>del()</b>&nbsp;&nbsp; function is called in&nbsp; recursive manner with the sub folder name (<i>$item</i>). <br /> <br /> &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; After the loop has executed <b>rmdir($dir)</b> will call.Now<b> rmdir() </b>can delete the directory<br /> because the directory will be empty.&nbsp;&nbsp; Hence delete directory with php is done.&nbsp;&nbsp;<br /> <br /> You can also read :-<br /> <div class="post-title entry-title" itemprop="name" style="font-weight: normal; text-align: left;"> <a href="http://newprograminglogics.blogspot.in/2012/04/extend-maximum-execution-time-of-php.html">Extend maximum execution time of php script</a></div> </div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com1tag:blogger.com,1999:blog-5725016407743583511.post-52271465012689267882012-05-24T04:02:00.000-07:002012-06-15T10:13:36.051-07:00Facebook like pop up window using jquery<div dir="ltr" style="text-align: left;" trbidi="on"> This article is discussing pop up window using jquery or popup box using jquery.<br /> Some of you are looking for a code for pop up window in html.&nbsp;&nbsp;&nbsp;&nbsp; But jquery is the better solution to not only create <b>simple pop up window</b> but also more<b> complicated popup windows</b>.To <br /> modal popup using jquery we use some essential css&nbsp; too.<br /> <br /> Try this :-<br /> <div> <iframe width="100%" height= 400 style="border:0" src="http://sukeshbr.byethost3.com/Blog_Works/Facebook_like_window/facebook_like_window.html"> </iframe> </div> <br /> <br /> <u><b>code</b></u><br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 10px;"> &lt;html&gt;<br /> &lt;head&gt;<br /> &nbsp;&nbsp; &lt;style type="text/css"&gt;<br /> &nbsp;&nbsp; #divid<br /> &nbsp;&nbsp; {<br /> &nbsp;&nbsp; z-index:5; <br /> &nbsp;&nbsp; position:absolute;<br /> &nbsp;&nbsp; width:400px;<br /> &nbsp;&nbsp; left:200px;<br /> &nbsp;&nbsp; top:150px;<br /> &nbsp;&nbsp; border:8px solid #a1a1a1;<br /> &nbsp;&nbsp; padding:0px 0px; <br /> &nbsp;&nbsp; background:#FFFFFD;<br /> &nbsp;&nbsp; border-radius:15px;<br /> &nbsp; }<br /> &nbsp; #headid<br /> &nbsp; {<br /> &nbsp; background:#6692CD;<br /> &nbsp; color:#ffffff;<br /> &nbsp; font-size:18px;<br /> &nbsp; }<br /> &nbsp; #shareid<br /> &nbsp; {<br /> &nbsp; background-color:#6692CD;<br /> &nbsp; color:#ffffff;<br /> &nbsp; font-size:15px;<br /> &nbsp; }<br /> &nbsp; &lt;/style&gt;<br /> <br /> &nbsp; <br /> &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;<br /> &lt;script type="text/javascript"&gt;<br /> <br /> $(document).ready(function(){<br /> $("#linkid").mouseenter(function(){<br /> if(!$("#divid").length)<br /> {<br /> $("#bodyid").append("&lt;div id='divid'&gt;"+<br /> "&lt;table width='100%'&gt;&lt;tr&gt;&lt;td id='headid'&gt;Share this Photo&lt;/td&gt;&lt;/tr&gt;"+<br /> "&lt;tr&gt;&lt;td&gt;&lt;br&gt;&lt;img src='http://mystifyingindia.com/blog/wp-content"+<br /> "/uploads/2010/09/taj_mahal.jpg' width='60' height='50'&gt;"+<br /> "&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbspHere come the body of the message..."+<br /> "&lt;br&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;"+<br /> "&lt;tr&gt;&lt;td align='right'&gt;&lt;input type='button' value='Share Photo' id='shareid'&gt;"+<br /> "&lt;input type='button' value='Cancel' onclick='btn_cancel()'&gt;&lt;/td&gt;&lt;/tr&gt;"+<br /> "&lt;/table&gt;&lt;/div&gt;"<br /> );<br /> $("#divid").css({"left":window.innerWidth/2-200,"top":window.innerHeight/2-100});<br /> }<br /> });<br /> <br /> <br /> <br /> }<br /> <br /> );<br /> &lt;/script&gt;<br /> &lt;script type="text/javascript"&gt;<br /> function btn_cancel()<br /> {<br /> <br /> $("#divid").remove();<br /> }<br /> &lt;/script&gt;<br /> &lt;/head&gt;<br /> <br /> &lt;body id="bodyid"&gt;<br /> &nbsp;&nbsp; &lt;div style='width:290px'&gt;<br /> &lt;a id="linkid"&gt;&lt;h3&gt;Mouse over it to see popup window&lt;/h3&gt;&lt;/a&gt;<br /> &nbsp;&nbsp;&nbsp; &lt;/div&gt;<br /> <br /> <br /> &lt;/body&gt;<br /> &lt;/html&gt;</div> <br /> <br /> Here is the sample screenshot :-<br /> <br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjD-R7X4LLkn2GPIC6ZwchZon7tZ2km8AHMDZ7n_QCR14H-HaAP7gQt1ihYLmqHLPJvVi-gVdPiJXVW2bzBst1sdAX3Aji9V0Xf4YOut96VZ_yK_koY4dvmGGMWIxNk9_0DqyY58uGalg6g/s1600/facebook+like+popuo+window.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjD-R7X4LLkn2GPIC6ZwchZon7tZ2km8AHMDZ7n_QCR14H-HaAP7gQt1ihYLmqHLPJvVi-gVdPiJXVW2bzBst1sdAX3Aji9V0Xf4YOut96VZ_yK_koY4dvmGGMWIxNk9_0DqyY58uGalg6g/s640/facebook+like+popuo+window.JPG" width="640" /></a></div> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> Here I am actully <b>dynamically include a &lt;div&gt;&nbsp; </b>with id <b>'divid'</b> when mouse is move over the text<br /> 'Mouse over it to see popup window'.&nbsp;<span style="color: blue;"> </span><b><span style="color: blue;">$("#bodyid").append("&lt;div id='divid'&gt;")&nbsp;</span>&nbsp; </b>is<br /> used to append the &lt;div&gt; to the body of html&nbsp; page.<br /> <br /> The contents in the pop up box is placed in this div. The css to this div is placed in the css section.<br /> The <b>border-radius</b> property set&nbsp; the &lt;div&gt; a rounded rectangle .<br /> <b>position:absolue</b> set the pop up box exactly where the top and left is given even if some<br /> elements are also present there.<br /> <br /> The top and left positions are calculated just like this <br /> <b>"left":window.innerWidth/2-200 , "top":window.innerHeight/2-100.</b><br /> <b>window.innerWidth</b> returns the width of browser window.Subtracting 200 from its half<br /> gives the center position of window, because 400 is the predefined width of pop up box.<br /> top position is also calculated just like this.<br /> <br /> <b>$("#divid").length</b> returns the number of elements with the id <b>'divid'.if(!$("#divid").length)</b><br /> is used to ensure the pop up box is not create when one is existing. <br /> <br /> Finally <b>$("#divid").remove()</b> is used to permenently remove the newly added pop up box<br /> from the dom.This is given in the onclick event of cancel button in the pop up box.<br /> <br /> You can also read:-<br /> <a href="http://newprograminglogics.blogspot.com/2012/01/open-new-browser-window-using.html">Open a new browser window using javascript</a><br /> <br /> <a href="http://newprograminglogics.blogspot.in/2011/12/introducing-ajax-with-simple-example.html">Introducing AJAX with a simple example program&nbsp;</a><br /> <br /> <h3 class="post-title entry-title" itemprop="name" style="font-weight: normal;"> <a href="http://newprograminglogics.blogspot.in/2012/06/very-simple-menu-using-jquery-beginners.html"><span style="font-size: small;">Very simple Menu using Jquery Beginners Tutorial</span></a></h3> </div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-39058238254024322272012-04-28T21:01:00.000-07:002012-05-24T04:50:26.374-07:00Include a page from url in php<div dir="ltr" style="text-align: left;" trbidi="on"> <style type="text/css"> .code{ border:2px solid #000000; padding:10px 40px; background:#ccffff; border-radius:8px; } </style> <br /> <div dir="ltr" style="text-align: left;" trbidi="on"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This article is to describe <b>how to include a page from other web site to our php page</b>.<br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; php include</b> url is not so simple as include a file in your site. We can <b>edit web pages</b>&nbsp; by including it to our php page.<br /> &nbsp;&nbsp;&nbsp; <b>&nbsp;</b><br /> <br /> <b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; php include external url</b>&nbsp; is not use <a href="http://php.net/manual/en/function.include.php"><b>include()</b>&nbsp; </a>or&nbsp; <a href="http://php.net/manual/en/function.require.php"><b>require()</b> </a>methods of&nbsp; php&nbsp; , which are used for local inclusion of&nbsp; pages in our site.<br /> <br /> <br /> &nbsp;&nbsp;&nbsp; If we want to use that &nbsp;&nbsp;&nbsp; we may use allow_url_include php for that.<br /> &nbsp;&nbsp;&nbsp;&nbsp; Here I am using&nbsp;<b> <a href="http://php.net/manual/en/function.file-get-contents.php">file_get_contents()</a></b><a href="http://www.blogger.com/goog_1730494715"> </a><a href="http://php.net/manual/en/function.file-get-contents.php">&nbsp;</a> for this purpose.<br /> &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; <u style="color: blue;"><b>&nbsp;Code</b></u><br /> &nbsp;&nbsp;&nbsp; <br /> <div class="code"> <b>&lt;?php<br /><br />&nbsp; $cnt=file_get_contents('http://www.gmail.com');<br />&nbsp; echo $cnt;<br />&nbsp; echo "&lt;div style=\" position:absolute;left:150px;top:50px \"&gt;<br />&nbsp; &lt;h1 style=\"color:red\"&gt;Successfully included By Sukesh B R<br />&nbsp; &lt;/h1&gt;&lt;/div&gt;";<br /><br />?&gt;</b></div> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Here I am including the <b>Gmail home page</b>.&nbsp; So give the URL <b>'<i> <span style="color: blue;">http://www.gmail.com</span></i> ' </b>as <br /> &nbsp;parameter to file_get_contents() .&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The return value from this is stored to the variable<br /> <b>&nbsp;$cnt</b>.&nbsp;&nbsp;&nbsp;&nbsp; Then print this using echo statement.<br /> <br /> <br /> &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Hence the Gmail page is displayed just like my local&nbsp;&nbsp;&nbsp; html page.&nbsp; Then I include a<b> &nbsp; &lt;div&gt;</b> &nbsp;&nbsp; in which a message&nbsp;&nbsp;&nbsp; <i style="color: blue;"><b>'Successfully included By Sukesh B R'</b></i> &nbsp; &nbsp; &nbsp; is displayed.I have use little css to display it in the top of gmail page.<br /> <br /> <br /> Here is a sample screenshot of this page :-<br /> <br /> <br /> <br /> <br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi13Y-LUL5I6BNMBRhTeqh2TEZfNtVU2zvVNALKKQ6fZ2snx2Td3y49lJjXjuZf-9WzR_G8djZgFS9EU6DLPm3d1Yysi8mfrzJzMVV7awxhNClLv84eAg2A9mWbBIsq7YlFoC5bduzafiip/s1600/include_file_by_url_in_php.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi13Y-LUL5I6BNMBRhTeqh2TEZfNtVU2zvVNALKKQ6fZ2snx2Td3y49lJjXjuZf-9WzR_G8djZgFS9EU6DLPm3d1Yysi8mfrzJzMVV7awxhNClLv84eAg2A9mWbBIsq7YlFoC5bduzafiip/s640/include_file_by_url_in_php.JPG" width="640" /></a></div> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /> <br /> <br /> <br /> You can add javascript blocks to this page and access the elements of Gmail home page&nbsp; and make changes in it with your like.You can add any other webpages just like this.<br /> <br /> <br /> You can also read:- <a href="http://newprograminglogics.blogspot.in/2012/04/download-image-file-using-php.html">Download image file using PHP</a><br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thanks for reading this article.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Please&nbsp; <b>just tick a response in the Reactions check boxes provided</b><br /> &nbsp;under this .</div> </div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-31424057251111288072012-04-23T10:34:00.000-07:002012-06-03T00:34:01.160-07:00Extend maximum execution time of php script<div dir="ltr" style="text-align: left;" trbidi="on"> <style type="text/css"> .code{ border:2px solid #000000; padding:10px 40px; background:#ccffff; border-radius:8px; } </style> <br /> <div dir="ltr" style="text-align: left;" trbidi="on"> Hi friends , <br /> today my discussion is about<b style="color: red;">&nbsp; extend maximum execution time of php script/page </b>.<br /> OR&nbsp;<b style="color: red;"> solution for <i>Fatal Error:Maximum execution time limit reached&nbsp; </i></b><span style="color: red;"><span style="color: black;">when you run a php page</span></span><b style="color: red;"> </b>.<br /> OR <b style="color: red;">change the maximum execution time of php script</b>.OR<b style="color: red;"> increase the maximum execution time of <br />php script </b>.<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; We can change the maximum execution time by call a function<b style="color: blue;"> set_time_limit().</b><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> <u style="color: blue;"><b>Syntax</b></u><br /> <div class="code"> <br /> &nbsp;&nbsp;<b> void set_time_limit ( int $seconds );</b><br /> <b>&nbsp;&nbsp;&nbsp; //set_time_limit(300);</b></div> <br /> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The<b> parameter</b> send to this specifies the<b> maximum execution time</b> in <b>seconds</b>.In the above code the maximum execution time is set to 300 seconds , that is 5 minutes.<br /> <br /> This can also achieve by using the function<b> <a href="http://php.net/manual/en/function.ini-set.php">ini_set()</a></b> , like this , <br /> <br /> <div class="code"> &nbsp;<b>&nbsp; ini_set('max_execution_time', 300);&nbsp;&nbsp; </b></div> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Here also 300 is the maximum execution time in seconds.<br /> <br /> Hope that this post is helpful to you.<br /> <br /> Thanks by <b>Sukesh B R</b><br /> <br /> <b>You can also read :-</b><br /> <div class="post-title entry-title" itemprop="name" style="text-align: left;"> <a href="http://newprograminglogics.blogspot.in/2012/06/delete-non-empty-directory-in-php.html"><b>Delete non empty directory in php</b></a></div> </div> </div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-53099805228790394922012-04-20T09:08:00.000-07:002012-04-29T00:19:26.648-07:00Download image file using PHP<div dir="ltr" style="text-align: left;" trbidi="on"> <style type="text/css"> .code{ border:2px solid #000000; padding:10px 40px; background:#ccffff; border-radius:8px; } </style> <br /> <div dir="ltr" style="text-align: left;" trbidi="on"> Hi friends,<br /> &nbsp;today my discussion is about how to <b style="color: red;">download an image from an URL using php</b>.OR <b style="color: red;">download picture from the given URL</b>.OR <b style="color: red;">save image file using php</b>.<br /> <br /> &nbsp;Here have two functions used for this:-<br /> <a href="http://php.net/manual/en/function.file-get-contents.php">&nbsp;&nbsp;&nbsp;<b>&nbsp; file_get_contents()</b></a> and <a href="http://php.net/manual/en/function.file-put-contents.php"><b>file_put_contents()</b></a><br /> &nbsp;&nbsp;&nbsp; <br /> <div style="color: blue;"> &nbsp;&nbsp;<b>&nbsp; <u>Code </u></b></div> <div class="code"> <b>&lt;</b><b>?php<br />set_time_limit(300) ;<br />$lnk='http://1.bp.blogspot.com/-SZgenQisfQc/TVPnClZOn5I/AAAAAAAABO8/zLFsX4UoFzg/s1600/The-best-top-desktop-dolphin-wallpapers-hd-dolphins-wallpaper-3.jpg';<br />file_put_contents('image.jpg',<br />&nbsp;&nbsp;&nbsp; file_get_contents($lnk));&nbsp;&nbsp;&nbsp; <br />?&gt;</b><br /> &nbsp;&nbsp;&nbsp; </div> <br /> <br /> <br /> <br /> <u><span style="color: blue;"><b>Code Description</b></span></u><br /> <b>&nbsp;<a href="http://newprograminglogics.blogspot.in/2012/04/extend-maximum-execution-time-of-php.html">set_time_limit(300) ;</a></b>&nbsp;&nbsp; This statement is used to set the maximum execution time for the php script.It's default value&nbsp; is 60 seconds.&nbsp; Set this to 300 seconds allow the time to download the image.<br /> &nbsp;$lnk holds the URL of a wallpaper image to be download.<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;<a href="http://php.net/manual/en/function.file-get-contents.php"><b> file_get_contents()</b></a> is used for get the contents from URL. Where<a href="http://php.net/manual/en/function.file-put-contents.php"><b> file_put_contents()</b></a> is used<br /> &nbsp;to write these contents to a file.<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The lnk is given to the parameter to&nbsp;&nbsp; <b style="color: blue;">file_get_contents()</b>.&nbsp; The return data from this and<br /> the name of file to be saved is given to <b style="color: blue;">file_put_contents()</b>.&nbsp; Here all these are written in single step.<br /> When you run this script the image will downloaded&nbsp; to the location where your php page is saved<br /> with the name <b>'image.jpg'</b>.&nbsp; To change the download location give it to<span style="color: blue;"> </span><b style="color: blue;">file_put_contents()</b> parameter<br /> like this <b style="color: blue;">file_put_contents(<i> 'imgfolder/img/image.jpg' , '...'</i>&nbsp; ); </b><br /> <br /> Also read this :- <a href="http://newprograminglogics.blogspot.in/2012/04/include-page-from-url-in-php.html">Include a page from url in php</a><br /> <br /> Hope that this post is helpful to you.<br /> Thanks By Sukesh B R</div> </div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com1tag:blogger.com,1999:blog-5725016407743583511.post-13106804032810331522012-04-17T05:15:00.000-07:002012-04-28T03:04:31.047-07:00Add tool tip text to HTML elements<div dir="ltr" style="text-align: left;" trbidi="on"> <style type="text/css"> .code{ border:2px solid #000000; padding:10px 40px; background:#ccffff; border-radius:8px; } </style> <br /> <div dir="ltr" style="text-align: left;" trbidi="on"> <style type="text/css"> .code{ border:2px solid #ffffff; padding:10px 40px; background:#ccffff; border-radius:8px; } </style> <br /> <div dir="ltr" style="text-align: left;" trbidi="on"> <div dir="ltr" style="text-align: left;" trbidi="on"> Hi friends ,<br /> Have you Think about <b style="color: red;">giving tool tip text to HTML elements?</b><br /> Today I am going to discuss <b style="color: red;">add tool tip text to HTML elements</b>.OR<b style="color: red;"> add a short descriptions to<br />links or buttons in HTML</b>.OR <b><span style="color: red;">the use of title attribute in HTML.</span></b><br /> <br /> &nbsp;<b>&nbsp;&nbsp;&nbsp;&nbsp; Tool tip</b> text is defined as a short description given to a link or button which gives information<br /> about what the link is for.<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b> title</b> attribute is used to create a tool tip text(Not the &lt;title&gt; tag). Just like other attributes type like this<br /> <b>tiltle="description"</b>.<br /> <br /> <u style="color: blue;"><b>1. For add a tool tip to a link</b></u><br /> <br /> <div class="code"> <b>&lt;a title="Link to Google" href="www.google.com"&gt;This is a link&lt;/a&gt;</b></div> <br /> <br /> The resultant screenshot is given belove :- <br /> <br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTHfl_iwqgici9mag99qNMN0r6WsbaYw_quRmTZIvqptx7KEIWtYW_Kgic5htYPKidV4FYyT6D8lc6B_lU8t9JVgLEEPpyi16nRLy8SvqbbyxaMT9xmHjmHHjJIyyolezeHjbfbYukRuV0/s1600/tooltip1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTHfl_iwqgici9mag99qNMN0r6WsbaYw_quRmTZIvqptx7KEIWtYW_Kgic5htYPKidV4FYyT6D8lc6B_lU8t9JVgLEEPpyi16nRLy8SvqbbyxaMT9xmHjmHHjJIyyolezeHjbfbYukRuV0/s320/tooltip1.JPG" width="320" /></a></div> <br /> <br /> <br /> <br /> <br /> <div style="color: blue;"> <br /></div> <u style="color: blue;"><b>2. For add a tool tip to a Button</b></u><br /> <br /> <br /> <div class="code"> <b>&lt;input type="button" title="This is a button"value="Button"&gt;</b></div> <br /> <br /> The resultant screenshot is given belove :-<br /> <br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjysrLOewU7-zhaxZnzR3AtF-Fw2AOk36KDik4n-KHd3ZYALwz-su8KxX8PXdI7kFEsfNn_HyDEXc2XeRZ01j5mDU3BLB2K8sCjnDIElSumXstx0_J8KrpIXtHqcJLFuAJsvyHm7BDs8_HJ/s1600/tooltip2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjysrLOewU7-zhaxZnzR3AtF-Fw2AOk36KDik4n-KHd3ZYALwz-su8KxX8PXdI7kFEsfNn_HyDEXc2XeRZ01j5mDU3BLB2K8sCjnDIElSumXstx0_J8KrpIXtHqcJLFuAJsvyHm7BDs8_HJ/s320/tooltip2.JPG" width="320" /></a></div> &nbsp; <br /> <br /> <br /> <u style="color: blue;"><b>3. For add a tooltip to a Textbox :-</b></u><br /> <br /> <br /> <div class="code"> <b>&lt;input type="text" title="This is a Textbox"&gt;</b></div> <br /> <br /> The resultant screenshot is given belove :-<br /> <br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ3RWdWlgZPAl93Ze_azB0Aa10IYPL2RrCdJiXWTByIKdol3BX17QtQgBwILf1kSgQitQ9Lo3wOTUKI3vW4BmyXIf1mKckrEWywKqJgKA4Slj7W1g-JXwUrbxhQDdf9pBiSZWzCku5pxEx/s1600/tooltip3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ3RWdWlgZPAl93Ze_azB0Aa10IYPL2RrCdJiXWTByIKdol3BX17QtQgBwILf1kSgQitQ9Lo3wOTUKI3vW4BmyXIf1mKckrEWywKqJgKA4Slj7W1g-JXwUrbxhQDdf9pBiSZWzCku5pxEx/s320/tooltip3.JPG" width="320" /></a></div> <br /> <br /> <b>The title attribute is not valid in: &lt;base&gt;, &lt;head&gt;, &lt;html&gt;, &lt;meta&gt;, &lt;param&gt;, &lt;script&gt;, &lt;style&gt;, and &lt;title&gt;.</b><br /> Hope that this post is helpful to you.<br /> &nbsp; <b>By Sukesh B R</b></div> </div> </div> </div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-4856181906244205442012-04-13T04:54:00.000-07:002012-06-03T03:32:25.189-07:00Pass parameter to another page in PHP<div dir="ltr" style="text-align: left;" trbidi="on"> <style type="text/css"> .code{ border:2px solid #000000; padding:10px 40px; background:#ccffff; border-radius:8px; } </style> <br /> <div dir="ltr" style="text-align: left;" trbidi="on"> <div dir="ltr" style="text-align: left;" trbidi="on"> I am discussing <b><span style="font-size: small;"><span style="color: red;">How to pass parameters as type GET to another page</span></span></b>. OR <b><span style="font-size: small;"><span style="color: red;">Pass parameters as GET without using a form</span></span></b>.OR <b><span style="color: red; font-size: small;">Pass parameters through URL</span></b>.<br /> <br /> When we are using a form of method <a href="http://www.roseindia.net/html/html-get-method.shtml"><b>GET</b></a> the values of text boxes enclosed in the form are<br /> send to the action page through the <b>URL</b>.We can also <span style="font-size: small;"><b><span style="color: red;">send values through URL without a form</span></b></span>.<br /> <br /> <br /> If we want to pass a variable to another page when click a link<br /> <div class="code"> <b>&lt;a href="target.php?n1=5"&gt;Click Here&lt;/a&gt;</b></div> <br /> <br /> If we want to pass more than 1 values seperate them with ' &amp; '.<br /> <div class="code"> <b>&lt;a href="target.php"?n1=5&amp;n2=10&amp;name=sbr&gt;Click Here&lt;/a&gt;</b></div> <br /> <br /> In target.php the values can be retrieved just like form values send as <b>GET</b> method.<br /> That is<br /> <div class="code"> <b>$n1=$_GET["n1"];</b><br /> <b>$n2=$_GET["n2"];</b><br /> <b>$name=$_GET["name"];</b></div> <br /> <b><br /></b><br /> <div style="color: black;"> <br /></div> <div style="color: black;"> <br /></div> <div style="color: black;"> <br /></div> <div style="color: black;"> <b>When we want to send values of php variables , these code may be helpful</b></div> <br /> <div style="color: blue;"> <u><span style="font-size: large;">1.Pass a single value to another page</span></u></div> <br /> <div style="color: blue;"> <div black;"="" class="code" color:="" style="color: black;"> <div style="color: blue;"> <u><b>t1.php</b></u></div> <b>&lt;?php</b><br /> <b>$n1=5;</b><br /> <b>?&gt;</b><br /> <b><br /></b><br /> <b>&lt;a href="target.php?n1=&lt;?php echo $n1 ;?&gt;"&gt;Click Here&lt;/a&gt; </b><br /> <br /> <div style="color: blue;"> <u><b>target.php</b></u></div> <b>&lt;?php</b><br /> <b>echo $_GET["n1"];</b><br /> <b>?&gt;</b></div> <br /> <div style="color: blue;"> <u><span style="font-size: large;"><br /></span></u></div> <div style="color: blue;"> <u><span style="font-size: large;">2.Pass more than one value to another page</span></u></div> <br /> <div class="code"> <b><u>t1.php</u></b><br /> <br /> <div style="color: black;"> <b>&lt;?php</b></div> <div style="color: black;"> <b>$n1=5;</b></div> <div style="color: black;"> <b>$n2=7;</b></div> <div style="color: black;"> <b>?&gt;</b></div> <div style="color: black;"> <b><br /></b></div> <div style="color: black;"> <b>&lt;a href="target.php?n1=&lt;?php echo $n1 ;?&gt;&amp;n2=&lt;?php echo $n2;?&gt;"&gt;Click Here&lt;/a&gt;</b></div> <br /> <u><b>target.php</b></u><br /> <br /> <b style="color: black;">&lt;?php<br />echo $_GET["n1"];<br />echo $_GET["n2"];<br />?&gt;</b></div> <br /> <span style="color: black;">You can see these two examples of using this&nbsp; method here :- </span><br /> <br /> <div style="color: black;"> <a href="http://newprograminglogics.blogspot.in/2011/11/varying-number-of-text-boxes-in-html.html">Varying number of text boxes in HTML form by user </a></div> <br /> <a href="http://newprograminglogics.blogspot.in/2011/11/change-font-size-of-text-in-html-page.html"><span style="font-size: small;"><span style="color: black;">Change font size of text in HTML page dynamically using&nbsp; php</span></span></a><br /> <br /> <br /> <br /> <div style="color: black;"> Hope that this post is helpful to you.</div> <div style="color: black;"> By <b>Sukesh B R </b></div> </div> </div> </div> </div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-19405460206968796032012-04-05T04:12:00.001-07:002012-06-03T03:41:33.841-07:00ACCESS $_GET , $_POST , $_SESSION using javascript<div dir="ltr" style="text-align: left;" trbidi="on"> <div dir="ltr" style="text-align: left;" trbidi="on"> Hi friends I am going to discuss <span style="font-size: large;"><span style="color: red;">Access $_GET or $_POST or $_SESSION using javascript</span></span>.<br /> In other words <span style="font-size: large;"><span style="color: red;">access parameters send by form as POST or GET method or</span><br style="color: red;" /><span style="color: red;">Read the session variables in the server using javascript.</span></span><br /> <br /> <br /> &nbsp;&nbsp;&nbsp;<span style="color: blue; font-size: large;"> 1.Access $_GET values using javascript</span><br /> <br /> <u style="color: blue;"><b>Code</b></u><br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> <b>&lt;html&gt;</b><br /> <b><br /> </b><br /> <b>&lt;head&gt;</b><br /> <b><br /> </b><br /> <b>&nbsp; &lt;script type="text/javascript"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var $_GET = &lt;?php echo json_encode($_GET); ?&gt;;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert($_GET["n1"]);&nbsp; </b><br /> <b>&nbsp; &lt;/script&gt;</b><br /> <b><br /> </b><br /> <b>&lt;/head&gt;</b><br /> <b><br /> </b><br /> <b><br /> </b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;body&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;form method="GET"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="text" name="n1"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="submit"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/form&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/body&gt;</b><br /> <b><br /> </b><br /> <b><br /> </b><br /> <b>&lt;/html&gt;</b></div> <br /> <div style="color: blue;"> <u><b>Code Description</b></u></div> <br /> <a href="http://php.net/manual/en/function.json-encode.php"><b>json_encode()</b></a> is the core function using here.In the javascript section a variable named <b>$_GET</b><br /> is declared.This variable is assigned with the<span style="color: blue;"> </span><b style="color: blue;">$_GET array of php page</b>.This is done by this statement :<br /> <b>var $_GET = &lt;?php echo json_encode($_GET); ?&gt;; </b><br /> <i>Dont forget the semicolon at the end.</i><br /> All the parameters passed as<b> GET</b> to the page will stored in the variable.These values can be retrived<br /> by their name.That is the name of the textbox in the html page.Here my textbox's name is 'n1'.So I use<br /> <b><span style="color: blue;">$_GET["n1"]</span></b> to access the value of n1.<br /> save it as a php file(.php extension) and run.<br /> <br /> <br /> <br /> &nbsp;<b>&nbsp; <span style="font-size: large;"><span style="color: blue;">2.Access $_POST values using javascript</span></span></b><br /> <br /> <div style="color: blue;"> <u><b>Code</b></u></div> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> <b>&lt;html&gt;</b><br /> <b><br /> </b><br /> <b>&lt;head&gt;</b><br /> <b><br /> </b><br /> <b>&nbsp; &lt;script type="text/javascript"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var $_POST = &lt;?php echo json_encode($_POST); ?&gt;;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert($_POST["n1"]);&nbsp; </b><br /> <b>&nbsp; &lt;/script&gt;</b><br /> <b><br /> </b><br /> <b>&lt;/head&gt;</b><br /> <b><br /> </b><br /> <b><br /> </b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;body&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;form method="POST"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="text" name="n1"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="submit"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/form&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/body&gt;</b><br /> <b><br /> </b><br /> <b><br /> </b><br /> <b>&lt;/html&gt;</b><br /> <br /></div> <div style="color: blue;"> <br /> <u><b>Code Description</b></u></div> <br /> <a href="http://php.net/manual/en/function.json-encode.php"><span style="color: blue;">json_enc<span id="goog_432138631"></span><span id="goog_432138632"></span>ode()</span></a>&nbsp; is the core function using here.In the javascript section a variable named <b>$_POST</b><br /> is declared.This variable is assigned with the $_POST array of php page.This is done by this statement :<br /> <div style="color: blue;"> <b>var $_POST = &lt;?php echo json_encode($_POST); ?&gt;; </b></div> Dont forget the semicolon at the end.<br /> All the parameters passed as POST to the page will stored in the variable.These values can be retrived<br /> by their name.That is the name of the textbox in the html page.Here my textbox's name is 'n1'.So I use<br /> <b style="color: blue;">$_POST["n1"] </b>to access the value of n1.<br /> <br /> save it as a php file(.php extension) and run.<br /> <br /> &nbsp; <br /> <div style="color: blue;"> <span style="font-size: large;">&nbsp;&nbsp; 3.Access $_SESSION values using javascript</span></div> <br /> <br /> <div style="color: blue;"> <u><b>Code </b></u></div> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> <b>&lt;?php session_start(); ?&gt;</b><br /> <b>&lt;html&gt;</b><br /> <b><br /> </b><br /> <b>&lt;head&gt;</b><br /> <b><br /> </b><br /> <b>&nbsp; &lt;script type="text/javascript"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var $_SESSION = &lt;?php echo json_encode($_SESSION); ?&gt;;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert($_SESSION["ns"]);&nbsp; </b><br /> <b>&nbsp; &lt;/script&gt;</b><br /> <b><br /> </b><br /> <b>&lt;/head&gt;</b><br /> <b><br /> </b><br /> <b><br /> </b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;body&gt;</b><br /> <b>&lt;?php</b><br /> <b>$_SESSION["ns"]="SESSION_VALUE";</b><br /> <b>?&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;form method="POST"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="text" name="n1"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type="submit"&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/form&gt;</b><br /> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/body&gt;</b><br /> <b><br /> </b><br /> <b><br /> </b><br /> <b>&lt;/html&gt;</b></div> <div style="color: blue;"> <br /> <u><b>Code Description</b></u></div> <br /> <a href="http://php.net/manual/en/function.json-encode.php">json_encode()</a> is the core function using here.<br /> First of all in a php section we call the function <a href="http://php.net/manual/en/function.session-start.php"><b style="color: blue;">session_start()</b></a>.This is for accessing SESSION variable in php.<br /> In the javascript section a variable named <b>$_SESSION&nbsp;</b> is declared.This variable is assigned with the <b style="color: blue;">$_SESSION array of php page</b>.<br /> This is done by this statement :<br /> <b style="color: blue;">var $_SESSION = &lt;?php echo json_encode($_SESSION); ?&gt;;</b> <br /> Dont forget the semicolon at the end.<br /> All the SECTION variables&nbsp; will be stored in the variable <b>$_SESSION</b>.These values can be retrived<br /> by their name.Here my section variable's&nbsp; name is 'ns'.So I use<br /> <b>$_POST["ns"]</b> to access the value of 'ns'.<br /> save it as a php file(.php extension) and run.<br /> <br /> You can also read :-</div> <div dir="ltr" style="text-align: left;" trbidi="on"> <a href="http://newprograminglogics.blogspot.in/2012/06/delete-non-empty-directory-in-php.html"><b>Delete non empty directory in php</b></a></div> <div dir="ltr" style="text-align: left;" trbidi="on"> <a href="http://www.blogger.com/goog_1640930334">Extend maximum execution time of php script</a><b><a href="http://newprograminglogics.blogspot.in/2012/04/extend-maximum-execution-time-of-php.html"> </a></b><br /></div> </div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com1tag:blogger.com,1999:blog-5725016407743583511.post-82223464316271324802012-02-02T08:45:00.000-08:002012-02-03T09:35:21.768-08:00Change the text typed in a text box to upper case using CSS<div dir="ltr" style="text-align: left;" trbidi="on">Hi friends ,<br /> Today my discussion is about <span style="font-size: large;"><b style="color: blue;">change the</b><b><span style="font-size: large;">&nbsp; </span><span style="color: blue;">text typed in a HTML </span><br style="color: blue;" /><span style="color: blue;">text box into uppercase</span></b></span>.&nbsp;&nbsp; It can be simply achieve using a simple CSS <br /> property <span style="font-size: small;"><b>text-transform</b></span>.<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; We only set the text-transform to uppercase just like this&nbsp; :<br /> <b>text-transform:uppercase</b><br /> <br /> Here is the sample code<br /> <b>&lt;html&gt;</b><br /> <b>&lt;body&gt;</b><br /> <b>&lt;input type="text" style="text-transform:uppercase"&gt;</b><br /> <b>&lt;/body&gt;</b><br /> <b>&lt;/html&gt;</b><br /> <br /> <br /> Here&nbsp; the usage of <b style="color: blue;">style</b> parameter is<b> inline CSS</b>.&nbsp;&nbsp; In the style parameter<br /> of <b>&lt;input&gt; </b>contains text-transform:uppercase. It instructs the browser<br /> to transform the text typed in the text box to upper case.<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Other <b style="color: blue;">possible values for text-transform</b> parameter are<br /> <b>lowercase</b> and <b>capitalize</b>.<br /> <b>&nbsp;text-transform:lowercase</b> convert the text typed to lowercase.<br /> &nbsp;<b>text-transform:capitalize</b> convert the first letter of each word of text typed to uppercase.<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hope that this post will be helpful to you.<br /> &nbsp;Thanks by Sukesh B R</div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-16616801910467086652012-01-14T08:35:00.000-08:002012-05-26T08:49:33.967-07:00Open a new browser window using javascript<div dir="ltr" style="text-align: left;" trbidi="on"> Hi friends,<br /> &nbsp;&nbsp; Here I am discuss about<span style="color: blue; font-size: large;"> open a new browser window when click a button<br /> using javascript</span>.Have you see pop up windows containing advertisements?<br /> We can create like one very easily.<br /> &nbsp;&nbsp; <br /> &nbsp;&nbsp; The <b>javascript function</b> used for pop up a new window is <b style="color: blue;">window.open()</b>.<br /> The syntax for window.open is :<br /> <b><span style="font-size: small;">window.open('http://www.google.com','window_name','width=400,height=200');</span></b><br /> <br /> &nbsp;&nbsp; In this function first parameter is the URL of the website to be loaded<br /> in the poped up window opened.Here I am use the address of&nbsp; <b>Google.com</b>.<br /> <br /> &nbsp;&nbsp; The second parameter of <b>open()</b> function is the <b style="color: blue;">name of the window</b>.We<br /> can use this name to access the window later.<br /> <br /> &nbsp;&nbsp; The third parameter is using to <b style="color: blue;">set the dimensions of the window</b> which is poped up.<br /> <br /> <b><u>Code of a simple form pop up the Google in a new window</u></b>:<br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> <b>&lt;FORM&gt;<br /> &lt;INPUT type="button" value="Click Me" onClick="window.open('http://www.google.com','Google','height=600,width=600')"&gt;<br /> &lt;/FORM&gt; </b></div> <br /> <br /> <br /> &nbsp; Here the <b>window.open()</b> function is called in the <b style="color: blue;">onclick</b> event of the button in the form.When click in the button , a pop up window with <b>600 pixel height and 600 pixel width </b>is opened and google.com will load in it in no time.<br /> <br /> &nbsp; In the third parameter we can include more options like the position of the window.We can use the top and left parameters to set the top and left of the window.<br /> <br /> <div style="background: #ccffff; border-radius: 8px; border: 2px solid #000000; padding: 10px 40px;"> <b>&lt;FORM&gt;<br /> &lt;INPUT type="button" value="Click Me" onClick="window.open('http://www.google.com','Google','height=600,width=600,left=0,top=100')"&gt;<br /> &lt;/FORM&gt; </b></div> <br /> <br /> This code will open a window with 600 pixels height and width and the top left of the window will be <b>(0,100)</b>.<br /> <b style="color: blue;">But one thing to be noted is that all these are belongs to the third parameter so these are within a single inverter comma('').</b><br /> <br /> <br /> We can also specify that which tool bars will appear in our new window just like this<br /> <b>window.open ("http://www.javascript-coder.com", "mywindow","status=yes,toolbar=no");</b><br /> By this code I am <b>allowing the status bar and disallow toolbar</b>.<br /> <u><br /> &nbsp; The other values set in the<b> <span style="color: blue;">third parameter</span></b> is as follows <b>:</b></u><br /> <br /> <b>status&nbsp;&nbsp;&nbsp;&nbsp; : &nbsp;&nbsp;&nbsp; The status bar at the bottom of the window.<br /> toolbar&nbsp;&nbsp;&nbsp; : &nbsp;&nbsp;&nbsp; The standard browser toolbar, with buttons such as Back and Forward.<br /> location&nbsp;&nbsp; : &nbsp;&nbsp;&nbsp; The Location entry field where you enter the URL.<br /> menubar&nbsp;&nbsp;&nbsp; :&nbsp;&nbsp;&nbsp; The menu bar of the window<br /> directories: &nbsp;&nbsp;&nbsp; The standard browser directory buttons, such as What’s New and What’s Cool<br /> resizable&nbsp; :&nbsp;&nbsp;&nbsp; Allow/Disallow the user to resize the window.<br /> scrollbars :&nbsp;&nbsp;&nbsp; Enable the scrollbars if the document is bigger than the window </b><br /> <br /> &nbsp;<b>&nbsp; windows.close() can be used to close the opened window.</b><br /> <b style="color: blue;">Another thing to be noted is that many browsers block the opening of pop up windows.So inorder to work&nbsp; the code above explained please unblock the pop up windows in your browser's setting</b>s.<br /> <br /> I am including a screen shot :<br /> <br /> <br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcXL5ApAVfQxphKVqG4oSoWRcGIGQF_TM77hH_DsRIjpesJqimpaTXyl-WXbQB2BPJ0vjrcwu_7VRsQBXKF8MncQTDeTBanzJ6MsnxOfU72R75TGM7nXlVF0fyDL8f8fuZo7NlKoSHfW6d/s1600/new_window.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcXL5ApAVfQxphKVqG4oSoWRcGIGQF_TM77hH_DsRIjpesJqimpaTXyl-WXbQB2BPJ0vjrcwu_7VRsQBXKF8MncQTDeTBanzJ6MsnxOfU72R75TGM7nXlVF0fyDL8f8fuZo7NlKoSHfW6d/s400/new_window.JPG" width="400" /></a></div> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> Thank you to my dear friends.<br /> You can read :- <br /> <h3 class="post-title entry-title" itemprop="name" style="font-weight: normal;"> <a href="http://newprograminglogics.blogspot.in/2012/05/facebook-like-pop-up-window-using.html">Facebook like pop up window using jquery</a></h3> <br /> By Sukesh B R</div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com0tag:blogger.com,1999:blog-5725016407743583511.post-16936256225865571482012-01-12T23:43:00.000-08:002012-01-12T23:43:06.297-08:00Multiple submit buttons in a Form in PHP explain with an example<div dir="ltr" style="text-align: left;" trbidi="on"><div style="font-family: &quot;Courier New&quot;,Courier,monospace;">Hi friends, today I am discussing<span style="color: blue;"> </span><span style="color: blue; font-size: large;"><b>handling multiple submit buttons in a single Form in PHP</b></span>.<br /> &nbsp;</div><div class="separator" style="clear: both; font-family: &quot;Courier New&quot;,Courier,monospace; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoQrFNu7ZWHcgdDIC0CFPfvjUqEXPS-Ar0aAxWE408zgqkT8NA6TDdWrIecB1VMqdBUz3gTsIoe9Up9OqVQ1lUIMfZ9KyB7czvgK-sIPVP1SwZZjfqpuUvxn34rFt_GjQ_8K8OoUXd6Cnu/s1600/multi_form.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /> </a></div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;">According to typical <b>HTML architecture </b>there have <b>one submit button for a Form</b>.When this submit button&nbsp; is clicked the <b>php page</b> specified by the form action parameter is loaded.<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; But some situations we need <b style="color: blue;">multiple submit buttons</b> in a single form.In such situations the php page loaded by clicking distinct buttons is same.But the task executed will be different.We can achieve it by isset()&nbsp; function of PHP.<br /> &nbsp;&nbsp;</div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The syntax for isset() is : <b>isset($_POST["<i>name of submit button in the form</i>"])</b> <br /> <br /> We can write the&nbsp; code for the action page like this:-<br /> &nbsp;</div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;">&lt;?Php<br /> if(isset($_POSt["s1"]))<br /> {<br /> echo "You pressed submit 1";<br /> }<br /> <br /> else if(isset($_POSt["s2"]))<br /> {<br /> echo "You pressed submit 2";<br /> }<br /> ?&gt;<br /> <br /> Where <b>s1</b> and <b>s2</b> are the name of submit buttons in the form.<br /> <br /> Here I am including a <b><span style="color: blue;">simple calculator example</span></b> to clear&nbsp; this concept<br /> <br /> This is a screen shot of the program:</div><div class="separator" style="clear: both; font-family: &quot;Courier New&quot;,Courier,monospace; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoQrFNu7ZWHcgdDIC0CFPfvjUqEXPS-Ar0aAxWE408zgqkT8NA6TDdWrIecB1VMqdBUz3gTsIoe9Up9OqVQ1lUIMfZ9KyB7czvgK-sIPVP1SwZZjfqpuUvxn34rFt_GjQ_8K8OoUXd6Cnu/s1600/multi_form.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoQrFNu7ZWHcgdDIC0CFPfvjUqEXPS-Ar0aAxWE408zgqkT8NA6TDdWrIecB1VMqdBUz3gTsIoe9Up9OqVQ1lUIMfZ9KyB7czvgK-sIPVP1SwZZjfqpuUvxn34rFt_GjQ_8K8OoUXd6Cnu/s320/multi_form.JPG" width="320" /></a></div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;"></div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;"></div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;"></div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;"></div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;"><br /> &nbsp;</div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;"><b><u><span style="font-size: large;">Source code</span></u></b></div><div style="font-family: &quot;Courier New&quot;,Courier,monospace; text-align: center;"><u><b>calculator.html</b></u></div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;"><br /> </div><div style="font-family: &quot;Courier New&quot;,Courier,monospace; text-align: center;">&lt;html&gt;<br /> &lt;body&gt;<br /> &lt;form name="f1" method="post" action="sub.php"&gt;<br /> Number1 &lt;input type="text" name="n1"&gt;&lt;/br&gt;&lt;/br&gt;<br /> Number2 &lt;input type="text" name="n2"&gt;<br /> &lt;/br&gt;&lt;/br&gt;<br /> &lt;input type="submit" name="add" value="+"&gt;<br /> &lt;input type="submit" name="sub" value="-"&gt;<br /> &lt;input type="submit" name="mul" value="*"&gt;<br /> &lt;input type="submit" name="div" value="/"&gt;<br /> &lt;/form&gt;<br /> &lt;/body&gt;<br /> &lt;/html&gt;</div><div style="font-family: &quot;Courier New&quot;,Courier,monospace; text-align: left;"><br /> <u style="font-family: inherit;"><b>&nbsp;</b></u><u style="font-family: inherit;"><b>sub.php&nbsp;</b></u></div><br /> <div style="font-family: &quot;Courier New&quot;,Courier,monospace; text-align: left;"><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">&lt;?php</span><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">if(isset($_POST["add"]))</span><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">echo "Sum : ".($_POST["n1"]+$_POST["n2"]);</span><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">else if(isset($_POST["sub"]))</span><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">echo "Difference : ".($_POST["n1"]-$_POST["n2"]);</span><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">else if(isset($_POST["mul"]))</span><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">echo "Product : ".($_POST["n1"]*$_POST["n2"]);</span><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">else if(isset($_POST["div"]))</span><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">echo "Quotient : ".($_POST["n1"]/$_POST["n2"]);</span><br style="font-family: &quot;Courier New&quot;,Courier,monospace;" /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">?&gt;</span><br /> <br /> <u><b><br /> code description:</b></u><br /> <br /> In calculator.html we can see a form.There have <span style="color: blue;">2 text boxes and 4 submit buttons</span>.The two submit buttons are the<br /> two numbers to perform arithmetic operations.The four submit buttons are for additon,substraction,multiplication and division.<br /> The name of the submit buttons are add,sub,mul,div respectively. <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In sub.php <span style="color: blue;">four if else statements</span> are used to determine which submit button is clicked. <br /> &nbsp;</div><div style="font-family: &quot;Courier New&quot;,Courier,monospace; text-align: left;">First if is: <br /> <b>if(isset($_POST["add"]))</b><br /> Where <b>'add'</b> is the name of first submit button.<b>isset($_POST["add"])</b>&nbsp; return <b>TRUE</b> if the submit button clicked is <b>'add'</b>.If it return true&nbsp;</div><div style="font-family: &quot;Courier New&quot;,Courier,monospace; text-align: left;"><b style="color: black;">echo "Sum : ".($_POST["n1"]+$_POST["n2"]);</b>&nbsp;</div><div style="font-family: &quot;Courier New&quot;,Courier,monospace; text-align: left;">this statement will execute.So the sum of given numbers will be displayed.<br /> If isset() returns FALSE go to the next if statement and check for the click of next submit button.This process will be continued till the clicked button is found.Thus our calculator works properly.<br /> <br /> <span style="color: blue;">isset()</span> is the standard way to achieve this but we can simply write<br /> <b>if($_POST["add"])<br /> {<br /> echo "Sum : ".($_POST["n1"]+$_POST["n2"]);<br /> }&nbsp; </b><br /> for achive the same result.<br /> <br /> Hope that this post is helpful to you.Thanks by Sukesh B R</div><div style="font-family: &quot;Courier New&quot;,Courier,monospace;"></div></div>Sukesh B Rhttp://www.blogger.com/profile/07439990768779619750noreply@blogger.com3