Welcome Guest, Not a member yet? Register   Sign In
Parse Error
#1

[eluser]Markie577[/eluser]
Hi People!

Wondering if someone could help with a problem I can't get my head around!

I want output a select field which gets its data from a database

this is the code
Code:
$options = '<select name="cities" id="cities">';
            foreach($data->result() as $row)
            {
            $options .= '<option value='$row->sort_id'>'$row->name_city;'</option>';
            }
            $options .= "</select>";
            
            echo $options; // this will be received by your jQuery script

The option variable within the foreach loop is the one that gives me trouble!
I get a Parse error
Parse error: syntax error, unexpected T_VARIABLE with that option field!

If I would delete that option variable and echo $row->name_city it will work!

anyone know what this can be?

Sincere thanks
#2

[eluser]n0xie[/eluser]
Code:
$options = '<select name="cities" id="cities">';
            foreach($data->result() as $row)
            {
            $options .= '<option value='.$row->sort_id.'>'.$row->name_city.'</option>';
            }
            $options .= "</select>";
Use concatenation.
#3

[eluser]Markie577[/eluser]
[quote author="n0xie" date="1275928284"]
Code:
$options = '<select name="cities" id="cities">';
            foreach($data->result() as $row)
            {
            $options .= '<option value='.$row->sort_id.'>'.$row->name_city.'</option>';
            }
            $options .= "</select>";
Use concatenation.[/quote]

Haha boy do i feel stupid... :roll: (A) Well thanks very much




Theme © iAndrew 2016 - Forum software by © MyBB