Drop Down: Per Page: Array Problem...

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
johnsonnc
Forum Newbie
Posts: 3
Joined: Tue Jan 20, 2004 10:42 pm

Drop Down: Per Page: Array Problem...

Post by johnsonnc »

i am trying to create a drop down box for page views this the code i am trying to it with and it seems to work a side from this error:

Warning: Cannot use a scalar value as an array in /home/quickj2/public_html/tracq/devlopment/gui_ctl_http.php on line 119

Warning: Cannot use a scalar value as an array in /home/quickj2/public_html/tracq/devlopment/gui_ctl_http.php on line 134

Warning: Cannot use a scalar value as an array in /home/quickj2/public_html/tracq/devlopment/gui_ctl_http.php on line 135

Warning: Cannot use a scalar value as an array in /home/quickj2/public_html/tracq/devlopment/gui_ctl_http.php on line 136

Warning: Cannot use a scalar value as an array in /home/quickj2/public_html/tracq/devlopment/gui_ctl_http.php on line 137

Warning: Cannot use a scalar value as an array in /home/quickj2/public_html/tracq/devlopment/gui_ctl_http.php on line 138

here is the code:

Code: Select all

function create_dropdown($name,$item_array){
	echo "<select name ="$name">";
	foreach ($item_array as $key => $value)&#123;
	echo "<option value="$value">"$value"</option>";
	&#125;
	echo "</select>";
&#125;


// create per-page drop
if(empty($perpage)) &#123;
$perpage&#1111;0]= 5;
$perpage&#1111;1] = 10;
$perpage&#1111;2] = 15;
$perpage&#1111;3] = 25;
$perpage&#1111;4] = 50;
&#125;
else &#123;
switch ($perpage) &#123;
	case 5:
		$perpage&#1111;0] = 5;
	break;
	case 10:
		$perpage&#1111;0] = 10;
	break;
	case 15:
		$perpage&#1111;0] = 15;
	break;
	case 25:
		$perpage&#1111;0] = 25;
	break;
	case 50:
		$perpage&#1111;0] = 50;
	default:
		$perpage&#1111;0] = 5;
		break;
				&#125;

$perpage&#1111;1]= 5;
$perpage&#1111;2] = 10;
$perpage&#1111;3] = 15;
$perpage&#1111;4] = 25;
$perpage&#1111;5] = 50;
&#125;
create_dropdown("Per Page", $perpage);

thanx for help in advance...
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Make sure that $name has square brackets as part of the name.

like

options[]

or

skills[]

etc.
johnsonnc
Forum Newbie
Posts: 3
Joined: Tue Jan 20, 2004 10:42 pm

no go...

Post by johnsonnc »

the error is @ 115 and beyond... the switch starts at line 114... sorry should have said that...
so it's really not even getting that far to have $name be a issue
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Switch commands don't like int values.

This won't work...

Code: Select all

<?php

$value = 1;

switch($value)
{
    case 1:
        echo "one";
    break;
}

?>
This will work...

Code: Select all

<?php

$value = "1";

switch($value)
{
    case 1:
        echo "one";
    break;
}

?>
As far as I know you can't give switch() and array either, so if $perpage is an array when you give it to the switch() it won't know what to do with it.
johnsonnc
Forum Newbie
Posts: 3
Joined: Tue Jan 20, 2004 10:42 pm

tried that... nothin'

Post by johnsonnc »

ya i thought about that but that didn't work either gave me the exact same thing....
Post Reply