如何使用带有$ row链接的str_replace 现在我的链接显示如下
example.com/view.php?category=laptop&model=dell i5
我想要这样
example.com/view.php?category=laptop&model=dell_i5
这是一个链接代码
<a href=\"detail.php?category=" . $row['category'] . "&model=" . $row['model'] ."\" >
那我如何使用str_replace链接&#34; 。 $ row [&#39; model&#39;]。&#34;
请帮我解决这个问题
完整代码
<?php
//connect to database
mysql_connect('localhost','user','password');
mysql_select_db('newalldata');
$page = (empty($_GET['page'])) ? 1 : $_GET['page'];
$max_results = 6;
$from = (($page * $max_results) - $max_results);
if(empty($_POST)) {
$query = "SELECT * FROM alldata LIMIT $from, $max_results";
}
$result = mysql_query("SET NAMES utf8"); //the main trick
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);
$count=0;
while($row = mysql_fetch_array($result))
{
if($count%6==0)
{
echo "<tr/>";
echo "<tr>";
}
echo "<td><hr><div class='style99' align='center'><a href=\"detail.php?category=" . $row['category'] . "&model=" . $row['model'] ."\" class=\"style2\"><img src='/media/image.php?width=200&height=210&image=/media/" . $row['photo'] . "' title=". $row['price'] ." alt=". $row['model'] ." style='FILTER: alpha(opacity=100);-moz-opacity: 1.0; opacity: 1.0;' onmouseover=BeginOpacity(this,100,40) onmouseout=EndOpacity(this,100)></a><p><font color='#3366FF'>" . $row['category'] . "</font></p><p><font color='#3366FF'>" . $row['model'] . "</font></p><p><font color='#336600'>" . $row['price'] . "</font></p><div></td>";
$count++;
}
?>
答案 0 :(得分:0)
$var = str_replace(" ","_",$row['model']);
<a href=\"detail.php?category=" . $row['category'] . "&model=" . $var ."\" >;
应该这样做 你可以查看http://php.net/manual/de/function.str-replace.php 第一个参数是您搜索的内容(在本例中为“”),第二个参数是您想要改为(“_”),然后检查哪个字符串。