19. This Is Slightly Scary to Me $A = 1; $B = “2”; $C = ($A + $B); // Integer sum $D = $A . $B; // String catenation echo $C; // prints 3 echo $D; // prints 12
20. I Do Like the Explode Function – Good for csv $sequence = “A,B,C,D,E,F,G”; $elements = explode (“,”,$sequence); // Now elements is an array with all substrings between “,” char echo $elemets[0]; // output: A; echo $elemets[1]; // output: B; echo $elemets[2]; // output: C; echo $elemets[3]; // output: D; echo $elemets[4]; // output: E; echo $elemets[5]; // output: F; echo $elemets[6]; // output: G;
21.
22.
23.
24. Connecting to a Database <?php //connect to database $conn=mysql_connect(“sauron.cs.nott.ac.uk",“usr",“pwd") or die(“could not connect to database “.mysql_error()); mysql_select_db(“megagamez”) or die(“message”); // do something ……… //disconnect from database mysql_close($conn); ?>
25. Executing Database Queries <?php $query = "SELECT name, age, phone FROM students WHERE (name LIKE '%Smith%')"; //execute query $result = mysql_execute($query); while($row = mysql_fetch_array($result)) { echo($row[“name”].”, “); echo($row[“age”]); } ?> WOW! That was Easy!
26. You Will Want More Control Over the Format – So Make a Table <table width="75%" border="1" cellspacing="1" cellpadding="1" bgcolor="#FFFFFF"> <tr bgcolor="#CCFFFF"> <td height="22"><b>Name</b></td> <td height="22"><b>Age</b></td> <td height="22"><b>Telephone</b></td> </tr> … some php stuff </table>