Just another WordPress.com site

PHP – Dropdownbox

PHP function that easily generates dropdownboxes on “runtime”. The function just needs the name of the dropdownbox that should be generated and an array which contains the values which should be selectable in the dropdownbox:

function generateSelect($name = '', $options = array()) {
 $html = '<select name="'.$name.'">';
 $value = 0;    
 foreach ($options as $option) {               
 $html .= '<option value='.$value.'>'.$option.'</option>';
 $value = $value +1;
 $html .= '</select></br>';
 return $html;

Easy function that shows the PHP-Source Code of the page with syntax high lighting. Might be quite useful just copy it to you page and call it when you want to show you code:

echo '<p> This is the code php file: </ p>';
 $page = highlight_file($_SERVER [ 'SCRIPT_FILENAME'], TRUE);
 $page = str_replace (
 array ( '<code>', '/ code>', '','</ are >','< font color ="'),
 array ( '<pre style="padding:1em;border:2px solid black;overflow:scroll">', '/ pre>', '','</ span >','< span style = "color:' ), $page);
 echo $page;
 echo '<a <p> href="',$_SERVER['PHP_SELF'],'"> Back </ a> </ p>';
 echo '</ body> </ html>';

Pseudo AJAX

The following technique is not real ajax because there is now xml-http-request-object in use and no data is loaded from the server after the page is displayed. But it’s possible to open different menu entries without sending requests to the web server. How is it done?

Assumption: We have a home page with a menu containing: “Home”, “Information”, “About me”.

First using this technique the whole page is loaded on page load which means each content like “Home”, “About”, … has its own <div> element.

<div id="cHome" style="display: none ">
 welcome to home

It is important that each <div> has a css-style element that sets display to “none” this causes the browser to hide all the unwanted content.

How to display the content of “cHome” after clicking on menu button?

First we need to implement the java-script function, which hides all unwanted and shows all wanted content:

function display_content(id)
 document.getElementById('cHome').style.display='none'; //hides
 document.getElementById('cAbout').style.display='none'; //hides
 document.getElementById(id).style.display=''; //displays

 The java-script function is called using “onclick” on a
 menu button or link:

 <a href="#"  onclick="display_content('cHome')">Home</a>

 After clicking on Home, all other <div> are set invisible and the cHome
 <div> is displayed. This is all done using CSS and Java-Script
 without using requests to the server.

MySQL Phonetic Search

The MySQL-Server offers as well as nearly all other SQL-Server phonetic search which makes every search function user friendlier and easier to use. The fuction that is used in MySQL for phonetic search is called SOUNDEX. This function generates and returns a code based on the sound of the string which is passed to it. This means that two strings that sound equal have the same soundex-code.

SQL-Query: SELECT * FROM table WHERE SOUNDEX( table.column ) LIKE SOUNDEX( ‘search_value’ );

For further details see: http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_soundex

Tag Cloud