Reputation: 5
Hi I have a loop which is outputting from database using php and html. I am trying to concatenate them together and have been messing around from a while now and can't get it correct can someone please give me some help, here is the string
I believe the problem is towards the end.
echo $rowCars['Make']. ' '.$rowCars['Model']. ' '.$rowCars['Age']. ' '.$rowCars['Reg']. ' '.$rowCars['Owner']. ' <img src="assets/images'.$rowCars['Image'].'" /> ''.
<a href="editdata.php?theid='$rowCars['ID']'">Edit Car</a><br /> }.'';
Upvotes: 0
Views: 35
Reputation: 1529
echo $rowCars['Make']." ".$rowCars['Model']." ".$rowCars['Age']." ".$rowCars['Reg']." ".$rowCars['Owner'];
echo "<img src=\"assets/images/" . $rowCars['Image'] . "\" />";
echo "<a href=\"editdata.php?theid=" . $rowCars['ID'] . "'\">Edit Car</a><br/>";
Whenever you are concatenating html and php, use "
for avoiding this kind of issues and split it into either in different echo
or store it in variable. "
supports printing of strings as well as variables also and use backslash character \
in describing string within another string like "src" attribute of "image" tag. Use '
to describe array index.
Hope you got it.
Upvotes: 0
Reputation: 16
I think this is what you want:
echo
$rowCars['Make'].
' '.
$rowCars['Model'].
' '.
$rowCars['Age'].
' '.
$rowCars['Reg'].
' '.
$rowCars['Owner'].
' <img src="assets/images'.
$rowCars['Image'].
'" /> ''.
'<a href="editdata.php?theid=' . $rowCars['ID'] . '">Edit Car</a><br /> }'.
'';
Upvotes: 0
Reputation: 339
$str = $rowCars['Make']. ' '.$rowCars['Model']. ' '.$rowCars['Age']. ' '.$rowCars['Reg']. ' '.$rowCars['Owner'];
$str .= "<img src='assets/images/'".$rowCars['Image'].'/>';
$str .= "<a href='editdata.php?theid='".$rowCars['ID']."'>Edit Car</a><br /> }";
echo $str;
or
echo $rowCars['Make']. ' '.$rowCars['Model']. ' '.$rowCars['Age']. ' '.$rowCars['Reg']. ' '.$rowCars['Owner'] <img src='assets/images/'".$rowCars['Image'].'/>' <a href='editdata.php?theid='".$rowCars['ID']."'>Edit Car</a><br /> }";
Upvotes: 0
Reputation: 182
You have some mistakes with Quotes and escaping
echo $rowCars['Make']. ' '.$rowCars['Model']. ' '.$rowCars['Age']. ' '.$rowCars['Reg']. ' '.$rowCars['Owner']. ' <img src="assets/images'.$rowCars['Image'].'" /> ''.
<a href=\"editdata.php?theid='.$rowCars['ID'].'\">Edit Car</a><br /> }';
This should work, but do not concate so much when your struggeling.
Upvotes: 0
Reputation: 514
I think it should be:
echo $rowCars['Make']. ' '.$rowCars['Model']. ' '.$rowCars['Age']. ' '.$rowCars['Reg']. ' '.$rowCars['Owner']. ' <img src="assets/images'.$rowCars['Image'].'" />'.'<a href="editdata.php?theid='.$rowCars['ID'].'">Edit Car</a><br />';
To help with this in future, you can bring your string into an IDE or even something like Notepad++, set the language settings to PHP, and you'll quickly see what is being interpreted as a string, and what is a variable.
You could also use an online PHP linter for this if you're scratching your head.
Upvotes: 1