English 中文(简体)
Mysql数据将显示表列中的“Array”数据。
原标题:Mysql data will show "Array" in table column
  • 时间:2012-05-07 04:36:10
  •  标签:
  • php
  • mysql


I want to ask about my php coding..
I am doing some array coding but when I submit my data, in my database is will display an array at the description and qty column..
I use mysql.. Below is my array coding..

$item = array(
 item_description  =>   ,
 price  =>   ,
 qty  =>   ,
 amount  =>   ,
);
foreach ($item as $key => $value){
$item_description = $_POST[ item_description ][$key];
$price = $_POST[ price ][$key];
$qty = $_POST[ qty ][$key];
$amount = $_POST[ amount ][$key];}
}

我插入了疑问。

$sql1="INSERT INTO payment_item (payment_id, payment_item_id, item_description, price, qty, amount)
VALUES
( $last_insert_payment_id , NULL , $_POST[item_description] , $_POST[price] , $_POST[qty] , $_POST[amount] )";

这是我的形式:

<form>
<h1>Payment Item</h1>
Payment ID :<input id="payment_id" name="payment_id" type="text"><br>
<input type="button" value="Add Row" onClick="addRow( tableID )"/>
<input type="button" value="Delete Row" onClick="deleteRow( tableID )"/>
<table class="table" bgcolor="#CCCCCC">
<thead>
<tr>
<td></td>
<td><center>Item Description</center></td>
<td><center>Price (RM)</center></td>
<td><center>Month</center></td>
<td><center>Amount (RM)</center></td>
</tr>
</thead>
<tbody id="tableID">
<tr>
<td><input type="checkbox" name="chk"></td>
<td>
<select name="item_description">
    <option value="deposit">Deposit</option>
    <option value="rental">Rental</option>
    <option value="stamp">Stamp Duty</option>
    <option value="process">Process Fee</option>
    <option value="ap">AP</option>
</select>
</td>
<td><input id="price" name="price" type="text"></td>
<td><input id="month" name="qty" type="text"></td>
<td><input id="amount" name="amount" type="text"></td>
</tr>
</tbody>
</table>
<input name="submit" type="submit" value="Submit">
<input name="reset" type="reset" value="Reset">
</form>

I am sorry for my poor english language..
But I really need any help from someone for this..
Thank you..

问题回答

A word Array appears when PHP is trying to cast an array as a string.
So for the field appeared as Array you have to process it somehow, depends on your application logic, converting whatever array you have to a proper string.

但问题与我的面纱无关。

人们还记得,你必须安排座椅。 至少做到这一点

$var = mysql_real_escape_string($var);

各位对每一变量重新提问,并在问询中总结出。

我不知道您的美元——《社会、文化权利国际公约》。 但我假定你们需要这样做。

<?php 
$item = array(
    item_description  =>   ,
    price  =>   ,
    qty  =>   ,
    amount  =>   ,
);
foreach ($item as $key => &$value)
{
    $value = $_POST[$key];
}
?>

EDIT: You have to specify a form method

<form method="post">

以及最后的INSERT问

$sql1="INSERT INTO payment_item (payment_id, payment_item_id, item_description, price,qty, amount) VALUES ( $last_insert_payment_id , NULL , $item[item_description] , $item[price] , $item[qty] , $item[amount] )";




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签