Hi,

DW complains of a syntax error that I cannot understand. I use the code as a standalone and it is not a problem, but when used as a table element as written below, it complains of a syntax error. The red highlight is where it complains, the green seems to work just fine. Any help is appreciated. Thanks

stony

------------------------------ code follows

while ($row = $result->fetch()) {
	$output[] = '<tr>';
	$output[] = '<td>'.$row['manufacturer'].'</td>';
	$output[] = '<td>'.$row['model'].'</td>';
	$output[] = '<td>'.$row['description'].'</td>';
	$output[] = '<td>'.'&#x24;.'.$row['price'].'</td>';

	$output[] = '<td>' echo "<input type='text' name='Value[{$row['id']}]' value='{$row['value']}'>" '</td>';
    $output[] = '<td>' echo "<input type='checkbox' name='Update[{$row['id']}]' value='Box #{$row['id']}'>" '</td>';

// echo "<input type='text' name='Value[{$row['id']}]' value='{$row['value']}'>"
	


	$output[] = '<td>'.'<a href="cart.php?action=add&id='.$row['id'].'&product='.$product.'">Add to list</a>'.'<td>';
	$output[] = '</tr>';
}
$output[] = '</table>';
echo join('',$output);

Recommended Answers

All 10 Replies

I am not quite sure what the red line of code is supposed to do.

$output[] = '<td>';
 echo "<input type='text' name='Value[{$row['id']}]' value='{$row['value']}'>";
$output[] = '</td>';
    $output[] = '<td>';
 echo "<input type='checkbox' name='Update[{$row['id']}]' value='Box #{$row['id']}'>"; 
$output[] = '</td>';

Is that what you were looking for, or did you want the whole thing in one string like this

$output[] = '<td>'."<input type='text' name='Value[{$row['id']}]' value='{$row['value']}'>".'</td>';
    $output[] = '<td>'."<input type='checkbox' name='Update[{$row['id']}]' value='Box #{$row['id']}'>".'</td>';

Both of these should compile, but whether or not they actually do what you want them to is another story.

commented: good eye +0

@Gerbiler,

You are the captain of the ship. I kept using the echo to print the row id attached to the checkbox but as you pointed out, that was the syntax error. I am a beginner-to-inter PHP programmer. Thanks for pointing the error out. You are right, I am still working on seeing whether that code would work. I surmised that it would after reading about it here on another thread.

http://www.daniweb.com/web-development/php/threads/227698

Again, thanks

sb

@gerbiler,

the red line was supposed to be one line. it just wrapped over.

sb

@stonybony
Then why did you put a semi-colon in the middle of it? It seemed as though it was supposed to be 2 lines, the way you put it.

Anyway, is this thread solved?

@gerbiler,

>> Anyway, is this thread solved?

absolutely, the checkboxes and the textbox started showing up. I am putting code in to see whether they are getting the right values.

The whole thing below is supposed to be one line, like you pointed out. I don't know why it wrapped into two lines :-(

$output[] = '<td>' echo "<input type='text' name='Value[{$row['id']}]'value='{$row['value']}'>" '</td>';

The "echo" was the problem

Thanks

sb

You should not use '[]' by repeating in the loop. The '[]' will generate array room every time you assign it. You have 7 elements each time mysql_fetch looping. Specify the index for one looping. For example:

$count = 0;
while ($row = $result->fetch()) {
	$output[$count] = '<tr>';
	$output[$count] .= '<td>'.$row['manufacturer'].'</td>';
	$output[$count] .= '<td>'.$row['model'].'</td>';
	$output[$count] .= '<td>'.$row['description'].'</td>';
	$output[$count] .= '<td>&#x24;'.$row['price'].'</td>';

	$output[$count] .= '<td><input type="text" name="Value[{'.$row['id'].'}]" value="{'.$row['value'].'}"></td>';
    $output[$count] .= '<td><input type="checkbox" name="Update[{'.$row['id'].'}]" value="Box #{'.$row['id'].'}"></td>';

	$output[$count] .= '<td><a href="cart.php?action=add&id='.$row['id'].'&product='.$product.'">Add to list</a><td>';
	$output[$count] .= '</tr>';
        $count++;
}

Don't forget to put '.' to assign new value to the array element. If not, the last will override the first one and so on. You can easily check the array with 'var_dump($input)', and ensure that your data entered in the array.

Can you mark this thread as solved? I'm a bit pedantic that way. Thanks.

done. thanks

@zero13,

thanks for the response. I am a little confused about using the '[]' syntax. I thought that it created space only when required at the end of the array for more elements. Am I wrong in understanding that? thanks

sb

it works like this.

for($array as $value){
   $newarray[] = "1";
   $newarray[] = "2";
}// that is the same as
for($array as $value){
   $newarray[$counter] ="1";
   $counter++
   $newarray[$counter] = "2";
   $counter++;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.