<?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>Freelance PHP Developer &#187; mysql</title>
	<atom:link href="http://freelance-php-developer.phpmysql.co.za/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://freelance-php-developer.phpmysql.co.za</link>
	<description>Freelance PHP Developer &#124; South Africa</description>
	<lastBuildDate>Sat, 07 Jan 2012 06:42:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP freelancer Retrieving Data in a Range by SQL BETWEEN</title>
		<link>http://freelance-php-developer.phpmysql.co.za/2010/03/php-freelancer-retrieving-data-in-a-range-by-sql-between/</link>
		<comments>http://freelance-php-developer.phpmysql.co.za/2010/03/php-freelancer-retrieving-data-in-a-range-by-sql-between/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 10:12:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Freelance Web Developer]]></category>
		<category><![CDATA[MySQL Tutorials]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php freelancer]]></category>

		<guid isPermaLink="false">http://freelance-php-developer.phpmysql.co.za/?p=70</guid>
		<description><![CDATA[
Working with Database
Create a database with a specified name if it does not exist  in database server
CREATE DATABASE [IF NOT EXISTS] database_name
Use database or change current database to another database  you are working with
USE database_name
Drop a database with specified name permanently. All  physical file associated with the database is no longer exists.
DROP [...]


No related posts.

Related posts brought to you by <a href='http://www.wordpressconnect.net/amazonpress/'>Amazon plugin</a>.]]></description>
			<content:encoded><![CDATA[<div>
<h2>Working with Database</h2>
<p>Create a database with a specified name if it does not exist  in database server</p>
<pre>CREATE DATABASE [IF NOT EXISTS] database_name</pre>
<p>Use database or change current database to another database  you are working with</p>
<pre>USE database_name</pre>
<p>Drop a database with specified name permanently. All  physical file associated with the database is no longer exists.</p>
<pre>DROP DATABASE [IF EXISTS] database_name</pre>
<p>Show all available databases in database server</p>
<pre>SHOW DATABASES</pre>
<h2>Working with Table</h2>
<p>Lists all tables in a database.</p>
<pre>SHOW TABLES</pre>
<p>Create table statement defines the structure of table in a  database.</p>
<pre> CREATE [TEMPORARY] TABLE [IF NOT EXISTS] <em>table_name</em>
 (<em>create_clause ,</em>...) [<em>table_options</em>]
 [[IGNORE|REPLACE] <em>select</em>]</pre>
<p>Altering table structure</p>
<pre>ALTER [IGNORE] TABLE <em>table_name</em> <em>actions</em></pre>
<p>Actions can be one of the following actions:</p>
<pre>ADD [COLUMN]</pre>
<p>Add a new column into a table</p>
<pre>DROP [COLUMN]</pre>
<p>Drop an existing column in a table</p>
<pre>ADD INDEX [name](column_name, ...)</pre>
<p>Add index with a specific name to a table on a column</p>
<pre>DROP INDEX index_name Drop an index from a table</pre>
<p>ADD PRIMARY KEY (column_name,&#8230;)</p>
<p>Add primary key into a tables</p>
<pre>DROP PRIMARY KEY</pre>
<p>Drop primary key from a table</p>
<p>Deleting table permanently</p>
<pre> DROP TABLE [IF EXISTS] <em>table_name</em> [, <em>name2</em>, ...]
 [RESTRICT | CASCADE]
</pre>
<p>Give information about the table or column.</p>
<pre>DESCRIBE table [column_name]
DESC table [column_name]<strong><em>
 </em></strong></pre>
<h2>Working with Index</h2>
<p>Creating an index with the specified name on a table</p>
<pre>CREATE [UNIQUE|FULLTEXT] INDEX index_name
ON table (column_name,...)</pre>
<p>Removing a specified index from table</p>
<pre>DROP INDEX index_name</pre>
<h2>Retrieving Data</h2>
<p>Retrieving complete data in a database table</p>
<pre>SELECT * FROM table_name</pre>
<p>Retrieving specified data which is shown in the column list  from a database table</p>
<pre>SELECT column_name, column_name2….
FROM table_name</pre>
<p>Retrieving unique records</p>
<pre>SELECT DISTINCT (column_name)
FROM table_name</pre>
<p>Retrieving data from multiples table using join</p>
<pre>SELECT *
FROM table_name1
INNER JOIN table_name2 ON conditions</pre>
<pre>SELECT *
FROM table_name1
LEFT JOIN table_name2 ON conditions</pre>
<p>SELECT *<br />
FROM table_name1<br />
RIGHT JOIN table_name2 ON conditions</p>
<p>Counting number of rows in a database table</p>
<pre>SELECT COUNT (*)
FROM table_name</pre>
<p>Sorting ascending or descending retrieved data based on one  or more column</p>
<pre>SELECT column_name, column_name2….
FROM table_name
ORDER BY column_name ASC [DESC], column_name2 ASC [DESC],</pre>
<p>Group the retrieved rows data</p>
<pre>SELECT *
FROM table_name
GROUP BY column_name</pre>
<h2>Matching Data based on a pattern</h2>
<p>Matching data using LIKE operator</p>
<pre>SELECT * FROM table_name
WHERE column_name LIKE ‘%value%’</pre>
<h2>Matching data using regular expression</h2>
<pre>SELECT * FROM table_name
WHERE column_name RLIKE ‘regular_expression’
<div>
<div>
<div id="contentarea">
 

 

<strong>Mark
 BSc Honours in Computer Science
 Software Architect / Developer
 Mobile 079 9111 855</strong>

<strong>Email <a href="mailto:info@mydeveloper.co.za"><strong>info@mydeveloper.co.za</strong></a></strong>
</div>
</div>
</div>
</pre>
</div>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://www.wordpressconnect.net/amazonpress/'>Amazon plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://freelance-php-developer.phpmysql.co.za/2010/03/php-freelancer-retrieving-data-in-a-range-by-sql-between/feed/</wfw:commentRss>
		<slash:comments>66</slash:comments>
		</item>
		<item>
		<title>Aggregate Functions in MySQL</title>
		<link>http://freelance-php-developer.phpmysql.co.za/2010/03/aggregate-functions-in-mysql/</link>
		<comments>http://freelance-php-developer.phpmysql.co.za/2010/03/aggregate-functions-in-mysql/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 21:22:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL Tutorials]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://freelance-php-developer.phpmysql.co.za/?p=62</guid>
		<description><![CDATA[
In some cases, the information we need is not actually stored in the database but we can retrieve it by computing in some ways from stored data. For example, we have OrderDetails table to store order data, we don&#8217;t know total of money of all selling  products when we look at the table. In [...]


No related posts.

Related posts brought to you by <a href='http://www.wordpressconnect.net/amazonpress/'>Amazon plugin</a>.]]></description>
			<content:encoded><![CDATA[<div>
<p>In some cases, the information we need is not actually stored in the database but we can retrieve it by computing in some ways from stored data. For example, we have <em>OrderDetails </em>table to store order data, we don&#8217;t know total of money of all selling  products when we look at the table. In order to do so, we can use aggregate functions. By definition, aggregate functions allow us to perform a calculation on a set of records and return a single returned value. Aggregate functions ignore null value when performing calculation except COUNT function. Aggregate functions are often used with GROUP BY clause of SELECT statement. Here are aggregate functions which MySQL supports:</p>
<h2>SUM Function</h2>
<p>SUM function returns the sum of all values in an expression.</p>
<p>Let&#8217;s practice with OrderDetails table by following examples:</p>
<p>To get the total money for each selling product we just use the SUM function and group by product. Here is the query:</p>
<pre>SELECT productCode,sum(priceEach * quantityOrdered) total
FROM orderdetails
GROUP by productCode
</pre>
<pre>productCode    total
-----------  ---------
S10_1678      90157.77
S10_1949     190017.96
S10_2016     109998.82
S10_4698        170686
S10_4757     127924.32
S10_4962     123123.01
S12_1099     161531.48
</pre>
<p>To see the result more details, we can join the OrderDetails table with Product table.</p>
<pre>
SELECT P.productCode,
       P.productName,
       SUM(priceEach * quantityOrdered) total
FROM orderdetails O
INNER JOIN products  P ON O.productCode = P.productCode
GROUP by productCode
ORDER BY total
</pre>
<pre>productCode  productName                                    total
-----------  -------------------------------------------  ---------
S24_1937     1939 Chevrolet Deluxe Coupe                   28052.94
S24_3969     1936 Mercedes Benz 500k Roadster              29763.39
S24_2972     1982 Lamborghini Diablo                       30972.87
S24_2840     1958 Chevy Corvette Limited Edition           31627.96
S32_2206     1982 Ducati 996 R                             33268.76
S24_2022     1938 Cadillac V-16 Presidential Limousine     38449.09
S50_1341     1930 Buick Marquette Phaeton                  41599.24
S24_1628     1966 Shelby Cobra 427 S/C                     42015.54
S72_1253     Boeing X-32A JSF                              42692.53
</pre>
<h2>AVG Function</h2>
<p>AVG is used to calculate average value of an expression. It ignores NULL values.</p>
<pre>AVG(expression)
</pre>
<p>We can use AVG function to calculate the average price of all products buy executing the following query.</p>
<pre>SELECT AVG(buyPrice) average_buy_price
FROM Products
</pre>
<p>Here is the result</p>
<pre>average_buy_price
-----------------
  54.395181818182
</pre>
<h2>MAX and MIN Function</h2>
<p>MAX function returns the maximum and MIN function returns the minimum value of the set of values in expression.</p>
<pre>MAX(expression)</pre>
<pre>MIN(expression)</pre>
<p>As an example, we can use MIN and MAX function to retrieve the highest and lowest price product as follows:</p>
<pre>SELECT MAX(buyPrice) highest_price,
       MIN(buyPrice) lowest_price
FROM Products
</pre>
<p>You will get the result</p>
<pre>highest_price  lowest_price
-------------  ------------
       103.42         15.91
</pre>
<h2>COUNT Function</h2>
<p>COUNT function returns the count of the items in expression. We can use COUNT function to count how many products we have as follows:</p>
<pre>SELECT COUNT(*) AS Total
FROM products
</pre>
<pre>Total
------
   110
</pre>
<p><strong>For more information Mark on 079 9111 855 or email info@mydeveloper.co.za</strong></p>
</div>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://www.wordpressconnect.net/amazonpress/'>Amazon plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://freelance-php-developer.phpmysql.co.za/2010/03/aggregate-functions-in-mysql/feed/</wfw:commentRss>
		<slash:comments>100</slash:comments>
		</item>
		<item>
		<title>mysql_fetch_array</title>
		<link>http://freelance-php-developer.phpmysql.co.za/2010/03/mysql_fetch_array/</link>
		<comments>http://freelance-php-developer.phpmysql.co.za/2010/03/mysql_fetch_array/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 21:03:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Freelance Web Developer]]></category>
		<category><![CDATA[MySQL Tutorials]]></category>
		<category><![CDATA[database developer]]></category>
		<category><![CDATA[database specialist]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql developer]]></category>
		<category><![CDATA[mysql freelancer]]></category>

		<guid isPermaLink="false">http://freelance-php-developer.phpmysql.co.za/?p=54</guid>
		<description><![CDATA[mysql_fetch_array: Why Use It?
Do you know what is returned when you used the mysql_query function to query a MySQL database?  It isn&#8217;t something you can directly manipulate, that is for sure. Here is a sample SELECT query of a table we created in the MySQL Create Table lesson.

PHP and MySQL Code:
&#60;?php
$result = mysql_query("SELECT * [...]


No related posts.

Related posts brought to you by <a href='http://www.wordpressconnect.net/amazonpress/'>Amazon plugin</a>.]]></description>
			<content:encoded><![CDATA[<h1>mysql_fetch_array: Why Use It?</h1>
<p>Do you know what is returned when you used the <em>mysql_query</em> function to query a MySQL database?  It isn&#8217;t something you can directly manipulate, that is for sure. Here is a sample <em>SELECT</em> query of a table we created in the MySQL Create Table lesson.</p>
<div>
<h2>PHP and MySQL Code:</h2>
<pre>&lt;?php
$result = mysql_query("SELECT * FROM example");
?&gt;
</pre>
</div>
<p>The value that <em>mysql_query</em> returns and stores into <em>$result</em> is a special type of data, it is a MySQL Resource. Additional PHP functions are required to extract the data from this Resource.</p>
<h1>A Row of Data</h1>
<p>The <em>mysql_fetch_array</em> function takes a MySQL query resource as an argument (<em>$result</em>) and returns the first row of data returned by the <em>mysql_query</em>.  Our table <em>example</em> basically looks like the table below.</p>
<h2>example MySQL Table:</h2>
<div>
<table border="1">
<tbody>
<tr>
<th>name</th>
<th>age</th>
</tr>
<tr>
<td>Timmy Mellowman</td>
<td>23</td>
</tr>
<tr>
<td>Sandy Smith</td>
<td>21</td>
</tr>
<tr>
<td>Bobby Wallace</td>
<td>15</td>
</tr>
</tbody>
</table>
</div>
<p>The first row of data in this table is &#8220;Timmy Mellowman&#8221; and &#8220;23&#8243;.  When we fetch an array from our MySQL Resource <em>$result</em> it should have Timmy&#8217;s name and age in it.</p>
<h1>Getting a Row of Data using mysql_fetch_array</h1>
<p><em>mysql_fetch_array</em> returns the first row in a MySQL Resource in the form of an associative array.  The columns of the MySQL Result can be accessed  by using the column names of the table.  In our table <em>example</em> these are: name and age.  Here is the code to print out the first MySQL Result row.</p>
<div>
<h2>PHP and MySQL Code:</h2>
<pre>&lt;?php
// Make a MySQL Connection
$query = "SELECT * FROM example"; 

$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['<span style="color: red;">name</span>']. " - ". $row['<span style="color: red;">age</span>'];
?&gt;
</pre>
</div>
<h2>Display:</h2>
<div>Timmy Mellowman &#8211; 23</div>
<p>This is just what we expected would happen!  Now, the cool thing about <em>mysql_fetch_array</em> is that you can use it again on the same MySQL Resource to return the second, third, fourth and so on rows. You can keep doing this until the MySQL Resource has reached the end (which would be three times in our example).</p>
<p>Sounds like an awfully repetitive task. It would be nice if we could get all our results from a MySQL Resource in an easy to do script.</p>
<h1>Fetch Array While Loop</h1>
<p>As we have said, the <em>mysql_fetch_array</em> function returns an associative array, but it <strong>also</strong> returns FALSE if there are no more rows to return!  Using a PHP While Loop we can use this information to our advantage.</p>
<p>If we place the statement &#8220;$row = mysql_fetch_array()&#8221; as our while loop&#8217;s conditional statement we will accomplish two things:</p>
<ol>
<li>We will get a new row of MySQL information that we can print out each time the while loop checks its conditional statement.</li>
<li>When there are no more rows the function will return FALSE causing the while loop to stop!</li>
</ol>
<p>Now that we know what we need to do and how to go about doing it, the code pretty much writes itself, so let&#8217;s move on to the next lesson. Just kidding! Here is the code that will print out all the rows of our MySQL Resource.</p>
<div>
<h2>PHP and MySQL Code:</h2>
<pre>&lt;?php
// Make a MySQL Connection
$query = "SELECT * FROM example"; 

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
	echo $row['name']. " - ". $row['age'];
	echo "&lt;br /&gt;";
}
?&gt;
</pre>
</div>
<h2>Display:</h2>
<div>Timmy Mellowman &#8211; 23<br />
Sandy Smith &#8211; 21<br />
Bobby Wallace &#8211; 15</div>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://www.wordpressconnect.net/amazonpress/'>Amazon plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://freelance-php-developer.phpmysql.co.za/2010/03/mysql_fetch_array/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

