0

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);

Edited by stonybony: n/a

3
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by Gerbiler
Featured Replies
  • I am not quite sure what the red line of code is supposed to do. [CODE]$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>';[/CODE] Is that what you were looking for, or did you want the … Read More

1

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.

Votes + Comments
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

0

@gerbiler,

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

sb

0

@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?

0

@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

0

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.

0

@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

0

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++;
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.