Prev | Current Page 207 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"


We??™ll use the LEFT(str, len)MySQL function to extract the first N (len) characters from
the product description, where N is the number of characters to be extracted. The following
SELECT command returns products??™ descriptions trimmed at 30 characters, with ???. . .??? appended
to the end if the description has a length greater than 30 characters:
SELECT name,
IF(LENGTH(description) <= 30, description,
CONCAT(LEFT(description, 30), '...')) AS description
FROM product
ORDER BY name;
The new column generated by the CONCAT(LEFT(description, 30), '...') expression
doesn??™t have a name by default, so we create an alias for it using the AS keyword. With your
current data, this query would return something like this:
CHAPTER 5 ?–  CREATING THE PRODUCT CATALOG: PART 2 125
name description
A Partridge in a Pear Tree The original of this beautiful...
Adoration of the Kings This design is from a miniatur...
Afghan Flower This beautiful image was issue...
Albania Flower Well, these crab apples starte...
Alsace It was in this region of Franc...
... ...
Joining Data Tables
Because your data is stored in several tables, all of the information you??™ll need might not be
one table. Take a look at the following list, which contains data from both the department and
category tables:
Department Name Category Name
----------------------------------------------------------------------------------
Regional French
Regional Italian
Regional Irish
Nature Animal
Nature Flower
Seasonal Christmas
Seasonal Valentine's
In other cases, all the information you need is in just one table, but you need to place
conditions on it based on the information in another table.


Pages:
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219