This is PHP4 Code! Get Number of Results $query1 = @mysql_query("SELECT COUNT(*) FROM some_table WHERE some_column != 1"); $number_of_rows = @mysql_fetch_array($query1); $number_of_rows = $number_of_rows[0]; echo "This many: $number_of_rows"; Results Based On An Average Score Calculation $query1 = @mysql_query("SELECT university_name, CONVERT((score / games_played), UNSIGNED INTEGER) as ave_score FROM tbl_universities ORDER BY ave_score DESC, university_name ASC"); […]
All posts by
Links
Google Fonts
Using Google Fonts Offline Find the font you want to use and find the Google recommended link to use (in the “Standard” tab). e.g. <link href=’http://fonts.googleapis.com/css?family=VT323′ rel=’stylesheet’ type=’text/css’> Enter the URL portion into your browser and get the resulting css, e.g. http://fonts.googleapis.com/css?family=VT323 gives: @font-face { font-family: ‘VT323’; font-style: normal; font-weight: 400; src: local(‘VT323’), local(‘VT323-Regular’), url(http://themes.googleusercontent.com/static/fonts/vt323/v4/LfMzj2MWAZU6qzlnp1MNbg.woff) […]
Text Align
Text Align
Paths
Up 1 parent directory level PHP Website Root directory This will give you the root directory of the current website (not the server root), e.g. ‘/public_html/’. If you want to access a folder above it you can do this: The current file Filesystem path – web server referenced Get filename from a path string
INSERT or UPDATE ON DUPLICATE
Object Oriented Style Insert Or Update If Already Present (Update if primary keys are not unique) Insert Or Update If Already Present WHERE You can ‘t use WHERE with ON DUPLICATE KEY UPDATE. A typical solution is to use a double operation instead, INSERT IGNORE followed by and UPDATE WHERE Insert or Do Nothing If […]
Reserved Names
Common Use Reserved Names Don't use the followign reserved names as otherwise you'll have to put them single quotes whenever you use them: index Full list here
Importing MySQL Table From An Uploaded CSV File
Loading A Table From An Uploaded .csv File <?php include_once('config.php'); //—– CONNECT TO DATABASE —– mysql_connect("localhost", $songs_db_username, $songs_db_password, $songs_db_name) or die("cannot connect"); mysql_select_db($songs_db_name) or die(mysql_error()); //Select the database so it doesn't need to be specified in mysql functions if ( (isset($_POST[‘action’])) && ($_POST[‘action’] == "uploading_all_songs_file") ) { //—————————————- //—– UPLOADING NEW ALL SONGS FILE —– […]
Dynamic json file
Use a php file which simply outputs json data. E.g. <?php //Get some data from a table $my_array = array(); $result1 = @mysql_query("SELECT field1, field2 FROM table1 ORDER BY field1"); while ($row = @mysql_fetch_array($result1)) { $my_array[] = $row; } //Add it and some other data to an array $data = array( "results" => array( "my_field1" […]
Title, description etc
Make titles less than 60 characters, and the descriptions less than 160, and they won't get "cut off" in the Google results.