私はラジオやチェックボックスでいっぱいのフォームからすべての値を取得する次のphp配列を持っています。php配列のクエリを書く方法は?
foreach(array('buss_type','anotherfield','anotherfield','...etc') as $index)
{
if (isset($this->request->post[$index])) {
$this->data[$index] = $this->request->post[$index];
} else {
$this->data[$index] = NULL;
}
}
は今、私が作成したばかりの新しいテーブル(小売店)に、私のデータベースにこれらの値を送信するために、クエリを作成する方法を疑問に思って。すべてのラジオ/チェックフォームの値には私の小売店のテーブルにその列があります。どのようにして$ indexに含まれるすべての値が特定の列に移動するようにクエリを記述しますか?
次は私の他のクエリはあなたが提供することができます任意の洞察力のためのような...
public function addCustomer($data) {
//this is the one I am trying to write, and this one works,
//but I'd have to add every single checkbox/radio name to the
//query, and I have 30!
$this->db->query("INSERT INTO " . DB_PREFIX . "retailer SET buss_t = '" .
(isset($data['buss_t']) ? (int)$data['buss_t'] : 0) .
"', store_sft = '" .
(isset($data['store_sft']) ? (int)$data['store_sft'] : 0) .
"'");
//Ends Here
$this->db->query("INSERT INTO " . DB_PREFIX . "customer SET store_id = '" .
(int)$this->config->get('config_store_id') . "', firstname = '" .
$this->db->escape($data['firstname']) . "', lastname = '" .
$this->db->escape($data['lastname']) . "', email = '" .
$this->db->escape($data['email']) . "', telephone = '" .
$this->db->escape($data['telephone']) . "', fax = '" .
$this->db->escape($data['fax']) . "', password = '" .
$this->db->escape(md5($data['password'])) . "', newsletter = '" .
(isset($data['newsletter']) ? (int)$data['newsletter'] : 0) .
"', customer_group_id = '" .
(int)$this->config->get('config_customer_group_id') .
"', status = '1', date_added = NOW()");
おかげで多くのことをどのように見えるかの例です。
*お使いのコードの出力を見て、「これはうまく書式設定されていますか?」と考えてください。 – jprofitt
@jprofitt何を意味するのかよく分かりませんか?あなたが推薦を持っているなら、私はそれを考慮に入れてうれしいですが、具体的にしてください。ありがとう。 – codekmarv
ほとんどのコードは、1行にスクロールして読み込む必要があり、理解しづらいものでした。私はあなたのサイトでより読みやすくなるように編集しました。 – jprofitt