让我们说我们有变量:$ page和$ id.例如,$ id = 2.我想从现有变量$ page和$ id:$ page2创建新变量.怎么做?可能吗??
我的db表看起来像那样.我正在尝试生成导航.db表中的菜单.这是我的表截图

我想得到类似的东西
<li><a href="?page=1">Level 1</a>
<ul>
<li><a href="?page=2">Level2</a>
<ul>
<li><a href="?page=3">Level3</a></li>
</ul>
</li>
</ul>
</li>
Run Code Online (Sandbox Code Playgroud)
这是我的递归php函数,它生成导航功能.
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<?php
require 'core/includes/db.php';
function menu($parent, $level){
global $db;
$q = $db->query("select * from menu where parent = '$parent'");
if($level > 0 && $q->num_rows > 0){
echo '<ul>';
}
while($row=$q->fetch_object()){
echo "<li>".$q->name."</li>"; (line 14)
//display this level's children
menu($q->id, $level+1); (line 16)
}
if($level > 0 && $q->num_rows > 0){
echo '</ul>';
}
}
echo '<ul>' …Run Code Online (Sandbox Code Playgroud) 我想在我的注册表单中使用jQuery Masked Input Plugin(http://digitalbush.com/projects/masked-input-plugin/).我的表格看起来像那样
...
<input class="part1" type="text" name="lname" value="Last Name" onfocus="if(this.value=='Last name') {this.style.color='#aea592';this.style.fontStyle='normal'; this.value=''};" onblur="if(this.value=='') {this.style.color='#aea592'; this.style.fontStyle='italic'; this.value='Last name'}" />
<input class="part2" type="text" id="dob" name="dob" value="Date of Birth" onfocus="if(this.value=='Date of Birth') {this.style.color='#aea592';this.style.fontStyle='normal'; this.value=''};" onblur="if(this.value=='') {this.style.color='#aea592'; this.style.fontStyle='italic'; this.value='Date of Birth'}" />
Run Code Online (Sandbox Code Playgroud)
...
一个文件的结尾
<script src="core/code/js/mask.js"></script>
<script type="text/javascript">
jQuery(function($) {
$('#dob').mask('99.99.9999', {placeholder:' '});
});
</script>
Run Code Online (Sandbox Code Playgroud)
当您打开页面时,姓氏字段显示单词"姓氏",但出生日期不显示任何内容.http://prntscr.com/2miaa如何仅为onfocus事件激活掩码插件?
我想把我国家的时间reg_date放在我的数据库表中.但是now()服务器的时间.如何将now()功能时间更改为阿塞拜疆(UTC +04.00)?
如果没有$ _GET,我试图给变量赋予默认值.有一种方法,if(isset(...))但它为每个变量编写一堆代码.在研究另一种解决方案的同时发现了这段代码.任何人都可以帮我理解第二行代码吗?
$defaults = array('page' => 'main', 'lang' => 'en');
foreach ($defaults as $k => $v) $$k = isset($_GET[$k])? $_GET[$k] : $v;
Run Code Online (Sandbox Code Playgroud) 我的db表看起来像那样

我正在尝试从此功能获取页面标题和内容
function page($current, $lang){
global $db;
$txt='txt_'.$lang;
$title='title_'.$lang;
$data=$db->query("SELECT '$txt', '$title' FROM pages WHERE `id`='$current'");
$data=$data->fetch_array(MYSQLI_BOTH);
return $data;
}
Run Code Online (Sandbox Code Playgroud)
然后在索引页面的开头获取数组值
$data=page($id, $lang);
并使用这个例子
<title><?=$data[1]?></title>
Run Code Online (Sandbox Code Playgroud)
但每次都得到相同的结果title_en(en是我的语言变量.).我的代码出了什么问题?
我的系统是Windows XP SP2,我的服务器是Microsoft Webmatrix.PHP运行良好,但是当我尝试添加数据库连接时,它会提供http错误500.0.发出错误的代码段
$db = new MySQLi('localhost', 'my_login', 'my_pass', 'db_name');
if ($db->connect_errno()) {
printf("Connect failed: %s\n", $db->connect_error());
exit();
}
Run Code Online (Sandbox Code Playgroud)
当我删除它时,页面加载正常.我该如何解决?
如何将日期分成碎片并从中获取最后一部分.可以说,我们有09.06.2010,我们想从它获得"2010".如何用PHP做到这一点?
用这段代码让用户ip地址.我的db表中有ip的unsigned int字段
<?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
//proxy check
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip=$_SERVER['REMOTE_ADDR'];
}
$ip = ip2long($ip);
?>
Run Code Online (Sandbox Code Playgroud)
在本地服务器上测试网站.问题是,越来越"63177408abbad957ed13ae1a2dd3e0b3ed47bd0b48ffcb362" ip2long转换后.试着
$ip=$_SERVER['REMOTE_ADDR'];
$ip = ip2long($ip);
Run Code Online (Sandbox Code Playgroud)
太.仍然没有成功.我该如何解决?
我正在使用以下功能来保护我的数据库免受注入攻击等gets.
function filter($data) {
global $db;
$data = trim(htmlentities(strip_tags($data)));
if (get_magic_quotes_gpc())
$data = stripslashes($data);
$data = $db->real_escape_string($data);
return $data;
}
foreach($_GET as $key => $value) {
$data[$key] = filter($value);
}
Run Code Online (Sandbox Code Playgroud)
问题是,我想不仅过滤$_GET,但$_POST也.怎么做?
我可以重新分配值$_GET或$_POST过滤后?我的意思是$_GET[$key] = filter($value);代替$data[$key] = filter($value);..