1. Trang chủ
  2. » Kỹ Năng Mềm

Lecture Web technologies and programming – Lecture 27: Retrieving data, delete, update from database - TRƯỜNG CÁN BỘ QUẢN LÝ GIÁO DỤC THÀNH PHỐ HỒ CHÍ MINH

20 8 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 20
Dung lượng 810,27 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

• Retrieving data from MySQL using PHP • CONNECTIONS: login functionality. • Deleting records in MySQL using PHP[r]

Trang 2

2

Trang 4

Creating database in MySQL using WAMP

database

web application with file upload

4

Trang 5

Retrieving data from MySQL using PHP

CONNECTIONS: login functionality

Trang 6

Connection with database

Make display structure

Write data

6

Trang 7

mysql_connect( “localhost” , ”root” , ”” ) or die( “Error in connection” );

die( “Error in Selection” );

?>

Trang 8

select data from one or more tables:

SELECT command in SQL:

FROM table-name

SELECT user_Name

FROM users

SELECT *

FROM users

Trang 9

Condition selection:

FROM table-name

SELECT *

Trang 10

<?php

include(‘connection.php’);

$sql = ‘ select * from users ’;

$result = mysql_query($sql);

?>

Trang 11

Counting rows:

mysql_num_rows(variable);

<?php

include(‘connection.php’);

$sql = ‘ select * from users ’;

$result = mysql_query($sql);

$users = mysql_num_rows($result);

Trang 12

<table border=‘1’>

<tr>

<th> User Name</th>

<th> User Email</th>

<th> User Password</th>

<th> User Picture</th>

</tr>

<tr>

<td> &nbsp;</td>

<td> &nbsp;</td>

<td> &nbsp;</td>

<td> &nbsp;</td>

</tr>

</table>

Trang 13

mysql_fetch_array(result-resource);

mysql_fetch_array( $result );

Trang 14

$result=

$row = mysql_fetch_array($result);

1 Ali ali@yahoo.com 123 upload/123ali.jpg

2 Umar umar@yahoo.com 123 upload/123umar.jpg

$row= 1 Ali ali@yahoo.com 123 upload/123ali.jpg

user_I d

user_Nam e

user_Emai l

user_Passwo rd

user_Pictur e

echo $row

[ 1 ];

echo

$row[ ‘user_Name’ ];

Trang 15

<table border=‘1’>

<tr>

<th> User Name</th>

<th> User Email</th>

<th> User Password</th>

<th> User Picture</th>

</tr>

<tr>

<td> <?php echo $row[1]; ?> </td>

<td> <?php echo $row[2]; ?> </td>

<td> <?php echo $row[3]; ?> </td>

<td> <img src= “<?php echo $row[4]; ?

User Name

User Email User

Password

User Picture Ali ali@yahoo.co

Trang 16

<table border=‘1’>

Heading Row

<?php

while($rows =

mysql_fetch_array($result))

{

?>

<tr>

<td> <?php echo $row[1]; ?> </td>

<td> <?php echo $row[2]; ?> </td>

<td> <?php echo $row[3]; ?> </td>

<td> <img src= “<?php echo $row[3]; ?

>”> </td>

</tr>

<?php } ?>

</table>

Name Password Picture Ali ali@yahoo.co

Umar umar@yahoo.

com

123

Trang 17

Starts a HTML page

Connection to database

Select command Query executed

Trang 18

Headin

g row

Loop starts Keeps row

Trang 19

Displays name

Displays email Displays

password

Displays

image Sets source

Ends loop

Trang 20

Records in user’s table

Output from the table

Ngày đăng: 01/04/2021, 18:31

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w