[PHP-DB] Re: Displaying Text From A Data File
Thanks for your responses guys. I got it to work. Ron - Original Message - From: Ron Piggott <[EMAIL PROTECTED]> To: PHP DB <[EMAIL PROTECTED]> Sent: Saturday, September 04, 2004 2:00 PM Subject: Displaying Text From A Data File > I am still new to PHP and I wanted to ask a question. > > I am wanting to create a PHP script to randomly display one of many greeting > messages on my web site. I was going to store them in a text based file. I > wanted PHP to randomly select one of them and display it each time the > script was loaded. > > I am still new at PHP and I am not sure where to get started. But I was > thinking about this and I am sure this has already been done many times ... > I am not sure where to look on the web. > > Can any of you help me get started? > > Ron > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Displaying Text From A Data File
"Ron Piggott" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I am still new to PHP and I wanted to ask a question. > > I am wanting to create a PHP script to randomly display one of many greeting > messages on my web site. I was going to store them in a text based file. I > wanted PHP to randomly select one of them and display it each time the > script was loaded. > > I am still new at PHP and I am not sure where to get started. But I was > thinking about this and I am sure this has already been done many times ... > I am not sure where to look on the web. > > Can any of you help me get started? > > Ron Hi Ron, put your messages in a text file line by line (each message on a separate line). Then use the following code to echo out a random message: $messages = file('/path/to/your/file.txt'); // file() returns an array where each line is an array element $randomKey = array_rand($messages); // will return a random array index echo $messages[$randomKey]; Hope this helps. Regards, torsten Roehr -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re Displaying Text From A Data File
If it were a database, this would make sense. He's asking about a text- based file. This isn't really a database issue -- there's a lot of what are called "fortune scripts" out there that do exactly what you want. Do a search on Google. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Sat, 2004-09-04 at 19:59 +0100, Neil Smith [MVP, Digital media] wrote: > It's actually very simple : Just use > > SELECT * FROM tbl_name ORDER BY RAND() LIMIT 1 > > Cheers - Neil > > > At 17:35 04/09/2004 +, you wrote: > >Message-ID: <[EMAIL PROTECTED]> > >From: "Ron Piggott" <[EMAIL PROTECTED]> > >To: "PHP DB" <[EMAIL PROTECTED]> > >Date: Sat, 4 Sep 2004 14:00:56 -0400 > >MIME-Version: 1.0 > >Content-Type: text/plain; > > charset="iso-8859-1" > >Content-Transfer-Encoding: 7bit > >Subject: Displaying Text From A Data File > > > >I am still new to PHP and I wanted to ask a question. > > > >I am wanting to create a PHP script to randomly display one of many greeting > >messages on my web site. I was going to store them in a text based file. I > >wanted PHP to randomly select one of them and display it each time the > >script was loaded. > > > >I am still new at PHP and I am not sure where to get started. But I was > >thinking about this and I am sure this has already been done many times ... > >I am not sure where to look on the web. > > > >Can any of you help me get started? > > > >Ron > > > > CaptionKit http://www.captionkit.com : Production tools > for accessible subtitled internet media, transcripts > and searchable video. Supports Real Player, Quicktime > and Windows Media Player. > > VideoChat with friends online, get Freshly Toasted every > day at http://www.fresh-toast.net : NetMeeting solutions > for a connected world. > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re Displaying Text From A Data File
It's actually very simple : Just use SELECT * FROM tbl_name ORDER BY RAND() LIMIT 1 Cheers - Neil At 17:35 04/09/2004 +, you wrote: Message-ID: <[EMAIL PROTECTED]> From: "Ron Piggott" <[EMAIL PROTECTED]> To: "PHP DB" <[EMAIL PROTECTED]> Date: Sat, 4 Sep 2004 14:00:56 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Subject: Displaying Text From A Data File I am still new to PHP and I wanted to ask a question. I am wanting to create a PHP script to randomly display one of many greeting messages on my web site. I was going to store them in a text based file. I wanted PHP to randomly select one of them and display it each time the script was loaded. I am still new at PHP and I am not sure where to get started. But I was thinking about this and I am sure this has already been done many times ... I am not sure where to look on the web. Can any of you help me get started? Ron CaptionKit http://www.captionkit.com : Production tools for accessible subtitled internet media, transcripts and searchable video. Supports Real Player, Quicktime and Windows Media Player. VideoChat with friends online, get Freshly Toasted every day at http://www.fresh-toast.net : NetMeeting solutions for a connected world. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php