V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)
-
Upload
verity-lewis -
Category
Documents
-
view
216 -
download
0
Transcript of V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)
V 1.0 OE NIK, 2013 1
PHP+SQL9.
CRUD (songs + genres)
V 1.0
CRUD• Create, Read, Update, Delete – basic management of
tables• Typical task – some typical functions are required• Reading user input
if (set in _GET) { set local variable from _GET }else { set local variable as default value }if (not number and must be number) set local variable: 0
• ReplacementReplace [TAGS] in HTML by PHPforeach($row as $key=>$val) {
$actrow=str_replace("[{$key}]", $val, $actrow); }
• Create <select> inputs from arrays/tables2OE NIK, 2013
V 1.0
Reading user input
V 1.0
function import($arr, $value, $default, $must_numeric=0)
$arr=array('key1'=>'value1', 'key2'=>'value2');$value=import($arr, 'key1', 'defvalue');$value=import($arr, 'key3', 'defvalue');
$id=import($_GET, 'id', 0, true);$user_name=import($_POST, "uname", "");$userid=import($_SESSION, 'userid', 0, true);
Reading user input
V 1.0
It is done in a loop (to avoid preg_replace / PCRE)
Replacement
V 1.0
function designer_replace($str, $arr)$template="<html>
<head>[HEAD]</head><body>[BODY] </body></html>";
$x=array("HEAD"=>"<title>My Title</title>","BODY"=>"<p>Hello, world!</p>");
$output=designer_replace($template, $x);
$linkbase=file_get_contents("link_base.html");$arr=array("target"=>$target, "text"=>$text);return designer_replace($linkbase, $arr);
Replacement
V 1.0
Creating <select> inputs
V 1.0
function create_select_from_array($fieldname,$array, $defvalue)
$fname="myselect";$arr=array(0=>"NO", 1=>"YES");$def=1; // $def=set_def('_GET', $fname, 0);$sel=create_select_from_array($fname, $arr, $def);
<select name='myselect'><option value='0'>NO</option><option value='1' selected='selected'>YES</option></select>
Creating <select> inputs
V 1.0
Genres + Songs• Download php09_songs_part.zip
OE NIK, 2013 9
V 1.0 OE NIK, 2013 10
11OE NIK, 2013