只是想知道是否可以这样做:
除了最后一位数字之外,我有多个具有相同名称的列:
第1轮,第2轮,第3轮,第4轮......等等
我还定义了一个我需要手动更新的变量,具体取决于我在所有查询中要考虑的列ID,而不是单独更新每个列(节省时间)
$round_number="4"; // round 4 selected for example here
然后这是我的一个查询,我需要它来选择上面变量定义的轮数,我试过这个:
SELECT *, sum(Round'$round_number') as round_total from mytable where group_name LIKE 'fighters%' group by side order by round_total desc
如预期的那样,上面的查询失败了......
欢迎任何帮助
谢谢费拉斯 编辑(实际查询)
$latest_week="4"; // UPDATE ALERT HERE
$result = mysql_query("SELECT *, sum(SR) as SRT, sum(RS'. $latest_week . ') as RST FROM na_july16_resources_v2 where group_name LIKE 'fighters%' group by side order by RST desc")
或死(mysql_error());
答案 0 :(得分:1)
在PHP中,字符串与点连接。
$sql = 'SELECT *, sum(Round' . $round_number . ') as round_total from mytable where group_name LIKE \'fighters%\' group by side order by round_total desc'
答案 1 :(得分:1)
您可以使用双引号在字符串中读取变量。双引号(而不是单引号)中的字符串将被解析为变量名称。所以你可以这样做来在查询中使用变量:
<?php
$email_to = "admin@urbansushi.com";
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$date = $_POST['date']; // required
$email_subject = "New feedback from CUSTOMER";
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Date of Visit: ".clean_string($date)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
正如Jaime所说,你也可以用点连接字符串。