这段代码来自Larry Ullman的PHP AND MySQL for Dynamic Web Sites (second edition) P.244这段代码是分页的代码,前面省略了,不是重点我的问题在第八和第九行,就是这句:
echo '<a href="view_users.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> '; 这里单引号里面的句点连接的用法谁能给我解释一下?(书上我觉得没讲清楚,给的几个例子也没有牵涉到如此复杂的结合) 把这句换成echo '<a href="view_users.php?s=' ($start - $display) '&np='$num_pages'&sort='$sort'">Previous</a> ';
会有什么区别? 就是在函数的前后去掉连接的句点,我觉得有单引号再加句点似乎多此一举,要加也应该加在外面?
Script Begin: // Make the links to other pages, if necessary.
if ($num_pages > 1) { echo '<br /><p>';
// Determine what page the script is on.
$current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button.
if ($current_page != 1) {
echo '<a href="view_users.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
} // Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="view_users.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
} else {
echo $i . ' ';
}
} // If it's not the last page, make a Next button.
if ($current_page != $num_pages) {
echo '<a href="view_users.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
} echo '</p>';
echo '<a href="view_users.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> '; 这里单引号里面的句点连接的用法谁能给我解释一下?(书上我觉得没讲清楚,给的几个例子也没有牵涉到如此复杂的结合) 把这句换成echo '<a href="view_users.php?s=' ($start - $display) '&np='$num_pages'&sort='$sort'">Previous</a> ';
会有什么区别? 就是在函数的前后去掉连接的句点,我觉得有单引号再加句点似乎多此一举,要加也应该加在外面?
Script Begin: // Make the links to other pages, if necessary.
if ($num_pages > 1) { echo '<br /><p>';
// Determine what page the script is on.
$current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button.
if ($current_page != 1) {
echo '<a href="view_users.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
} // Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="view_users.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
} else {
echo $i . ' ';
}
} // If it's not the last page, make a Next button.
if ($current_page != $num_pages) {
echo '<a href="view_users.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
} echo '</p>';
你改成echo ' <a href="view_users.php?s=' ($start - $display) '&np='$num_pages'&sort='$sort'">Previous </a> '; 1是 编译肯定出错
2是 即便是不出错了(大大的假设一下)很有可能使 $符号已经成为真的$了 所有的变量都不好用了,,,