This is a discussion on "PHP Looping script" within the PHP Forum section. This forum, and the thread "PHP Looping script are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
PHP Looping script
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
PHP Looping script
Hello all
I'm new here and I need some advice. Im trying to create a script that will loop and return multiple variables. for example I have a mysql database with image records in it. I want the script to return something like $image1="image1name" $image2="image2name" but the amount of images in the database changes all the time so one day i may have 10 and the next day 25 I hope this makes sensei Thanks in advance Pete |
|
|
|
#2
|
||||
|
||||
|
Re: PHP Looping script
Check out arrays. From what it sounds like, those will make your life a lot easier.
http://php.net/array |
|
#3
|
||||
|
||||
|
Re: PHP Looping script
It would help if you gave a description of the table including a row or two of sample contents, and how it was populated.
I've never really done this, but here's an interesting idea at least, assuming 1) a table whose first field is the autonumber and 2) the second field is a graphic that you want identified with the autonumber:
Just a thought. If I'm missing something really stupid, I'm sure someone will point it out |
|
#4
|
|||
|
|||
|
Re: PHP Looping script
Hi there
You can fairly easily create $image1 to $image100 etc., using variable variables, however given the number is going to shift ongoing it would be better to learn to use arrays and store the images in an array instead: $images = array(); $counter = 0; while ($r = mysql_fetch_row($result)) { //you could say $images[$counter] = $r[0]; // or wherever in the result set the image is //or perhaps array_push($images, $r[0]); //also several other ways; if you really want to assign to strings ${"image$counter"} = $r[0]; //look up variable variables for more info on php.net $counter++; } //this is what your array now has: print_r($images); |
![]() |
| Tags |
| dynamic variables, looping script |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Automatic Button 'Looping' for Navigation | starrzo | JavaScript Forum | 2 | Apr 4th, 2008 14:38 |
| Looping through arrays | assgar | Starting Out | 1 | Apr 22nd, 2007 18:43 |
| Looping through objects with variables and strings [Help Please] | andrewbriscoe87 | JavaScript Forum | 1 | Mar 24th, 2007 16:14 |
| looping issue with flash file | snooper | Flash & Multimedia Forum | 9 | Nov 20th, 2006 13:34 |
| looping background music | gwx03 | Flash & Multimedia Forum | 6 | Sep 7th, 2003 03:07 |