User Tools

Site Tools


tutorials:zencartmods:quotes.html

This is an old revision of the document!


Create the Table

First, create a table in the DB that will hold all of your quotes. In our case, we wanted the quote, the author, a link to the author, and the date it was added, so a query like this did fine.

CREATE TABLE `quotes` (
`quotes_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`quotes_text` TEXT NOT NULL ,
`quotes_author` TEXT NOT NULL ,
`quotes_link` VARCHAR(255) NOT NULL,
`quotes_active` INT NOT NULL DEFAULT 0,
`quotes_date_added` DATE NOT NULL
) ENGINE = MYISAM ;

Pro tip: VARCHAR(255) is used commonly for things like URLs, but in reality some URLs are longer than 255 characters. Make sure you don't allow URLs that are too long to store, or else make this field bigger.

You can go ahead and insert some quotes in this stage if you like.

Add to Template

Find the place in the template where you'd like to insert the random quote, and add these lines:

$quote_sql = $db->Execute("SELECT * from quotes WHERE quotes_active = 1 ORDER BY RAND() LIMIT 1;");
$quote_content = '<div style="color: #000;font-weight: normal">"' . stripslashes($quote_sql->fields['quotes_text']) . '"</div> <br /><div style="text-align:right; margin-right: 10px;"> - <a style="font-weight: normal" href="'.stripslashes($quote_sql->fields['quotes_link']).'"  target="_blank">' . stripslashes($quote_sql->fields['quotes_author']). '</div></a></div>';
echo $quote_content;
/home/ladyada/public_html/wiki/data/attic/tutorials/zencartmods/quotes.html.1309377369.txt.gz · Last modified: 2016/01/28 18:05 (external edit)