<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL Archives</title>
	<atom:link href="https://www.johnpatel.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>SEO, WordPress, Make Money, Online Jobs, Reviews</description>
	<lastBuildDate>Mon, 01 Apr 2019 18:56:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
<site xmlns="com-wordpress:feed-additions:1">145939692</site>	<item>
		<title>MySQL Limit Query Implementation in PHP</title>
		<link>https://www.johnpatel.com/mysql-limit-query-php/</link>
		
		<dc:creator><![CDATA[JP]]></dc:creator>
		<pubDate>Tue, 25 Dec 2018 09:03:39 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">https://www.johnpatel.com/?p=958</guid>

					<description><![CDATA[<p>MySQL Limit Query generally used in pagination purpose. I will show you how you can implement in PHP and MySQL. First of all, let&#8217;s see the syntax of SQL limit. MySQL Limit Syntax SELECT * FROM table_name LIMIT start_from, total_results; This is the basic syntax where&#8230; table_name shows the database table name start_from shows the [&#8230;]</p>
<p>The post <a href="https://www.johnpatel.com/mysql-limit-query-php/">MySQL Limit Query Implementation in PHP</a> appeared first on <a href="https://www.johnpatel.com">JP</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><b>MySQL Limit Query</b> generally used in pagination purpose. I will show you how you can implement in PHP and <a href="https://wikitech.wikimedia.org/wiki/Help:MySQL_queries" target="_blank" rel="noopener noreferrer">MySQL</a>.</p>
<p><img decoding="async" src="https://www.johnpatel.com/wp-content/uploads/2018/12/MySQL-Limit-in-php.jpg" alt="MySQL Limit Query Implementation in PHP" title="MySQL Limit Query Implementation in PHP"></p>
<p>First of all, let&#8217;s see the syntax of SQL limit.</p>
<h2>MySQL Limit Syntax</h2>
<pre><xmp>
SELECT *
FROM table_name
LIMIT start_from, total_results;
</xmp>
</pre>
<p>This is the basic syntax where&#8230;</p>
<ul>
<li><b>table_name</b> shows the database table name</li>
<li><b>start_from</b> shows the starting value from table</li>
<li><b>total_results</b> shows the number of total results to print</li>
</ul>
<h2>Why we have to use MySQL Limit?</h2>
<p>Developers or programmer make the listing page for list out all the details from the database. At that time, if you have small number of results in the database then no worries to fetch results. Because it will give you results immediately. But if you have a large number of data like 1000 rows to fetch then your page will take time to load. Sometimes it takes a very long time and users get panic from it.</p>
<p>This is the time to use the Limit Query. It will help you to fetch 10 or 20 number of results from the database. The best part is it will take very less time to load and a user can get the results very quickly. You can get full tutorial for <a href="#" target="_blank" rel="noopener noreferrer">pagination in php</a> here.</p>
<p>Now, let&#8217;s take some examples for get more idea.</p>
<h3>Example &#8211; 1</h3>
<p>If you want to print just 5 results from database table then you have to write query like below.</p>
<pre><xmp>
SELECT id,name
FROM admin
LIMIT 5;
</xmp>
</pre>
<h3>Output:</h3>
<table>
<tbody>
<tr>
<th><b>ID</b></th>
<th><b>Name</b></th>
</tr>
<tr>
<td>1</td>
<td>John</td>
</tr>
<tr>
<td>2</td>
<td>Suzy</td>
</tr>
<tr>
<td>3</td>
<td>Eathan</td>
</tr>
<tr>
<td>4</td>
<td>James</td>
</tr>
<tr>
<td>5</td>
<td>Binny</td>
</tr>
</tbody>
</table>
<h3>Example &#8211; 2</h3>
<p>Now, if you want to fetch results which is start from 6 to 10. Below query will help you to do this.</p>
<pre><xmp>
SELECT id,name
FROM admin
LIMIT 6, 5;
</xmp>
</pre>
<p>In above query 6 is for starting point and 5 is for number of results you want.</p>
<h3>Output:</h3>
<table>
<tbody>
<tr>
<th><b>ID</b></th>
<th><b>Name</b></th>
</tr>
<tr>
<td>6</td>
<td>Sam</td>
</tr>
<tr>
<td>7</td>
<td>Mansi</td>
</tr>
<tr>
<td>8</td>
<td>Parth</td>
</tr>
<tr>
<td>9</td>
<td>Aditi</td>
</tr>
<tr>
<td>10</td>
<td>Anjali</td>
</tr>
</tbody>
</table>
<h2>SQL Limit Implementation in PHP</h2>
<p>Now, I will show you the MySQL Limit implementation in PHP. Just follow the code below.</p>
<pre><xmp>
<?php 

// Database connection
$con = mysqli_connect("DB_host", "DB_Username", "DB_Password", "DB_Name");

if ($con === false) {
	die("ERROR:: Database not connected. ".mysqli_error($con));
}

// Select first 5 results
$query = "SELECT * FROM name LIMIT 5";
$result = mysqli_query($con, $query) or die ('Error :: in fetch results'.mysqli_error($con));

// Print results in table format
if (mysqli_num_rows($result) > 0)
{
?>
< table border="1">
< tr>
< th><b>ID</a></ th>
< th><b>Name</b></ th>
</ tr>
<?php while ($row = mysqli_fetch_array($result)) { ?>
< tr>
< td><?php echo $row['id']; ?></ td>
< td><?php echo $row['name']; ?></ td>
</ tr>
<?php } ?>
</ table>
<?php

mysqli_free_result($result);
}
else {
  echo "No results found!";
}

// Close database connection
mysqli_close($con);

?> 
</xmp>
</pre>
<h5>Output:</h5>
<p>You will get the output table like this.</p>
<table>
<tbody>
<tr>
<th><b>ID</b></th>
<th><b>Name</b></th>
</tr>
<tr>
<td>1</td>
<td>Samar</td>
</tr>
<tr>
<td>2</td>
<td>Juli</td>
</tr>
<tr>
<td>3</td>
<td>Satyam</td>
</tr>
<tr>
<td>4</td>
<td>Krishna</td>
</tr>
<tr>
<td>5</td>
<td>Urja</td>
</tr>
</tbody>
</table>
<p><b>Releated Articles:</b></p>
<ul>
<li><a href="https://www.johnpatel.com/mysql-insert-query-php/">MySQL Insert Query</a></li>
<li><a href="https://www.johnpatel.com/mysql-update-query/">MySQL Update Query</a></li>
</ul>
<p>The post <a href="https://www.johnpatel.com/mysql-limit-query-php/">MySQL Limit Query Implementation in PHP</a> appeared first on <a href="https://www.johnpatel.com">JP</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">958</post-id>	</item>
		<item>
		<title>MySQL INSERT Query in PHP &#8211; MySQL</title>
		<link>https://www.johnpatel.com/mysql-insert-query-php/</link>
		
		<dc:creator><![CDATA[JP]]></dc:creator>
		<pubDate>Fri, 21 Dec 2018 09:42:02 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">https://www.johnpatel.com/?p=891</guid>

					<description><![CDATA[<p>Hello Friends, Are you looking for a MySQL INSERT Query in PHP &#8211; MySQL. This tutorial is only for you. Even more, I will explain how to implement INSET Query using PHP, MySQL and Command Prompt. Just keep reading the post and get the knowledge. INSERT Query in MySQL Syntax First of all, I will [&#8230;]</p>
<p>The post <a href="https://www.johnpatel.com/mysql-insert-query-php/">MySQL INSERT Query in PHP &#8211; MySQL</a> appeared first on <a href="https://www.johnpatel.com">JP</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hello Friends, Are you looking for a <strong>MySQL INSERT Query in PHP &#8211; MySQL</strong>. This tutorial is only for you. Even more, I will explain how to implement INSET Query using PHP, MySQL and Command Prompt. Just keep reading the post and get the knowledge.</p>
<p><img decoding="async" src="https://www.johnpatel.com/wp-content/uploads/2018/12/MySQL-INSERT-Query-in-PHP-MySQL.jpg" alt="MySQL INSERT Query in PHP - MySQL" title="MySQL INSERT Query in PHP - MySQL"></p>
<h2>INSERT Query in MySQL Syntax</h2>
<p>First of all, I will show you the main syntax of query. So, you can get basic ideas how query looks like and how to enter table name and values in query.</p>
<p>There are 3 methods to write <a href="https://en.wikipedia.org/wiki/Insert_(SQL)" target="_blank" rel="noopener noreferrer">INSERT</a> Query in MySQL. You can use any method among these 3 and insert the value inside the database.</p>
<h6>1) First Method</h6>
<pre><xmp>
INSERT INTO table_name 
( column1, column2,...columnN )
VALUES
( value1, value2,...valueN );
</xmp>
</pre>
<h6>2) Second Method</h6>
<pre><xmp>
INSERT INTO table_name 
VALUES
( value1, value2,...valueN );
</xmp>
</pre>
<h6>3) Third Method</h6>
<pre><xmp>
INSERT INTO table_name 
SET
column1 = 'value1',
column2 = 'value2',
...
</xmp>
</pre>
<p>You can replace table_name with your table and same as column and values.</p>
<h2>INSERT Query in PHP</h2>
<p>You can refer below code and fire insert query in PHP. I have used the method no 3 for insert operation.</p>
<pre><xmp>
<?php 

$DB_Host = 'localhost';
$DB_Name = "database_name"
$DB_Username = 'database_username';
$DB_Password = 'database_password';
$con = mysql_connect($DB_Host,$DB_Username,$DB_Password) or die(mysql_errno());
$db = mysql_select_db("$DB_Name",$con) or die(mysql_error());
				
// INSERT Query
$qry = '
INSERT INTO admin_table
SET 
name = "John Patel",
email = "info@johnpatel.com"
';
$result = mysql_query($qry);

if(!result)
{
  die ('Error:: in insert'.mysql_error());
}
else
{
  echo "Data Inserted Successfully";
}

?>
</xmp>
</pre>
<p>First, you have to connect your database with some code which is written above the query. So, when your connection is proper with the database then you can implement the query.<br />
This query will insert the name as John Patel and email as info@johnpatel.com in database table admin_table. If all goes well then the &#8220;Data Inserted Successfully&#8221; message appears.</p>
<h2>MySQL INSERT using Command Prompt</h2>
<p>Write the syntax below in command promp to fire MySQL INSERT. We will use <strong>SQL INSERT INTO</strong> command to insert values in admin_table.</p>
<pre><xmp>
root@host# mysql -u root -p password;
Enter password:*******
mysql> use DB_Name;
Database changed

mysql> INSERT INTO admin_table 
   ->(name, email, phone)
   ->VALUES
   ->("John Patel", "info@johnpatel.com", "+919909666700");
Query OK, 1 row affected (0.01 sec)
mysql>
</xmp>
</pre>
<p><strong>NOTE:</strong> Please note arrow(-&gt;) signs are not required in SQL command. They are automatically created by CMD and it denotes the new line.</p>
<p>Finally, you can use above all methods and INSERT data in MySQL. I hope you will like this tutorial and it will help you in web development. Please share it if you like it.</p>
<h6>Releated Articles:</h6>
<ul>
<li><a href="https://www.johnpatel.com/mysql-update-query/" alt="MySQL UPDATE Query - Update Query in MySQL">MySQL UPDATE Query</a></li>
<li><a href="https://www.johnpatel.com/mysql-limit-query-php/" alt="MySQL Limit">MySQL Limit</a></li>
</ul>
<p>The post <a href="https://www.johnpatel.com/mysql-insert-query-php/">MySQL INSERT Query in PHP &#8211; MySQL</a> appeared first on <a href="https://www.johnpatel.com">JP</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">891</post-id>	</item>
	</channel>
</rss>
