[英]Struggling with php and html concatenating
Hi I have a loop which is outputting from database using php and html. 嗨,我有一个循环,它是使用php和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 /> }.'';
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. 为了将来解决这个问题,您可以将字符串带入IDE或什至是Notepad ++之类的语言,将语言设置设置为PHP,然后您将很快看到什么被解释为字符串以及什么是变量。
You could also use an online PHP linter for this if you're scratching your head. 如果您挠头,也可以使用在线PHP linter。
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. 这应该可以工作,但是在挣扎时不要过多连接。
$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; 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 /> }";
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 /> }'.
'';
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. 每当连接html和php时,请使用"
以避免此类问题并将其拆分为不同的echo
或将其存储在变量中。 "
支持打印字符串以及变量,并使用反斜杠字符\\
来描述另一个字符串字符串,例如“ image”标签的“ src”属性。 Use '
to describe array index. 使用'
来描述数组索引。
Hope you got it. 希望你明白了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.