concatanating

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
jaad
Forum Commoner
Posts: 95
Joined: Fri Jan 03, 2014 5:30 am
Location: Vancouver Canada

concatanating

Post 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 />';
}
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: concatanating

Post 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.
User avatar
jaad
Forum Commoner
Posts: 95
Joined: Fri Jan 03, 2014 5:30 am
Location: Vancouver Canada

Re: concatanating

Post 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
Post Reply