Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Help forming an array!!!

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Help forming an array!!!

Postby BigKyle » Sun Apr 06, 2003 12:07 pm

I've been programming PHP for a while but I'm still fairly new to more advanced things. First look at my site so far....

If you see where it say 'Jump to...' - then it has a drop down box with a page and the page number. Well - right now these are just typed in the HTML. I need to make it to where it will take the total number of pages. and break it into the numbers leading up to it.

IE: IF there are 7 total pages - it will put 1,2,3,4,5,6, and 7 into the array.

I can do any other editing like the implementing the array into the dropdown box - I just need to know how to assaign the array the right values

If there's another way to do this I am open for ideas! THANKS!!
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Apr 06, 2003 9:18 am

Postby pootergeist » Mon Apr 07, 2003 4:37 am

$temp_count = -1;
$array_max = 7;
while(++$temp_count < $array_max)
$output_array[$temp_count] = $temp_count+1;

if you plugged $array_max = 3 into that, you'd get

$output_array[0] = 1;
$output_array[1] = 2;
$output_array[2] = 3;

personally I wouldn't build an array though, I'd just echo the <option tags within the while loop

echo '<option value="' .$temp_count. '">Page ' .$temp_count. '</option>
and start $temp_count = 0 instead.
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

I accually got it already

Postby BigKyle » Mon Apr 07, 2003 9:42 pm

A tracked down a guy I used to know on the net and he helped me out - here is accually what the script looks like....

Code: Select all
for($i=1;$i<=$num_pages;$i++) { $i }

$i being a new var that stands for the page number
$num_pages being the total number of pages (also the number where it stops the loop)

when the loop is run, I have it placing a new line in the drop-down box filling in $i correctly.

you can see it in action @
the default is 10 per page...but set it at 1 or 2 per page and you'll see it add more page selections to the drop-down box

Thanks again for you input![/url][/code][/quote]
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Apr 06, 2003 9:18 am

Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.