开发者

Daily style site [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I'm working on a daily style site. I found one site that does what I want and am wondering about the best way to do it.

I thought about having a PHP file that simply spits out a saying based on date(z) from PHP. O use a database because it's probably better practice.

What do you think? Here is the site I'm trying to emulate, you can get some idea from viewing the source, but the saying changes daily: http://daily-day.com开发者_运维百科/.

Just some suggestions in the right direction would be great. I don't want you to write it for me. As a beginner I want to do it myself with a little help.


Create a MySQL table to store quotes, and recall them using PHP. You could recall them based on date, or you might be able to do something where is selects the most recent quote (by id), that hasn't been requested yet. So maybe you would have a value called 'requested' and if it is 0, it hasn't been displayed. Then when you select it via MySQL_query(); you change the value to 1.


Seems overly complex with that javascript thingy. You can just output the text from PHP. You could use an array, but that means you have to add new proverbs to your code.

A database table would be just as easy. You need just a single table with a data and a text column. You can enter new proverbs for each day beforehand and just query the one for the current date.

It allows you to retrieve every line you have used so far, so you can add a 'browse history' feature later.

There are numerous MySQL examples for PHP. This is about as close as you'll get to the Hello World of databases. :)


I've done these things before and it depends on how many sayings you have. If you have 5 rotating sayings for a month:

<?php

 $sayings = "one
             two
             three
             ";

 $sayings = split("\n",$things);

 $num = date("z") % count($sayings);

 echo $sayings[$num];

?>

Or something like that could do the trick. But Trufa is right, if you want to know about CSS layout or something you're asking too broad a question. I don't think that is the case though.


This is an overly broad question that does not have much to do with a Q&A site, please take a look at our FAQ.

To briefly answer toy question getting a simple database structure working for a relatively small site is not so complicated and would help you scale eventually, you've said it yourself it is better practice.

Just imagine having to change your PHP file every time you add a new phrase or want to add some functionality. You could brake it every time.

Implement a database and google around for a some scripts examples of what you are doing, there are a lot out there and it will help you as a learning exercise.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜