我使用以下內容將公司數據插入到mysql表中。是否有可能在再次嘗試重新輸入之前檢查公司是否已經在數據庫中? php變量$company
是我想要檢查的。如果記錄已存在,請檢查mysql表
<?php
require("database.php");
// Opens a connection to a MySQL server
$con = mysql_connect("localhost", $username, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("medicom_wp", $con);
$pages = get_posts(array(
'orderby' => 'title',
'post_type' => 'members',
'numberposts' => 300,
'post_status' => 'any'
));
foreach($pages as $post) {
setup_postdata($post);
$company = get_field('company_name');
$address = get_field('address');
$city = get_field('city');
$post_code = get_field('post_code');
mysql_query("INSERT INTO markers (`name`, `address`, `lat`, `lng`, `type`) VALUES ('".$company."', '".$address.", ".$city.", ".$post_code."', '0.0', '0.0', '')");
}
wp_reset_query();
mysql_close($con);
?>