More PHP - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

More PHP

Description:

More PHP – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 14
Provided by: gil3
Category:
Tags: php | assign | more | readable

less

Transcript and Presenter's Notes

Title: More PHP


1
More PHP
2
Strings
  • Assign str1 the value how are you guys?
  • str1 how are you guys
  • Assign str2 the value were great
  • str2 we\re great
  • Assign str3 the value of str1 and then str2
  • str3 str1 . str2
  • str3 str1 . . str2

NO! there should be a space between these two
lines
3
PHP Strings MYSQL
  • MYSQL takes input like
  • SELECT id, user from usertable where user
    gillw3
  • SELECT id, user from usertable where id 7
  • To write SQL in PHP
  • Assume we have stored the user id and name in id
    and user
  • sql SELECT id, user from usertable where user
    \ . user . \
  • sql SELECT id, user from usertable where id
    . id

4
Strings Functions
  • Orderly and Readable
  • cust mysql_real_escape_string(_GETexclude)
  • sql SELECT Customer,OrderDate,SUM(OrderPrice)
  • sql . FROM Orders
  • sql . where Customer ! \. cust . \
  • sql . GROUP BY Customer,OrderDate
  • //echo sql
  • result mysql_query(sql)

5
Strings Functions
  • Terrible
  • result mysql_query(SELECT Customer,OrderDate,S
    UM(OrderPrice) FROM Orders where Customer ! \.
    mysql_real_escape_string(_GETexclude). \
    GROUP BY Customer,OrderDate)

6
Other Times to Escape
  • Using PHP to write Javascript
  • Using PHP to write HTML

7
PHP to write JS
  • Writing a JS array
  • var myarray new Array(val1, val2, val3)
  • Using PHP to create the above array
  • jsoutput var myarray new Array(\
  • for(i 1 i lt 3 i)
  • jsoutput . \val . i . \,
  • jsoutput . )

8
PHP to write HTML
  • Creating a link, with the url stored in URL and
    the link text stored in text
  • Desired HTML
  • lta hrefhttp//www.rpi.edugt RPI lt/agt
  • With PHP
  • echo lta href\ . URL . \gt . text .
    lt/agt

9
Error Checking
  • Turn on error reporting in php (even if it is off
    in PHP.INI)
  • error_reporting(E_ALL)
  • Check for results frequently

10
Resources
  • Check the documentation, many functions return
    resources.
  • Resources cannot be directly manipulated

Function returns a resource
11
Page Based Applications
  • listproducts.php
  • displayproduct.php

12
ListProducts.php
  • Connects to db
  • Selects all products from DB
  • Loops over results
  • Prints out link to product
  • lta hrefdisplayproduct.php?pid.id.gtptitle.
    lt/agt
  • Closes DB connection

13
DisplayProduct.php
  • Connects to DB
  • Takes a product ID from the querystring
  • If no ID/an invalid ID is given, redirects user
    to listproducts.php
  • Selects product from DB
  • Displays product data
  • Closes DB connection
Write a Comment
User Comments (0)
About PowerShow.com