<?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>NewSourceMedia Blog &#187; mysql</title>
	<atom:link href="http://newsourcemedia.com/blog/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://newsourcemedia.com/blog</link>
	<description>Focused on Interactive Design, Development and Marketing</description>
	<lastBuildDate>Fri, 30 Dec 2011 04:30:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Fix SQL INSERT problems with PHP addslashes function</title>
		<link>http://newsourcemedia.com/blog/sql-insert-php-addslashes-fix/</link>
		<comments>http://newsourcemedia.com/blog/sql-insert-php-addslashes-fix/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 01:54:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL / Database]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/?p=643</guid>
		<description><![CDATA[If you've created you own custom content management system using PHP, you may have noticed problems inserting data. One of the problems could be that your data may have characters that prevent it from being inserted. Some of the character &#8230; <a href="http://newsourcemedia.com/blog/sql-insert-php-addslashes-fix/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[If you've created you own custom content management system using PHP, you may have noticed problems inserting data. One of the problems could be that your data may have characters that prevent it from being inserted. Some of the character that would cause this type of problem are single or double quotes, backslash, and NUL characters.

You can escape these problematic characters using the PHP function addslashes(). As explained by the PHP manual: It returns a string with backslashes before characters that need    to be quoted in database queries etc.  These characters are    single quote (<em>'</em>), double quote    (<em>"</em>), backslash (<em>\</em>)    and NUL (the <strong><tt>NULL</tt></strong> byte).

As you can see from my example below, I first run the content through the addshashes function and than return it to the same named string "$Page_Content" before passing it to my SQL UPDATE or INSERT statement.
<pre lang="php">$Page_Content = addslashes($Page_Content);
$query = "UPDATE site_content SET Page_Title='$Page_Title', Page_Content='$Page_Content' WHERE id_f='$id_f'";
query_db($query);
</pre>]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/sql-insert-php-addslashes-fix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to backup MySQL Database via SSH</title>
		<link>http://newsourcemedia.com/blog/how-to-backup-mysql-database-via-ssh/</link>
		<comments>http://newsourcemedia.com/blog/how-to-backup-mysql-database-via-ssh/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 02:44:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[MySQL / Database]]></category>
		<category><![CDATA[Terminal]]></category>
		<category><![CDATA[Web Servers]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[compress]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/how-to-backup-mysql-database-via-ssh/</guid>
		<description><![CDATA[First you log in using your terminal application by typing the flowing SSH command: ssh yourusername@hostname-or-ipaddress After that, you will be prompted to enter your password. As you enter your password, the text will be hidden. Next we should switch &#8230; <a href="http://newsourcemedia.com/blog/how-to-backup-mysql-database-via-ssh/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[First you log in using your terminal application by typing the flowing SSH command:

ssh yourusername@hostname-or-ipaddress

After that, you will be prompted to enter your password. As you enter your password, the text will be hidden. Next we should switch to the "root" user. You can do so by typing the following in your terminal window:

su - root

You will have to enter a password once more. Now navagate to where you would like to store your MySQL database file. For an example of changing the directory to the "public_html" direcotry, type this:

cd /var/www/html_public

Now you can back up your db here using the following command. This command will backup all of your databases. I also chose to compress them after the pipe "|" as a gzip file. Type the following but be sure to change the user name and password to your info:

mysqldump -u yourusername -p yourpassword --all-databases | gzip &gt;databasebackup.sql.gz

You can also target single database using the following:

mysqldump -u yourUserName -p yourDBName | gzip &gt;databasebackup.sql.gz]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/how-to-backup-mysql-database-via-ssh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Select UNIQUE or DISTINCT MySQL/PHP Queries</title>
		<link>http://newsourcemedia.com/blog/select-unique-or-distinct-mysqlphp-queries/</link>
		<comments>http://newsourcemedia.com/blog/select-unique-or-distinct-mysqlphp-queries/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 20:09:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL / Database]]></category>
		<category><![CDATA[distinct]]></category>
		<category><![CDATA[duplicate]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[results]]></category>
		<category><![CDATA[unique]]></category>
		<category><![CDATA[unwanted]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/?p=502</guid>
		<description><![CDATA[How to filter / remove duplicate items in your database query result using DISTINCT Say you wanted to show a list of client names from using a portfolio projects database. The problem is you may have multiple portfolio projects for &#8230; <a href="http://newsourcemedia.com/blog/select-unique-or-distinct-mysqlphp-queries/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[How to filter / remove duplicate items in your database query result using DISTINCT

<span id="more-502"></span>Say you wanted to show a list of client names from using a portfolio projects database. The problem is you may have multiple portfolio projects for the same client. So if you ran that list, you could get something like: Nike, Nike, Audi, BMW, BMW, Kmart and Ford. Here is how to clean up all duplicate using the "DISTINCT" clause.

<pre lang="php">$query = "SELECT DISTINCT Client_Name FROM Portfolio ORDER BY Client_Name ASC";
$result = query_db($query);

while ($myrow = mysql_fetch_array($result))
{
echo $myrow[Client_Name].", ";
}</pre>

Notice how we did not add in "limit 0,1". DISTINCT does this for us. It will only return one item.

You want to use it without any other columns, otherwise you are going to need a GROUP BY clause.]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/select-unique-or-distinct-mysqlphp-queries/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP MySQL Order by Two Columns</title>
		<link>http://newsourcemedia.com/blog/php-mysql-order-by-two-columns/</link>
		<comments>http://newsourcemedia.com/blog/php-mysql-order-by-two-columns/#comments</comments>
		<pubDate>Tue, 30 Nov 1999 06:00:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL / Database]]></category>
		<category><![CDATA[column]]></category>
		<category><![CDATA[keyword]]></category>
		<category><![CDATA[more]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[order]]></category>
		<category><![CDATA[order by]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rows]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[two]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/1969/12/31/php-mysql-order-by-two-columns/</guid>
		<description><![CDATA[Here's how to order your data by two or more columns using PHP and MySQL Order by Two Columns Here's how to order by more than one column. When ordering by more than one column, the second column is only &#8230; <a href="http://newsourcemedia.com/blog/php-mysql-order-by-two-columns/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[Here's how to order your data by two or more columns using PHP and MySQL<span id="more-166"></span>
<h3>Order by Two Columns</h3>
Here's how to order by more than one column. When ordering by more than   one column, the second column is only used if the values are identical with   the onces in the first column:

<code>SELECT column_name(s)
FROM table_name
ORDER BY column_name1, column_name2</code>
<h3>Sort the display by Ascending or Descending Order</h3>
If you use the ORDER BY keyword, the sort-order of the recordset is ascending   by default (1 before 9 and "a" before "p").

Use the DESC keyword to specify a descending sort-order (9 before 1 and "p" before "a"):

<code>SELECT column_name(s)
FROM table_name
ORDER BY column_name DESC</code>]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/php-mysql-order-by-two-columns/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>MySQL Table Fields Data Types</title>
		<link>http://newsourcemedia.com/blog/mysql-table-fields-data-types/</link>
		<comments>http://newsourcemedia.com/blog/mysql-table-fields-data-types/#comments</comments>
		<pubDate>Tue, 26 Dec 2006 00:22:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL / Database]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Data Typs.]]></category>
		<category><![CDATA[Fields]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Table]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/2006/12/25/mysql-table-fields-data-types/</guid>
		<description><![CDATA[Learn MySQL data types like Numeric Types, Date and Time Types and String Types for building dynamic web sites. Learn the three main basic data types used in MySQL and how to utilize them to build a more effective dynamic &#8230; <a href="http://newsourcemedia.com/blog/mysql-table-fields-data-types/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[Learn MySQL data types like Numeric Types, Date and Time Types and String Types for building dynamic web sites.
<span id="more-180"></span>

Learn the three main basic data types used in MySQL and how to utilize them to build a more effective dynamic web site. Lots of web developers use MySQL but not all of them harness the power of these features.

<strong>The three main types of data types used in MySQL are</strong>
1) Numeric (Integer/Numbers/Money)
2) String (Text)
3) Date (Dates and Time)

It's very important to pick the right data to achieve speed, effective storage and data retrieval. Here is a introduction to data types:
<h3><span class="nothing">Numeric Data Types</span></h3>
In addition to <strong>int</strong> (Integer data type), MySQL also has provision for floating-point and double precision numbers. Each integer type can take also be UNSIGNED and/or AUTO_INCREMENT.
<ul>
	<li><strong>TINYINT</strong>: very small numbers; suitable for ages. Actually, we should have used this data type for employee ages and number of children. Can store numbers between 0 to 255 if UNSIGNED clause is applied, else the range is between -128 to 127.</li>
	<li><strong>SMALLINT</strong>: Suitable for numbers between 0 to 65535 (UNSIGNED) or -32768 to 32767.</li>
	<li><strong>MEDIUMINT</strong>: 0 to 16777215 with UNSIGNED clause or -8388608 to 8388607.</li>
	<li><strong>INT</strong>: UNSIGNED integers fall between 0 to 4294967295 or -2147683648 to 2147683647.</li>
	<li><strong>BIGINT</strong>: Huge numbers. (-9223372036854775808 to 9223372036854775807)</li>
	<li><strong>FLOAT</strong>: Floating point numbers (single precision)</li>
	<li><strong>DOUBLE</strong>: Floating point numbers (double precision)</li>
	<li><strong>DECIMAL</strong>:Floating point numbers represented as strings.</li>
</ul>
<h3>Date and Time Data types</h3>
	<li><strong>DATE</strong>: YYYY-MM-DD (Four digit year followed by two digit month and date)</li>
	<li><strong>TIME</strong>: hh:mm:ss (Hours:Minutes:Seconds)</li>
	<li><strong>DATETIME</strong>: YYYY-MM-DD hh:mm:ss (Date and time separated by a space character)</li>
	<li><strong>TIMESTAMP</strong>: YYYYMMDDhhmmss</li>
	<li><strong>YEAR</strong>: YYYY (4 digit year)</li>
<h3>Text Data Type</h3>
Text can be fixed length (char) or variable length strings. Also, text comparisions can be case sensitive or insensitive depending on the type you choose.
<ul>
	<li><strong>CHAR(x)</strong>: where x can range from 1 to 255.</li>
	<li><strong>VARCHAR(x)</strong>: x ranges from 1 - 255</li>
	<li><strong>TINYTEXT</strong>: small text, case insensitive</li>
	<li><strong>TEXT</strong>: slightly longer text, case insensitive</li>
	<li><strong>MEDIUMTEXT</strong>: medium size text, case insensitive</li>
	<li><strong>LONGTEXT</strong>: really long text, case insensitive</li>
	<li><strong>TINYBLOB</strong>: Blob means a <strong>B</strong>inary <strong>L</strong>arge <strong>OB</strong>ject. You should use blobs for case sensitive searches.</li>
	<li><strong>BLOB</strong>: slightly larger blob, case sensitive.</li>
	<li><strong>MEDIUMBLOB</strong>: medium sized blobs, case sensitive.</li>
	<li><strong>LONGBLOB</strong>: really huge blobs, case sensitive.</li>
	<li><strong>ENUM</strong>: <strong>Enum</strong>eration data type have fixed values and the column can take only one value from the given set. The values are placed in parenthesis following ENUM declaration. An example, is the marital status column we encountered in <em>employee_per</em> table.
<pre class="code">m_status ENUM("Y", "N")</pre>
Thus, m_status column will take only <strong>Y</strong> or <strong>N</strong> as values. If you specify any other value with the INSERT statement, MYSQL will not return an error, it just inserts a NULL value in the column.</li>
	<li><strong>SET</strong>: An extension of ENUM. Values are fixed and placed after the SET declaration; however, SET columns can take multiple values from the values provided. Consider a column with the SET data type as
<pre class="code">foods SET ("Apples", "Cookies", "Pies", "Chicken")</pre>
You can have 0 or all the four values in the column.
<pre class="code">INSERT tablename (foods) values ("Apple", "Cookies");</pre>
</li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/mysql-table-fields-data-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create MySQL Database With PHP</title>
		<link>http://newsourcemedia.com/blog/create-mysql-database-with-php/</link>
		<comments>http://newsourcemedia.com/blog/create-mysql-database-with-php/#comments</comments>
		<pubDate>Tue, 26 Dec 2006 00:22:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL / Database]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[base]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[information]]></category>
		<category><![CDATA[myslq]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[store]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/2006/12/25/create-mysql-database-with-php/</guid>
		<description><![CDATA[Create a dynamic web site by using MySQL Database and PHP. It is easy and I provided the code to cut and paste. Now let get started with PHP and MySQL code for building a Dynamic Web Site: PHP &#38; &#8230; <a href="http://newsourcemedia.com/blog/create-mysql-database-with-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[Create a dynamic web site by using MySQL Database and PHP. It is easy and I provided the code to cut and paste.<span id="more-179"></span>

Now let get started with PHP and MySQL code for building a Dynamic Web Site:
<h3>PHP &amp; database connection code in a lib file for inclusion</h3>
1) First we make a php file called "lib.php"
2) Then we add the following php code to the lib.php file for making a connection to the database. Be sure to change the names to match your host name, user name, password and database name :

<span class="code">&lt;?
$dbhost = 'localhost';
$dbuser = 'myusername'; // you must set user name!
$dbpass = 'mypassword'; // you must set pass word!
$dbname = 'car_database'; // you must set database or fill-in database name in the form!</span>
<p class="code">function dbconnect()
{
global $dbhost, $dbuser, $dbpass, $dbname;
mysql_pconnect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die ("Unable to select database");
}

<p class="code">function query_db($query)
{
dbconnect();
return @mysql_query($query);
}
?&gt;
<h3>Database Manager (PhpMyAdmin) to create a new table</h3>
3) Open up your database manager (PhpMyAdmin) and select your database, then click the SQL tab or icon for running a SQL query and copy and paste the following code in the text field then click the "Go" or "Submit" button to create the <em>car_table</em> database.
<p class="code">CREATE TABLE car_table (</p>

<p class="code">car_make varchar(250) default NULL,
car_model varchar(250) default NULL,
car_year varchar(250) default NULL,
id_field int(11) NOT NULL auto_increment,
PRIMARY KEY (id_field)
) TYPE=MyISAM;
<h3>PHP code for managing your table fields</h3>
4) <span class="code">Download Code file "cars.txt" here: <a href="../../New%20Tutorials/cars.txt" target="_blank">http://newsourcemedia.com/New Tutorials/cars.txt</a></span>

5)  Rename that file to "cars.php". Notice that the first line of code is there to imports your first file "lib.php". Why? Because for every php file that query's the database will need to make a database connection. So why not use one file to make that connection for all php files.

6) Uploads both the "lib.php" and the "cars.php" to your web server. Make sure both files are in side of the same directory.
<h3>Third PHP file for visitors without the edit or delete functions.</h3>
7) After adding content to your database, you may want to make a third file called "viewcars.php" for the users to view the database list of cars. Do this by duplicating the "cars.php" file. But be sure to <strong>delete </strong>all of the links labeled "delete", "edit" and "add" and remove all php blocks of code that start with "<span class="code">$query=INSERT INTO...</span>, <span class="code">$query=UPDATE...</span>, and <span class="code">$query=DELETE FROM...</span>" to provent visitors from editing your database content.]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/create-mysql-database-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Order By Multiple Fields in MySQL</title>
		<link>http://newsourcemedia.com/blog/php-order-by-multiple-fields-in-mysql/</link>
		<comments>http://newsourcemedia.com/blog/php-order-by-multiple-fields-in-mysql/#comments</comments>
		<pubDate>Sat, 17 Jul 2004 00:22:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ascent]]></category>
		<category><![CDATA[descent]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[order]]></category>
		<category><![CDATA[reorder]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/2004/07/16/php-order-by-multiple-fields-in-mysql/</guid>
		<description><![CDATA[Want to be able to order by two or more database fields / columns using the ASC and DESC order clause You can sort query results in ascending or descending order on one or more of the columns in the &#8230; <a href="http://newsourcemedia.com/blog/php-order-by-multiple-fields-in-mysql/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[Want to be able to order by two or more database fields / columns using the ASC and DESC order clause
<span id="more-192"></span>

You can sort query results in ascending or descending order on one or more of the columns in the result set by using the ASC or DESC keywords with the ORDER BY clause.

<strong>Ordering By Two Fields</strong>
<p class="sourceCODE">SELECT * FROM table ORDER BY (field1 / field2) DESC</p>

<strong>Ordering By Three Fields</strong>

If both field1 and field2 match in more then one row, then use a third to order them by:
<p class="sourceCODE">SELECT * FROM table ORDER BY (field1 / field2) DESC, field3 DESC</p>]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/php-order-by-multiple-fields-in-mysql/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>PHP Search using WHERE, AND, LIKE, OR Query Functions</title>
		<link>http://newsourcemedia.com/blog/php-search-using-where-and-like-or-query-functions/</link>
		<comments>http://newsourcemedia.com/blog/php-search-using-where-and-like-or-query-functions/#comments</comments>
		<pubDate>Sat, 17 Jul 2004 00:22:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL / Database]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[content management system]]></category>
		<category><![CDATA[data-driven]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mutiple]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[where]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/2004/07/16/php-search-using-where-and-like-or-query-functions/</guid>
		<description><![CDATA[How to search multiple fields in a database Search using WHERE, AND, LIKE, OR Query Functions Looking for an exact match in field1: SELECT * FROM table WHERE field1 = '$name' Looking if the field1 contains the search word anywhere &#8230; <a href="http://newsourcemedia.com/blog/php-search-using-where-and-like-or-query-functions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[How to search multiple fields in a database
<span id="more-190"></span>

<strong>Search using WHERE, AND, LIKE, OR Query Functions</strong>
<ol>
	<li>Looking for an exact match in field1:
<span class="sourceCODE">SELECT * FROM table WHERE field1 = '$name'</span></li>
	<li>Looking if the field1 contains the search word anywhere using LIKE and both  '%%'
<span class="sourceCODE">SELECT * FROM table WHERE field1 LIKE '%$word%'</span></li>
	<li>Looking if the field1 contains the value that begins with our word using LIKE  and the last ' %'
<span class="sourceCODE">SELECT * FROM table WHERE field1 LIKE '$word%'</span></li>
	<li>Looking if the field1 contains the value that ends with our word using LIKE  and the first '% '
<span class="sourceCODE">SELECT * FROM table WHERE field1 LIKE '%$word'</span></li>
	<li>Looking if our search word appears in both fields using AND
<span class="sourceCODE">SELECT * FROM table WHERE field1 LIKE '%$word%' AND field2  LIKE '%$word%'</span></li>
	<li>Looking if our search word appears in any of the two fields using OR
<span class="sourceCODE">SELECT * FROM table WHERE field1 LIKE '%$word%' OR field2  LIKE '%$word%'</span></li>
	<li>Looking if our word is in field1 OR in field2 AND field3 using Parentheses
<span class="sourceCODE">SELECT * FROM table WHERE field1 LIKE '%$word%' OR (field2  LIKE '%$word%' AND field2 LIK</span></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/php-search-using-where-and-like-or-query-functions/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Polls and Comments with PHP and MySQL</title>
		<link>http://newsourcemedia.com/blog/polls-and-comments-with-php-and-mysql/</link>
		<comments>http://newsourcemedia.com/blog/polls-and-comments-with-php-and-mysql/#comments</comments>
		<pubDate>Sun, 11 Apr 2004 00:22:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CMS]]></category>
		<category><![CDATA[comments.]]></category>
		<category><![CDATA[contest]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[points]]></category>
		<category><![CDATA[polls]]></category>
		<category><![CDATA[total]]></category>
		<category><![CDATA[vote]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/2004/04/10/polls-and-comments-with-php-and-mysql/</guid>
		<description><![CDATA[Create a poll voting and comments system with the help of PHP and MySQL. Explains in details the script and database design. What do you need: PHP - obviously you know this from the title Get it from PHP's website, &#8230; <a href="http://newsourcemedia.com/blog/polls-and-comments-with-php-and-mysql/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[Create a poll voting and comments system with the help of PHP and MySQL. Explains in details the script and database design.
<span id="more-202"></span>
<h2 class="title">What do you need:</h2>
<ul>
	<li>PHP - obviously you know this from the title
Get it from <a title="PHP - Hypertext Preprocessor" href="http://www.php.net/" target="_blank">PHP's                          website</a>, available in source or binary for free.</li>
	<li>MySQL - here we store the data. You should probably be able to use some other database also with a few modifications.
Download from your nearest <a title="MySQL" href="http://www.mysql.com/" target="_blank">MySQL</a> mirror. It is available through a GPL license in source                          or binary.</li>
	<li>Apache or some other web server to test it all, and a hosting service for permanent storage.
You can get <a title="Apache Web Server" href="http://httpd.apache.org/" target="_blank">Apache</a> for free too. Source and binaries are available.</li>
</ul>
So, I don't think you have to spend any money to get these wonderful software packages, and you should be ready to go if you already have them.
<h2 class="title">What are you expected to already know:</h2>
<ul>
	<li>XHTML/HTML of course, after all this is what PHP sends the browser.</li>
	<li>CSS - basic knowledge, if you like to control the way things look.</li>
	<li>JavaScript - for client-side validation, not needed if you want to only check on the server-side, which is a lot slower and higher network load.</li>
	<li>PHP - this is not a PHP tutorial, just an example. At least basic knowledge is needed.</li>
	<li>MySQL - you have to create the database and tables or let someone else do it for you.</li>
</ul>
<h2 class="title">A word about the configurations</h2>
I use a .htaccess file to setup PHP. If you have any trouble using the code try using these settings. If you get escaped quotes (like \' instead of ') you should use <code>magic_quotes_gpc = off</code> in php.ini or paste the following contents into a .htaccess file (or whatever it's called on your server). This should be in the directory where your code is, or in its parent directory.
<pre>php_value arg_separator.output "&amp;amp;"
php_value arg_separator.input "&amp;"
php_flag register_globals off
php_flag short_open_tag off
php_flag magic_quotes_gpc off</pre>
<h2 class="title">Getting started</h2>
<h3>Globally included code</h3>
<pre>function connect_db() {
   global $link;

   $db_host = "localhost";
   $db_username = 'username';
   $db_pass = 'password';
   $db_name = 'database_name';

   $link = @mysql_connect($db_host, $db_username, $db_pass)
      or die ("Could not connect to database");
   @mysql_select_db ($db_name)
      or die ("Could not select database");
}</pre>
This is a function that connects to the database; I put this in a file that's included from every page at the site. If you think you don't understand anything you should check out the PHP manual. The <code>@</code> in front of the functions is used to suppress the default error messages if you can't connect to the database.
<pre>&lt;?php
   if ( !isset($link) )
      connect_db();
   $res = @mysql_query("select count from poll where id=0")
      or die("Query cm p0 failed");
   $result = mysql_fetch_object($res);

   $poll = (int) $HTTP_GET_VARS['poll'];
   if ( ($poll &lt; 1) or ($poll &gt; $result-&gt;count) ) {
      mt_srand ((double) microtime() * 1000000);
      $poll = mt_rand(1,$result-&gt;count);
   }
?&gt;</pre>
Connect to the database if no connection is established yet, and get the total number of polls available. Check if a GET variable <code>poll</code> has been passed. If negative or greater than the number of polls, this is an illegal value so get a random one.
<pre>&lt;form method="get" action="poll.php"
   onsubmit="return validateVote(this.vote)"&gt;
&lt;table border="0" summary="poll inputs"&gt;

&lt;?php
   $res = @mysql_query("select title, count, last from poll where id=$poll")
      or die("Query poll failed");
   $result = mysql_fetch_object($res);
?&gt;
   &lt;tr&gt;&lt;td&gt;&lt;?php echo $result-&gt;title?&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;?php
   $total = $result-&gt;count;
   $date = $result-&gt;last;

   $res = @mysql_query("select text, vote from poll_data where id=$poll")
      or die("Query poll_data failed");
   while ($row = mysql_fetch_object ($res)) {
      $input ='&lt;input type="radio" name="vote" value="' .
         $row-&gt;vote . '" /&gt;';
      echo "&lt;tr&gt;&lt;td&gt;$input $row-&gt;text&lt;/td&gt;&lt;/tr&gt;";
   }
?&gt;

   &lt;tr&gt;&lt;td&gt;Total&amp;#160;votes:&amp;#160;&lt;?php echo $total?&gt;&lt;/td&gt;&lt;/tr&gt;
   &lt;tr&gt;&lt;td&gt;Last&amp;#160;vote:&amp;#160;&lt;?php echo $date?&gt;&lt;/td&gt;&lt;/tr&gt;

   &lt;tr&gt;&lt;td&gt;&lt;input type="submit" value="Vote" /&gt;
      &lt;a href="poll.php?poll=&lt;?php echo $poll?&gt;"
         title="View the current poll results"&gt;Results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
   &lt;div&gt;

   &lt;input type="hidden" id="poll" name="poll" value="&lt;?php echo $poll?&gt;" /&gt;
   &lt;/div&gt;
&lt;/form&gt;</pre>
This one defines the form which is submitted to the polls handling page, in my case <code>poll.php</code>. Get the poll title, total vote count, and the last time someone voted. Then loop over each option and create a <code>radio input</code> for all of them. Finally display the total votes, last voted date, a  <code>submit input</code> for voting and a link to the results (if somebody doesn't want to vote). We also pass the poll id to the poll handler. This can also be implemented with session variables but see first if PHP is compiled with <code>--enable-trans-sid</code>. If yes, then it is safe, otherwise your option is to pass the <code>SID</code> constant, but this is essentially the same.

Now for the client-side validation function that is run <code>onsubmit</code>.
<pre>function validateVote(vote) {
   valid = false;

   // Opera 5.05 Linux does not support for/in on this object
   for ( var i = 0; i &lt;  vote.length; i   ) {
      if ( vote[i].checked ) {
         valid = true;
         break;
      }
   }
   if ( ! valid ) {
      alert("You must choose one");
   }
   return valid;
}</pre>
Well, that's all for the include code (this is usually shown on every page). The only other thing you may consider is protecting the file that holds the db username and password, in case PHP isn't there to process the code with something like this in a .htaccess file:
<pre>&lt;Files "my_db_password_in_here.php"&gt;
    Order deny,allow
    Deny from all
&lt;/Files&gt;</pre>
Now to get our hands on the input handling code.
<h3>The Poll Handling Code</h3>
<pre>&lt;?php
   require "global_includes_file.php";
   if ( !isset($link) )
      connect_db();

   $res = @mysql_query("select count from poll where id=0")
      or die("Query polls failed");
   $result = mysql_fetch_row($res);
   $polls = $result[0];

   $poll = (int) $HTTP_GET_VARS['poll'];
   if ( $poll &gt; $polls or $poll &lt; 1 )
      $poll = 1;</pre>
Include a <code>global_includes_file.php</code> and check if a link to the database is established. Get the number of polls from the db and check if there is a GET passed variable <code>poll</code>. If not just display the first.
<pre>$poll_voted = (int) $HTTP_COOKIE_VARS['voted'];
$poll_bit = ( 1 &lt;&lt; $poll );
if ( !($poll_voted &amp; $poll_bit) ) {
	$poll_ok = true;
} else {
	$poll_ok = false;
}

$vote = (int) $HTTP_GET_VARS['vote'];
if ( $poll_ok and $vote &gt; 0 and $vote &lt; 6 ) { // count the vote
	$cookie_voted = $poll_voted | $poll_bit;
	setcookie('voted', $cookie_voted, time() 2592000); // one month time

	$sql = "update poll set count=count 1, last=now() where id=$poll";
	@mysql_query($sql) or die('Query p2 failed');

	$sql = "update poll_data set count=count 1 " .
		"where id=$poll and vote=$vote";
	@mysql_query($sql) or die('Query p3 failed');
}</pre>
Now we do not require visitors to register, just to vote                        but we neither allow them to vote again and again (except                        if they erase the cookies, but that's another story in which                        case you definitely need user registration (there are two                        articles on evolt: <a title="Creating a login script with PHP 4: part 1" href="http://evolt.org/article/Creating_a_Login_Script_with_PHP_4/17/19661/" target="_blank">Creating                        a Login Script with PHP 4</a> and <a title="Creating a login script with PHP 4: part 2" href="http://www.evolt.org/article/view/17/27093/" target="_blank">Creating                        a Login Script with PHP 4 - Part II</a> on evolt). Make                        sure you read the articles, if this is what you need.

To get by on cookies, get one called <code>voted</code>, if available, and check whether the user has already voted for this poll. Get the vote that is handled; here's an example of some hard-coded variables that you may wish to get rid of, if you think there may be a different number of answers to one question. Check whether he/she is allowed to vote and if the vote is ok, and set a cookie that will stay for one month to keep track that the user has voted (not that he/she cannot use another browser or just delete the cookie, but anyway).

To finish the voting update the total number of votes and the current choice (increment by one). I'm not quite sure if MySQL applies locking and other stuff when you pass the queries this way, but this is definitely safer than extracting the value from the database and then explicitly setting it to a value that is incremented in PHP.
<pre>function my_esc($input) {
	return mysql_escape_string(htmlspecialchars($input) );
}

if ( $HTTP_SERVER_VARS['REQUEST_METHOD'] == 'POST' ) {
	$comment = my_esc($HTTP_POST_VARS['fComments']);
	$subject = my_esc($HTTP_POST_VARS['fSubject']);
	$name = my_esc($HTTP_POST_VARS['fName']);
	if ( $name == '' )
		$name = 'anonymous';
	$email = my_esc($HTTP_POST_VARS['fEmail']);
	$poll = (int) $HTTP_POST_VARS['poll'];

	if ( $comment != '' )
		$sql = "insert into comments " .
			"(name, subject, email, comment, date, poll)" .
			"values('$name', '$subject', '$email', " .
			"'$comment', now(), $poll)"

		@mysql_query($sql)
			or die('Query add comments failed');
}</pre>
Define a function that should escape the HTML and SQL if some <em>smarty</em> guy has decided to pass it to see what can happen. I'm not quite sure if this name is OK according to the PHP coding standards but anyway it's short and convenient, think up something else if you want. This is where you should change the code if you definitely want <code>magic_quotes_gpc = on</code>.

Check if any POSTing has happened, if so escape all the variables passed, and instead of displaying nothing replace the name with "anonymous". If any comments have been POSTed we are ready to <code>insert</code> that in the database.
<pre>	begin_head();
?&gt;
&lt;meta name="description" content="Poll results and comments" /&gt;
&lt;title&gt;Think up one&lt;/title&gt;
&lt;?php
	begin_body()
?&gt;</pre>
That's supposed you have a function called&lt; code&gt;begin_head() that prints the document type declaration and stuff. Remember we used cookies, so nothing but headers should have been printed until now. The other function begins the body and prints some headers (like navbar or logo, etc.).
<pre>&lt;h1&gt;Poll results and comments&lt;/h1&gt;
&lt;?php
   if ( !$poll_ok and $vote )
      echo "&lt;p&gt;You are not allowed to vote again&lt;/p&gt;";

   $sql = "select title, count, last from poll where id=$poll";
   $res = @mysql_query($sql)
      or die("Query c2 failed");
   $result = mysql_fetch_object($res);
   echo "&lt;h2&gt;$result-&gt;title&lt;/h2&gt;";
   $total = $result-&gt;count;
   $date = $result-&gt;last;

?&gt;</pre>
Print the first level header of the page and a message that the user is not allowed to vote again, if they've tried. Query the database to get the title, total count and last vote date for the current poll. I know the query failed messages are not user friendly, unfortunately I found that out long after I started using this code.
<pre>&lt;table border="0" cellspacing="5" summary="votes statistics"&gt;
&lt;?php
   $sql = "select text, count from poll_data where id=$poll";
   $res = @mysql_query($sql)
      or die("Query c3 failed");
   if ( mysql_num_rows($res) == 0 ) {
      echo "&lt;tr&gt;&lt;td&gt;&lt;p&gt;Sorry still nothing in here&lt;/p&gt;&lt;/td&gt;&lt;
;/tr&gt;";
   } else {
      while ($row = mysql_fetch_object ($res)) {
         $share = round(100 * $row-&gt;count / $total, 2);
            echo "&lt;tr&gt;&lt;td&gt;$row-&gt;text&lt;/td&gt;

            &lt;td&gt;$share% ($row-&gt;count)&lt;/td&gt;&lt;/tr&gt;";
      }
   }
?&gt;
&lt;/table&gt;
&lt;p&gt;
Total votes: &lt;?php echo $total?&gt;&lt;br /&gt;

Last vote: &lt;?php echo $date?&gt;
&lt;/p&gt;</pre>
Print a table with the poll results, if any. Otherwise a message will be shown, which is needed. Without it you will get a division by zero error when calculating the percentage share of each choice.
<pre>&lt;h2&gt;Other polls&lt;/h2&gt;
&lt;?php
   $res = @mysql_query("select * from poll where id!=$poll and id!=0")
      or die("Query c4 failed");
?&gt;

&lt;table border="0" cellspacing="5" summary="other polls"&gt;
&lt;tr&gt;&lt;th&gt;Poll&lt;/th&gt;
     &lt;th&gt;Votes&lt;/th&gt;
     &lt;th&gt;Comments&lt;/th&gt;

&lt;/tr&gt;
&lt;?php
   while ($row = mysql_fetch_object ($res)) {
?&gt;
      &lt;tr&gt;&lt;td&gt;&lt;a
href="poll.php?poll=&lt;?php echo "$row-&gt;id" .'"&gt;' .
$row-&gt;title?&gt;&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row-&gt;count?&gt;&lt;/td&gt;

      &lt;td&gt;&lt;?php echo $row-&gt;comments?&gt;&lt;/td&gt;
      &lt;/tr&gt;
&lt;?php
   }
?&gt;
&lt;/table&gt;</pre>
Print a table with links to other polls to be viewed/voted for. Note the query <code>where .. and id!=0</code>. That's because I use <code>id=0</code> to store the total number of polls.
<pre>&lt;h2&gt;Comments&lt;/h2&gt;
&lt;div&gt;
&lt;?php
   $sql = "select name, subject, email, comment, date " .
      "from comments where poll=$poll&amp;q
uot;;
   $res = @mysql_query($sql)
      or die("Query poll comments failed");
   if ( mysql_num_rows($res) == 0 ) {
      echo "&lt;p&gt;Sorry still nothing in here&lt;/p&gt;";
   } else {
      while ($row = mysql_fetch_object ($res)) {
?&gt;
         &lt;div class="commenthead"&gt;

            &lt;div class="subject"&gt;&lt;?php echo $row-&gt;subject ?&gt;&lt;/div&gt;
            &lt;div class="info"&gt;by &lt;a href="mailto:&lt;?php echo $row-&gt;email ?&gt;"&gt;
               &lt;?php echo $row-&gt;name ?&gt;&lt;/a&gt; on
               &lt;?php echo gmdate('d M Y g:ia', strtotime($row-&gt;date)) ?&gt; GMT
            &lt;/div&gt;

         &lt;/div&gt;

         &lt;div class="comment"&gt;
         &lt;?php echo $row-&gt;comment ?&gt;
         &lt;/div&gt;
&lt;?php
      }
   }
?&gt;
&lt;/div&gt;</pre>
Now for the comments: get all for the current poll from the database (or if nothing is available say so). Iterate over each comment and print its subject. On the next line print the name provided (you may consider not creating it as a <code>mailto:</code> link because e-mail is optional) and the date and time. I know many people don't like UTC (that's Universal Coordinated Time, also informally known as GMT), but I think this is what should be used all over the Internet. Or print the GMT offset (though this is rarely seen). Many sites would rather print their local time, but this doesn't help people in different time zones.
<pre>&lt;h2&gt;Say your mind&lt;/h2&gt;

&lt;form method="post" action="&lt;?php echo $HTTP_SERVER_VARS['PHP_SELF']?&gt;"
   onsubmit="return validateString(this.comment)"&gt;

&lt;div&gt;&lt;input type="hidden" name="poll" value="&lt;?php echo $poll?&gt;" /&gt;&lt;/div&gt;
&lt;div class="formwrapper"&gt;

&lt;div class="row"&gt;
   &lt;label for="fName"
      title="Write down your name here (optional)"&gt;Name:&lt;/label&gt;
   &lt;span&gt;&lt;input type="text" name="fName" id="fName" size="25"
      title="Write down your name here (optional)" tabindex="1" /&gt;&lt;/span&gt;

&lt;/div&gt;

&lt;div class="row"&gt;
   &lt;label for="fEmail"
      title="Write down your e-mail here (optional)"&gt;E-mail:&lt;/label&gt;
   &lt;span&gt;&lt;input type="text" name="fEmail" id="fEmail" size="25"
      title="Write down your e-mail here (optional)" tabindex="2" /&gt;&lt;/span&gt;
&lt;/div&gt;

&lt;div class="row"&gt;
   &lt;label for="fSubject"
      title="Write down a short subject, maximum 60 chars"&gt;Subject:&lt;/label&gt;
   &lt;span&gt;&lt;input type="text" name="fSubject" id="fSubject" size="25"
      title="Write down a short subject, maximum 60 chars" tabindex="3" /&gt;
   &lt;/span&gt;
&lt;/div&gt;

&lt;div class="row"&gt;
   &lt;textarea cols="40" rows="6" name="fComments" id="fComments"
      title="Just write the message here" tabindex="4"&gt;&lt;/textarea&gt;
&lt;/div&gt;

&lt;div class="row" style="padding-bottom : 10px;"&gt;
   &lt;input type="submit" value="Submit comment"
      title="Submit the comment" tabindex="5" /&gt;

   &lt;input type="reset" value="Clear form"
      title="Clears the text box" tabindex="6" /&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;/form&gt;

&lt;p&gt;Note: All fields except the comments are optional.&lt;/p&gt;</pre>
This is pretty straight forward XHTML so I don't think anyone should need an explanation. The function that handles <code>onsubmit</code> follows.
<pre>function validateString(str) {
   if ( str.value &amp;&amp; str.value.length &gt; 0 ) return true
   else {
      alert("You don't think I can read your mind do you?");
      str.focus();
      return false;
   }
}</pre>
<h3>Database stuff</h3>
I apologize for the mixed case database queries; MySQL doesn't care about it so I don't feel I need to type all keywords in uppercase. You first have to create the database and then use  <code>mysql -p your_database_name &lt; this_code.sql</code> where <code>this_code.sql</code> is the filename you used to save the following SQL code.
<pre>CREATE TABLE poll (
   id int NOT NULL auto_increment,
   title varchar(100) NOT NULL default '',
   count int NOT NULL default '1',
   last date,
   PRIMARY KEY  (id)
);

CREATE TABLE poll_data (
   id int NOT NULL default '0',
   text char(50) NOT NULL default '',
   count int NOT NULL default '1',
   vote tinyint NOT NULL default '0'
);

create table comments(
   name varchar(30) not null default '',
   subject varchar(50) not null default '',
   email varchar(30) not null default '',
   comment text not null default '',
   date datetime not null default '',
   poll int not null default '0',
);</pre>
<h3>Stylesheet</h3>
You can use the following selectors in a stylesheet linked from the <code>poll.php</code>:
<ul>
	<li>div.formwrapper</li>
	<li>div.row</li>
	<li>div.row label</li>
	<li>div.row span, you can make it div.row input if you clear up the code</li>
	<li>div.commenthead</li>
	<li>div.subject</li>
	<li>div .comment</li>
</ul>
<h2 class="title">To finish up</h2>
The code and a more advanced version of it is available                        for <a href="http://martin.f2o.org/download/poll/" target="_blank">download</a>.]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/polls-and-comments-with-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing PHP MySQL Apache on windows 98 in 5 min</title>
		<link>http://newsourcemedia.com/blog/installing-php-mysql-apache-on-windows-98-in-5-min/</link>
		<comments>http://newsourcemedia.com/blog/installing-php-mysql-apache-on-windows-98-in-5-min/#comments</comments>
		<pubDate>Sat, 20 Mar 2004 00:22:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/2004/03/19/installing-php-mysql-apache-on-windows-98-in-5-min/</guid>
		<description><![CDATA[This article on "Installing Apache-MySQL-PHP on Windows 98" in just five min is a complete step by step tutorial to install this trio package. The article contains full graphics snapshots to help the new developers to install the trio package &#8230; <a href="http://newsourcemedia.com/blog/installing-php-mysql-apache-on-windows-98-in-5-min/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[This article on "Installing Apache-MySQL-PHP on Windows 98" in just five min is a complete step by step tutorial to install this trio package. The article contains full graphics snapshots to help the new developers to install the trio package without any <span id="more-205"></span>
This article on "Installing Apache-MySQL-PHP on Windows 98" in just five min is a complete step by step tutorial to install this trio package. The article contains full graphics snapshots to help the new developers to install the trio package without any glitch or much effort. Happy developing!

<a href="http://newsourcemedia.com/blog/wp-content/uploads/2004/03/settingupphp.pdf">http://newsourcemedia.com/blog/wp-content/uploads/2004/03/settingupphp.pdf</a>]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/installing-php-mysql-apache-on-windows-98-in-5-min/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
