Page 1 of 1

Find numbers between 1 and 10

Posted: Mon Oct 16, 2006 2:04 pm
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

Posted: Mon Oct 16, 2006 2:06 pm
by feyd

Posted: Mon Oct 16, 2006 2:32 pm
by Jza
PHP seems to have a function for everything, how would I write each number generated by range into an sql database?

Posted: Mon Oct 16, 2006 2:36 pm
by feyd
generally

Code: Select all

INSERT INTO
  tableName
  (field1, field2)
  VALUES('value1', 'value2')

Posted: Mon Oct 16, 2006 2:39 pm
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.

Posted: Mon Oct 16, 2006 2:42 pm
by feyd
A foreach() may help, although if your database supports extended inserts, I'd use those too.

Posted: Mon Oct 16, 2006 2:44 pm
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.

Posted: Mon Oct 16, 2006 2:44 pm
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);