我有以下代码。使用单个选择查询和更新查询。当我删除更新查询时它工作正常。当我运行完整代码后,没有任何反应。 请帮助我,我想在选择查询的每个周期更新表。有没有办法执行以下代码。
$query = "SELECT * FROM ab_rec WHERE username='$userid'" or die(mysql_error());
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
$t_name=$row['testname'];
$first_url=$row['first_url'];
$thanks_url=$row['thanks_url'];
$start_date=$row['start_date'];
$parse_first_url = parse_url($first_url); //parsing URL of first page for removing main domain name from it.
$parse_thanks_url = parse_url($thanks_url);
$final_first_url = $parse_first_url['path'] ; //Finally parsed URLs are stored into new variables
$final_thanks_url = $parse_thanks_url['path'] ;
$row['unique_visits'] = calculate_visitors($final_first_url, $start_date);
$row['conversions']= calculate_visitors($final_thanks_url, $start_date);
$row['conversion_percent'] = ($conversions/$unique_visits_first)*100;
$query1="UPDATE `ab`.`ab_rec` SET unique_visits=$row['unique_visits'], conversions=$row['conversions'] , conversion_percent=$row['conversion_percent'], WHERE testname=$row['testname'] " or die(mysql_error());
$result2=mysql_query($query1, $connection);
echo "<tr><td>" . $checkbox . "</td><td>" ."<a href='my_test.php?test_name=$t_name'>".$row['testname'] . "</a></td><td>" . $row['date_of_creation'] . "</td><td>" . $row['unique_visits'] . "</td><td>" . $row['conversions'] . "</td><td>" . $row['conversion_percent'] ."%". "</td></tr>"; //$row['index'] the index here is a field name
}
答案 0 :(得分:0)
此:
$query1="UPDATE `ab`.`ab_rec` SET unique_visits=$row['unique_visits'],
conversions=$row['conversions'] , conversion_percent=$row['conversion_percent'],
WHERE testname=$row['testname'] " or die(mysql_error());
$result2=mysql_query($query1, $connection);
应该是:
$query1="UPDATE `ab`.`ab_rec` SET unique_visits=$row['unique_visits'],
conversions=$row['conversions'] , conversion_percent=$row['conversion_percent']
WHERE testname='{$row['testname']}'";
echo $query1; //POST THIS RESULT
$result2=mysql_query($query1, $connection) or die(mysql_error());