Learning PHP and MySQL

Monday, August 07, 2006

Example 06-10 Using extract with the EXTR_PREFIX_ALL directive

<?php
$Apple
="Computer";
$shapes=array('SodaCan'  =>  'Cylinder',
              
'NotePad'  =>  'Rectangle',
              
'Apple'  =>  'Sphere',
              
'Orange'  =>  'Sphere',
              
'PhoneBook'  =>  'Rectangle');

extract($shapes,EXTR_PREFIX_ALL,"shapes");
//  $shapes_SodaCan,  $shapes_NotePad,  $shapes_Apple,  $shapes_Orange,  and
//$shapes_PhoneBook  are  now  set

echo "Apple is $Apple.<br>";
echo 
"Shapes_Apple is $shapes_Apple";
echo 
"<br>";
echo 
"Shapes_NotePad is $shapes_NotePad";
?>

Posted by krautgrrl on 08/07 at 10:25 AM
Chapter 6 Code • (0) Comments • (2) TrackbacksPermalink

Example 06-11 Using EXTR_PREFIX_ALL on a numeric array

<?php
$shapes
=array( 'Cylinder','Rectangle'); 
extract($shapes,EXTR_PREFIX_ALL,"shapes"); 
echo 
"Shapes_0 is $shapes_0 <br>";
echo 
"Shapes_1 is $shapes_1";
?>

Posted by krautgrrl on 08/07 at 10:25 AM
Chapter 6 Code • (0) Comments • (98) TrackbacksPermalink

Friday, August 18, 2006

Example 07-01 Creating the books and authors tables

CREATE TABLE books title_id INT NOT NULL AUTO_INCREMENT
                     
title VARCHAR (150),
                     
pages INT,
                     
PRIMARY KEY (title_id)); 
CREATE TABLE authors author_id INT NOT NULL AUTO_INCREMENT
                       
title_id INT NOT NULL,
                       
author VARCHAR (125), 
                       
PRIMARY KEY (author_id));

Posted by krautgrrl on 08/18 at 10:40 AM
Chapter 7 Code • (0) Comments • (27) TrackbacksPermalink

Example 07-02 The SQL to create and populate a purchases table that links user_ids and title_ids

This code is for:
The SQL to create and populate a purchases table that links user_ids and title_ids to a purchase_id

CREATE TABLE `purchases` ( purchase_id int(11NOT NULL auto_increment
                           
user_id varchar(10NOT NULL,
                           
title_id int(11NOT NULL,
                           
purchased timestamp NOT NULL default CURRENT_TIMESTAMP
                           
PRIMARY KEY  (purchase_id));
INSERT INTO `purchasesVALUES (1'mdavis'2'2005-11-26 17:04:29');
INSERT INTO `purchasesVALUES (2'mdavis'1'2005-11-26 17:05:58');

Posted by krautgrrl on 08/18 at 10:41 AM
Chapter 7 Code • (5) Comments • (391) TrackbacksPermalink

Monday, August 07, 2006

Example 08-01 The contents of the my_backup.sql file

-- MySQL dump 10.9
--
-- 
Hostlocalhost    Databasetest
-- ------------------------------------------------------
-- 
Server version    4.1.11-Debian_4-log
--
-- 
Table structure for table `authors`
--
DROP TABLE IF EXISTS `authors`; 
CREATE TABLE `authors` ( `author_idint(11NOT NULL auto_increment,
             `
title_idint(11NOT NULL default '0',
             `
authorvarchar(125) default NULLPRIMARY KEY (`author_id`)
ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- 
Dumping data for table `authors`
--
/*!40000 ALTER TABLE `authors` DISABLE KEYS */LOCK TABLES `authorsWRITE;
INSERT INTO `authorsVALUES (1,1,'Ellen Siever'),(2,1,'Aaron Weber'),(3,2,'Arno ld Robbins'),(4,2,'Nelson Beebe');
UNLOCK TABLES;
/*!40000 ALTER TABLE `authors` ENABLE KEYS */;

Posted by krautgrrl on 08/07 at 05:10 PM
Chapter 8 Code • (3) Comments • (256) TrackbacksPermalink

Example 08-02 Book titles in CSV format

1,Linux in a Nutshell,476
2
,Classic Shell Scripting,256

Posted by krautgrrl on 08/07 at 05:10 PM
Chapter 8 Code • (1) Comments • (3) TrackbacksPermalink

Example 08-03 Creating a simple index

CREATE UNIQUE INDEX `authindON `authors` (`author`);

Posted by krautgrrl on 08/07 at 05:11 PM
Chapter 8 Code • (0) Comments • (0) TrackbacksPermalink

Example 08-04 Using CONCAT to put fields together

SELECT CONCAT(`title`,' has ',`pages`,' pages.'FROM `books`;

Posted by krautgrrl on 08/07 at 05:12 PM
Chapter 8 Code • (3) Comments • (0) TrackbacksPermalink

Example 08-05 Calculating the length of a string

SELECT CONCAT(`title`,' has 'LENGTH(`title`), ' characters.'FROM `books`;

Posted by krautgrrl on 08/07 at 05:13 PM
Chapter 8 Code • (0) Comments • (1) TrackbacksPermalink

Example 08-06 Changing the case of the title

SELECT UCASE(`title`), LCASE(`title`) from `books`;

Posted by krautgrrl on 08/07 at 05:13 PM
Chapter 8 Code • (2) Comments • (1) TrackbacksPermalink

Example 08-07 Using the LEADING option to remove zeros

SELECT TRIM(LEADING '0' from '0000Example00000');

Posted by krautgrrl on 08/07 at 05:13 PM
Chapter 8 Code • (0) Comments • (0) TrackbacksPermalink

Example 08-08 Using TRIM with the TRAILING option

SELECT TRIM(TRAILING '0' from '0000Example00000');

Posted by krautgrrl on 08/07 at 05:14 PM
Chapter 8 Code • (0) Comments • (1) TrackbacksPermalink

Example 08-09 Looking for the string in our author names

SELECT LOCATE`author`,LOCATE('on',`author`) FROM `authors`;

Posted by krautgrrl on 08/07 at 05:14 PM
Chapter 8 Code • (0) Comments • (0) TrackbacksPermalink

Example 08-10 Adding the formatting to a phone number using LEFT, RIGHT, and SUBSTR

SELECT CONCAT('('LEFT('6128238193',3),
')'SUBSTR('6128238193',4,3),
'-',
RIGHT('6128238193'4));

Posted by krautgrrl on 08/07 at 05:15 PM
Chapter 8 Code • (26) Comments • (1) TrackbacksPermalink

Example 08-11 Using WEEKDAY to get the day of the week

SELECT WEEKDAY('1964-10-12');

Posted by krautgrrl on 08/07 at 05:15 PM
Chapter 8 Code • (1) Comments • (0) TrackbacksPermalink
Page 6 of 15 pages « First  <  4 5 6 7 8 >  Last »

Statistics

This page has been viewed 375167 times
Page rendered in 0.2857 seconds
Total Entries: 224
Total Comments: 16
Total Trackbacks: 307338
Most Recent Entry: 09/27/2006 12:39 pm
Most Recent Comment on: 10/26/2007 10:00 am
Total Members: 2
Total Logged in members: 0
Total guests: 8
Total anonymous users: 0
Most Recent Visitor on: 02/10/2012 09:08 am
The most visitors ever was 1103 on 11/20/2007 12:50 pm

Referrers

Powered by ExpressionEngine