Find numbers between 1 and 10

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jza
Forum Newbie
Posts: 17
Joined: Sat Sep 23, 2006 10:10 am

Find numbers between 1 and 10

Post by Jza »

Hello,

I'm currently working on a project that requires me to do the following:
- Find the numbers between any two given integers between 1 and 365 (i.e: 1 and 9, should echo 1,2,3,4,5,6,7,8,9) I'm not exactly sure how these integer should be stored (array, etc.) But they need to be written to an SQL database, I was thinking a for loop, but I'm not sure how to do this.

Please help,
Jeff
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Jza
Forum Newbie
Posts: 17
Joined: Sat Sep 23, 2006 10:10 am

Post by Jza »

PHP seems to have a function for everything, how would I write each number generated by range into an sql database?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

generally

Code: Select all

INSERT INTO
  tableName
  (field1, field2)
  VALUES('value1', 'value2')
Jza
Forum Newbie
Posts: 17
Joined: Sat Sep 23, 2006 10:10 am

Post by Jza »

feyd wrote:generally

Code: Select all

INSERT INTO
  tableName
  (field1, field2)
  VALUES('value1', 'value2')
Yes, I know that lol. But I don't know how many values I'm going to have, I could have 365 values, or I could have 2.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

A foreach() may help, although if your database supports extended inserts, I'd use those too.
Jza
Forum Newbie
Posts: 17
Joined: Sat Sep 23, 2006 10:10 am

Post by Jza »

feyd wrote:A foreach() may help, although if your database supports extended inserts, I'd use those too.
Thanks alot Feyd, much appreciated. I'll be sure to PM you the next time I need help ;) (kidding). If anyone else has anything to add, i'd still appreciate it.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

There's no need to store every number in the database... store the minimum value, and the maximum value, and then when you take it out of the db, do this...

Code: Select all

$array = range($min, $max);
Post Reply