Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assignment help PHP + MySQL crash course

Similar presentations


Presentation on theme: "Assignment help PHP + MySQL crash course"— Presentation transcript:

1 Assignment help PHP + MySQL crash course
2018/11/9 Assignment help PHP + MySQL crash course Minpeng Zhu

2 Assignment Implement a web application for movie management with movie database as data storage and a web front-end using the Linux-Apache-MySQL-PHP, or LAMP, Web development framework To be completed in groups (3-5) Deploy solution See TA in the lab to get a MySQL account for your group Demo your solution during the scheduled labs or send solution (URL + source) by to TAs by 2018/11/9 Gyozo Gidofalvi

3 Connecting to MySQL from PHP
$hostname = "linne.it.uu.se"; $username = "…"; $password = "…"; $link = mysql_connect($hostname, $username, $password) or die("Could not open connection to database"); ?> Now the variable $link contains the information for your connection to MySQL. You can disconnect using: mysql_close($link) or die("Could not close connection to database"); 2018/11/9 Gyozo Gidofalvi

4 Select a database, issue queries
Once you have connected successfully, you should select the database you will use. Then you can issue queries to the database. <?php mysql_select_db(“your DB name", $link) or die("Could not select database"); $result = mysql_query("select * from some_table") or die("Could not issue MySQL query"); ?> Now the variable $result holds the query resultset. No ; at the end 2018/11/9 Gyozo Gidofalvi

5 Printing the results from a query
After issuing a query, you retrieve the results using the variable $result. And typically each() and list() are used together to traverse an array. <?php $result = mysql_query("select * from book_table") if (mysql_num_rows($result) == 0) { print("No results matching your query<BR>\n"); } else { print("Here are the results:<BR>\n"); //Fetching one row with mysql_fetch_row() while ($row = mysql_fetch_row($result)) { while (list($key, $value) = each($row)) { print("$value "); } print("<BR>\n"); ?> 2018/11/9 Gyozo Gidofalvi

6 The above example would be used to show book data from a book table in a following way. e.g,
BookName Publish year Price Rating Database 2000 500 5 2018/11/9 Gyozo Gidofalvi

7 HTML forms and PHP variables
From an HTML page that had this form: <FORM ACTION="target.php" METHOD="GET"> <INPUT TYPE="TEXT" NAME="myvar"> <INPUT TYPE="TEXT" NAME="yourvar"> <INPUT TYPE="SUBMIT" NAME="submit"> </FORM> The PHP script (target.php) will receive the variables value from the form by the same name: <?php $myvar = $_GET[myvar]; $yourvar = $_GET[yourvar] print("you entered $myvar and $yourvar"); ?> 2018/11/9 Gyozo Gidofalvi

8 Drop down list usage Example of filling drop down list value from a database table. <tr><td>Category</td>    <td>    <select name=“Category">    <?php       $result = mysql_query("select name from category_table");       while($row = mysql_fetch_row($result))        {          print("<option>$row[0]</option>");         }      ?>     </select>     </td></tr> 2018/11/9 Gyozo Gidofalvi

9 Technique reference http://se.php.net/manual/en/book.mysql.php
2018/11/9 Gyozo Gidofalvi


Download ppt "Assignment help PHP + MySQL crash course"

Similar presentations


Ads by Google