P. 1
Extraordinar de BUNNNN

Extraordinar de BUNNNN

|Views: 104|Likes:
Published by Liviu Cana

More info:

Published by: Liviu Cana on Jan 09, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/31/2013

pdf

text

original

3 Type function ?(), replacing
? with a name for the
function.

4 Type {.

5 Type the code you want to
have the function execute.

6 Type }.

7 Type ?>.

1 In your editor, open an
existing PHP document or
create a new one.

2 At the top of the page, type

Create Your Own PHP Function

You can encapsulate PHP code that you need to reuse into functions. The syntax for creating PHP

functions is nearly identical to that for creating functions in JavaScript: You begin by using the

function keyword, followed by the name of the function and a pair of parentheses. The code
for the function is enclosed in curly braces. You can pass arguments to the function by creating
variables within the parentheses, and send a value out of the function using the return keyword.
Functions are called in PHP by simply referencing their name.

1

2

3

5

7

4

6

14_881019-ch12.indd 29014_881019-ch12.indd 290

9/22/10 8:57 PM9/22/10 8:57 PM

291

CHAPTER

12

Creating Dynamic Pages

What sorts of things can I use functions for?

A function can be used for any logical block of code.
Most often, you use functions to designate a set of
code that you need to call repeatedly, but some
developers use them simply to organize the code
into blocks.

Does my function have to go at the top of the
page?

No, it merely needs to be written before it is called.
Most developers place functions at the top of the
page to keep them together and easy to find, but
they can be placed anywhere.

● When you view the page in
the browser, the function
works.

8 At the point on the page
where you want to call the
function, type echo and
then the function name
followed by parentheses and
a semi-colon.

8

TIPS

14_881019-ch12.indd 29114_881019-ch12.indd 291

9/22/10 8:57 PM9/22/10 8:57 PM

CHAPTER 13

Adding
Information
from a Database

Creating a dynamic site gives you the ability to allow your site to

interact with a database. Databases are used to store information,

which your site can then both display and manipulate.

15_881019-ch13.indd 29215_881019-ch13.indd 292

9/22/10 8:59 PM9/22/10 8:59 PM

Understanding Relational Databases . . . . . . . . . . 294

Create a Database . . . . . . . . . . . . . . . . . . . 296

Create a Table . . . . . . . . . . . . . . . . . . . . . 298

Populate the Table with Data . . . . . . . . . . . . . . 300

Connect PHP to the Database . . . . . . . . . . . . . . 302

Display the Contents of a Table on a Web Page . . . . . 304

Search the Database . . . . . . . . . . . . . . . . . . 308

Insert New Data into a Table with PHP . . . . . . . . . 312

15_881019-ch13.indd 29315_881019-ch13.indd 293

9/22/10 8:59 PM9/22/10 8:59 PM

294

A database, in the simplest terms, is a structured collection of information, or records. Computer

databases can be used to store massive amounts of information in a format that makes it easy to
sort and find specific data points. Early databases were first developed in the years following World
War II. In the 1970s, a new model was proposed that more efficient data storage would be possible
if databases were created as a series of related tables. Today, almost every major database system on
the market follows this relational database model.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->