How to display Data in mysql using php

Leave a Comment



Step no 1: 
Open your localhost/phpmyadmin if you don’t have xamp or wamp server you can download at this link for free : http://www.wampserver.com/en/

After installing your wamp server or xamp server for your database now type this words at your browser in my case I use google Chrome.


Step 2: Creating Database name..

Then click the create..
Step 3: After your click the create the database name will appear in the side of your server..then click the SQL and paste the some code for the sample of this tutorial..

-- phpMyAdmin SQL Dump
-- version 3.3.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 27, 2017 at 01:21 AM
-- Server version: 5.5.8
-- PHP Version: 5.3.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `student`
--

-- --------------------------------------------------------

--
-- Table structure for table `student1`
--

CREATE TABLE IF NOT EXISTS `student1` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `middlename` varchar(255) DEFAULT NULL,
  `lastname` varchar(255) DEFAULT NULL,
  `age` varchar(255) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

--
-- Dumping data for table `student1`
--

INSERT INTO `student1` (`id`, `name`, `middlename`, `lastname`, `age`, `date`) VALUES
(1, 'Alexis', 'Q', 'Banayat', '17', '2017-01-07 00:00:00'),
(2, 'Shyna', 'R', 'Comesario', '16', '2017-01-11 00:00:00'),
(3, 'Argentina', 'Y', 'Dacanay', '19', '2017-01-02 00:00:00'),
(4, 'Arman', 'C.', 'Ruelo', '70', '2017-02-07 00:00:00'),
(5, 'Jess Drian', 'P', 'Estrada', '85', '2017-02-20 00:00:00'),
(6, 'Alexis', 'Q', 'Banayat', '17', '2017-01-15 00:00:00'),
(7, 'Shyna', 'R', 'Comesario', '16', '2017-01-06 00:00:00'),
(8, 'Argentina', 'Y', 'Dacanay', '19', '2017-02-25 00:00:00'),
(9, 'Arman', 'C.', 'Ruelo', '70', '2017-01-06 00:00:00'),
(10, 'Jess Drian', 'P', 'Estrada', '85', '2017-01-23 00:00:00');

Paste the code and click GO for executing your database..
This is the data in your database..


Step 4: download the sublime for displaying the data in php code..if you don’t have sublime installer you can use the notepad++ or notepad  and copy the code..

<?php
$conn=mysql_connect('localhost','root','');
mysql_select_db('student');
if($conn)
{
                 
}
else
{
                die();
}
 ?>









After all the step we can create now a code for displaying the data coming from sql database since the connection code already created we can now create a code to display content in our database…

Step 4:
create new notepad page or sublime new page.. and paste this code

<?php

include 'conn.php';
             $sql=mysql_query('select * from student1 ')or die(mysql_error());
 
                  while($result=mysql_fetch_array($sql)){
                    $id = ''. ucfirst($result['id']). '';
                    $name = ''. ucfirst($result['name']). '';
                    $middlename = ''. ucfirst($result['middlename']). '';
                    $lastname = ''. ucfirst($result['lastname']). '';
                   
                  }
                  echo ''.$name.'';
                  echo '&nbsp;&nbsp;&nbsp;';
                  echo ''.$middlename.'';
                  echo '&nbsp;&nbsp;&nbsp;';
                  echo ''.$lastname.'';


?>


Since the code is done.. we can now test the page if they will display the data coming from database..
Open the chrome and type this link ..  localhost/student/


Follow me in Google and like my page for more coming tutorial ..Thanks

Source code of this file : DOWNLOAD HERE
like my page in facebook: CrazyDeveloper



If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment