We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,521 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

DW complains of syntax error in checkbox code that uses row id as input value..

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);
3
Contributors
10
Replies
2 Hours
Discussion Span
2 Years Ago
Last Updated
11
Views
Question
Answered
stonybony
Newbie Poster
13 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

Gerbiler
Junior Poster in Training
81 posts since Nov 2010
Reputation Points: 12
Solved Threads: 14
Skill Endorsements: 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

stonybony
Newbie Poster
13 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

@gerbiler,

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

sb

stonybony
Newbie Poster
13 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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?

Gerbiler
Junior Poster in Training
81 posts since Nov 2010
Reputation Points: 12
Solved Threads: 14
Skill Endorsements: 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

stonybony
Newbie Poster
13 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

ko ko
Practically a Master Poster
673 posts since Jan 2009
Reputation Points: 120
Solved Threads: 152
Skill Endorsements: 1

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

Gerbiler
Junior Poster in Training
81 posts since Nov 2010
Reputation Points: 12
Solved Threads: 14
Skill Endorsements: 0
Question Answered as of 2 Years Ago by Gerbiler and ko ko

done. thanks

stonybony
Newbie Poster
13 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

stonybony
Newbie Poster
13 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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++;
}
Gerbiler
Junior Poster in Training
81 posts since Nov 2010
Reputation Points: 12
Solved Threads: 14
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.1351 seconds using 2.78MB