Current location: Hot Scripts Forums » Programming Languages » PHP » Some help with a Simple Script


Some help with a Simple Script

Reply
  #1 (permalink)  
Old 03-29-08, 12:42 PM
boxer10 boxer10 is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Some help with a Simple Script

I am trying to write a very simple script but I am a total newb to PHP.
I was hoping for some help.

The script needs to print a list of clickable links on a webpage from
http://www.mydomain.com/100.htm to http://www.mydomain.com/646.htm
and everything in between those numbers is a page too.

I think I need to make 100 to 646 into a variable and then echo the URL with the variable in an unordered list. But I don't know quite how to write it.

If this is considered a script request and not script help, I apologize and I will delete and re-post into the script request forum, just let me know. Thanks.
Reply With Quote
  #2 (permalink)  
Old 03-29-08, 12:50 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Use range() to create an array of numbers between 100, and 646. Then use foreach() to loop through this array and output the links.
Reply With Quote
  #3 (permalink)  
Old 03-29-08, 12:58 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

echo "<ul>\r\n";
for(
$i=100;$i<=646;$i++)
{
$url"http://www.mydomain.com/".$i.".htm";
echo 
"<li>\r\n\t<a href=\"$url\">$url</a>\r\n</li>\r\n";
}
echo 
"</ul>\r\n"
something like that?
change the line
PHP Code:

 for($i=100;$i<=646;$i++)
#to
foreach(range(100,646) as $i
if you want to use the way nico suggested
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName

Last edited by Jay6390; 03-29-08 at 01:14 PM.
Reply With Quote
  #4 (permalink)  
Old 03-29-08, 10:32 PM
boxer10 boxer10 is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
THANK YOU Nico and Jay6390! Both versions worked perfectly!

One thing I don't understand, what is the

/r and the /n and the /t for? Thanks!
Reply With Quote
  #5 (permalink)  
Old 03-30-08, 02:44 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by boxer10 View Post
/r and the /n and the /t for?
The \r\n are to create a new line. While this is not apparent in html, if you look at the view source, you will see the difference in appearance with and without them. Also, the \t is a tab character, and is also there merely for the aesthetic's

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #6 (permalink)  
Old 04-01-08, 09:56 AM
boxer10 boxer10 is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Hi I got another question.

How would you write it if you want it to print 1 or more random numbers
between a certain range of numbers?
Reply With Quote
  #7 (permalink)  
Old 04-01-08, 09:59 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by boxer10 View Post
Hi I got another question.

How would you write it if you want it to print 1 or more random numbers
between a certain range of numbers?
Can you be a bit more specific? Give an example please
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #8 (permalink)  
Old 04-01-08, 03:45 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by boxer10 View Post
Hi I got another question.

How would you write it if you want it to print 1 or more random numbers
between a certain range of numbers?
print rand(100, 646);

This will print a random number between 100 and 646 inclusive. Adjust the values to use the range you want, and call the rand function each time you want a number.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #9 (permalink)  
Old 04-01-08, 05:22 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$max rand(1,100);
for(
$i=0;$i<=$max;$i++)
print 
rand(100,646)."<br />"
That will print between 1 and 100 random numbers between 100 and 646
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #10 (permalink)  
Old 04-02-08, 02:13 AM
boxer10 boxer10 is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you very very much!

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Raffle/Lottery Script (Very profitable!), Coded it myself. Voltaire General Advertisements 6 03-16-09 07:15 AM
3 Column CSS Fluid Layout (IE 6 Problem) Heidenreich12 CSS 9 10-04-06 03:22 PM
CSS Border Width Question. nova912 CSS 6 09-07-06 09:13 AM
Need a simple auction script installed caver911 Job Offers & Assistance 1 08-03-05 02:11 PM
Need help with this keyword script - i'm sure it's simple! dudeman248 JavaScript 2 05-19-04 05:11 PM


All times are GMT -5. The time now is 07:39 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.