2013-04-23 56 views

回答

2

它使用

multi_query 

您可以鰭更多關於它here

像這樣的事情

$link = mysqli_connect("server", "user", "pass", "db"); 

if (mysqli_connect_errno()) { 
    printf("Connect failed: %s\n", mysqli_connect_error()); 
    exit(); 
} 


$testquery .= "INSERT INTO x (`agent_name`, `job_number`, `job_value`, `points_value`) SELECT agent_name, job_number, job_value, points_value FROM jobs WHERE YEAR(booked_date) = $current_year && WEEKOFYEAR(booked_date) = $weeknum;"; 

$testquery .= "SELECT agent_name, SUM(job_value), SUM(points_value) FROM leaderboard GROUP BY agent_name ORDER BY SUM(points_value) DESC"; 

mysqli_multi_query($link, $testquery) or die("MySQL Error: " . mysqli_error($link) . "<hr>\nQuery: $testquery"); 
+0

你能打電話給我樣品查詢 – soundari 2013-04-23 08:55:52

+0

我需要樣品查詢bcoz我嘗試了很多方法,但它不工作。 – soundari 2013-04-23 08:58:52

+0

Cechk我更新的答案供參考。 – 2013-04-23 09:01:22

0

您可以只需鍵入它,並自動將mysqli的讀取是可能的。像

@mysql_query("INSERT INTO x (`name`,`age`) VALUES ('me','21')"); 
@mysql_query("UPDATE y SET `status`='verified' WHERE `name`='me'");