Page 1 of 1

concatanating

Posted: Tue Jan 28, 2014 3:34 am
by jaad
Can someone explain to me how concatenation is used in this function?

1- why does value= $row[id] needs to be concatenated on both sides?

the result of this function returns a list rows with a check-box at the beginning of the line followed by firstname, lastname and email address all equally spaced on the same line. there is a tidbit in there I don't quite get because if I was to write an inline echo line to have the same output, I would write it differently and I am trying to figure out why there is a difference?

or does it have to do with the fact that it is concatenated inside the array todelete[] and then used by the delete query? but that poses a problem since I think we would need to use an explode function... as you can see, I'm not clear on theory and design question.

Code: Select all

// Display the customer rows with checkboxes for deleting
$query = "SELECT * FROM email_list";
$result = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($result)) {
echo '<input type="checkbox" value="' . $row['id'] . '" name="todelete[]" />';
echo $row['first_name'];
echo ' ' . $row['last_name'];
echo ' ' . $row['email'];
echo '<br />';
}

Re: concatanating

Posted: Tue Jan 28, 2014 5:33 am
by Celauran
You're using a single quote to delimit your strings. The complete string has three components, so you need two concatenation operators. The first operator joins 2 to 1, the second joins 3 to (1 + 2).

Code: Select all

'<input type="checkbox" value="' // 1
$row['id'] // 2
'" name="todelete[]" />' // 3
You could restructure it as above with an echo at the start of each line and achieve the same result.

Re: concatanating

Posted: Tue Jan 28, 2014 12:11 pm
by jaad
ok yes this makes sense. I think I been looking at it as being part of an input field which is throwing me off since a form is usually between HTML tags and then add a php tag in between for the value. Thanks for your help, much appreciated