So you have a Mysql table you want to pull data from, but you don’t want to flood the page with everything in the table right! So you need some pagination to seperate all the content in the table into easy to open pages. So let’s say this is your mysql query: $sql = mysql_query("SELECT [...]
Read More...Posts in the "Code" Category
-
-
The date() function converts a given timestamp into a readable date format. Here is the syntax for this function: Syntax date(format,timestamp); Parameters: format This parameter determines the format and how the date will read. For example: “Saturday, Nov. 16th 2009” would be the following code: $timestamp = time(); date("l, M. jS Y",$timestamp); timestamp This parameter [...]
Read More... -
Here is a table for formatting the PHP function date() and the letters used to represent different parts of a timestamp. .data { font: 11px verdana; color: #5b5b5b; } .post_table { background-color:#dedede; border: 2px solid #ccc; } .post_table td { border:1px solid #eee; } a ‘am’ or ‘pm’ A ‘AM’ or ‘PM’ B Swatch Internet [...]
Read More... -
Many times when you upload a image somewhere you want to resize it to different dimensions based off of a maximum width or height. Here is a simple script that does this for you, using a HTML form and a PHP script. We start with the PHP script that will run if our $_GET['do'] is [...]
Read More... -
Here is a very simple function to use to ordinalize numbers in PHP. This adds the place value suffix to numbers. So you can turn numbers like 1, 2, 3 into 1st, 2nd, 3rd. Here is the code: function ordinalize($int){ if(in_array(($int % 100),range(11,13))){ return $int . "th"; } else { switch(($int % 10)){ case 1: [...]
Read More... -
Let’s say you want to have a simple HTML <select> form as a drop down for rows in a Mysql table. This could be for things like categories, pages, games, anything you want to have in a drop down to navigate to another page or submit a form. What ever the case is, I’m going [...]
Read More... -
The error_reporting() function determines what errors are reported from the current script. Here is the syntax for this function: Syntax error_reporting(report_level); The report_level parameter is optional and specifies what report level to report for the current script. This can be set by its numeric value or its constant name, however for future versions of PHP [...]
Read More... -
Here we’re going to take a look at variables inside and outside of PHP functions. It is very easy to make one error with a function and have it return the wrong value. We’re going to make a simple function named “func1” which we’ll tweak a bit to show how variables are used inside and [...]
Read More... -
One of the most common ways to capture the current time in PHP scripting is by using the time() function. This returns the current timestamp which is the number of seconds after a certain date and time in the past. You can use this when entering a mysql query to note the current time of [...]
Read More...