Go Back   Dynamic Drive Forums > General Coding > PHP
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-29-2006, 03:38 AM
maverick maverick is offline
Junior Coders
 
Join Date: Dec 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow PHP Noob

Hey,

I'v been working with html and javascript for a while but when it comes to php i really suck,I was wondering if anyone had a script to display random text,description & link,I have a small movie review site and I wanted to have a table that displays a new movie everytime you reload the page,with a small ss of the the movies,small description and link to the big description. thank you for the support

kind regards

Mav
Reply With Quote
  #2  
Old 06-29-2006, 07:56 AM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 Posts
Default

The php for this is easy. the issue is getting the information.
Would you store it in a database (best idea)? text file? Directly within the php code (worst idea)?
__________________
Daniel - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #3  
Old 06-29-2006, 10:34 AM
maverick maverick is offline
Junior Coders
 
Join Date: Dec 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

since i'm planning on iframing that page i think directly on the script would be easier.
Reply With Quote
  #4  
Old 06-29-2006, 06:23 PM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 Posts
Default

It would create a really bulky page, and be limited later, especially for changing the values later on.
It is a bit easier to code... might work for your purposes. Integrating with a database or maybe text file could help you later on... something to think about later.

Basically... you could do something like this:
PHP Code:
Put this at the top of your page:
<?php
$array
[0] = "this is a quote";
$array[1] = "something else";
//add as many as you want, increasing the number each time.
$n rand (01); //Change the "1" to the highest value above.
?>

This outputs the quote.
Put it where you want the quote to go on your page:
<?php
echo $array[$n];
?>
The top part assigns values to an array then chooses a random number, assigning it to $n.
The bottom part takes that $n value and chooses the corresponding part of the array.
If you need more than just the quotes, you can use more than one array, assigning in the same exact way, just using something different than "array" in $array[0]. Like $quote[0], etc.
Then, when displaying them, just display all the variables there.

Note: Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.
that is from php.net. If you happen to be using a php version earlier than 4.2, you WILL need to seed the random number generator.
__________________
Daniel - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #5  
Old 06-29-2006, 06:55 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

Code:
<?php
  $quote = array(
    "Quote one",
    "Quote two",
    "Quote three"
  );
  $quote = $quote[rand(0, count($quote) - 1)];
?>

...

<?php echo($quote); ?>
... would be a more elegant way to do it, I think.
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Reply With Quote
  #6  
Old 06-29-2006, 09:33 PM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 Posts
Default

Indeed. I was going for simple, but that's much easier to manage. Good call.

Additionally, I figured my way taught what going on a little better, in hopes that maverick would learn php
But... now he's got two example, so that's better anyway, right?
__________________
Daniel - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #7  
Old 06-29-2006, 09:47 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

Lol, you may be right with the latter
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Reply With Quote
  #8  
Old 06-29-2006, 09:50 PM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 Posts
Default

Sure, but either way.
(And, your example teaches me, so it's win-win-win )
__________________
Daniel - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #9  
Old 06-29-2006, 11:04 PM
maverick maverick is offline
Junior Coders
 
Join Date: Dec 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thats for the help guys,so how would the text document script gets abouts?
Reply With Quote
  #10  
Old 06-29-2006, 11:37 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

Text document script?
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:36 PM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.