v 1.0 oe nik, 2013 1 php+sql 9. crud (songs + genres)

11
V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)

Upload: verity-lewis

Post on 23-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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)

Page 2: V 1.0 OE NIK, 2013 1 PHP+SQL 9. 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

Page 3: V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)

V 1.0

Reading user input

Page 4: V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)

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

Page 5: V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)

V 1.0

It is done in a loop (to avoid preg_replace / PCRE)

Replacement

Page 6: V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)

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

Page 7: V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)

V 1.0

Creating <select> inputs

Page 8: V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)

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

Page 9: V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)

V 1.0

Genres + Songs• Download php09_songs_part.zip

OE NIK, 2013 9

Page 10: V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)

V 1.0 OE NIK, 2013 10

Page 11: V 1.0 OE NIK, 2013 1 PHP+SQL 9. CRUD (songs + genres)

11OE NIK, 2013