我想使用php和mysql显示某个货币符号,表名是fund,表行名是symbol。符号必须根据特定行的ID动态更改。如何编写应用程序用户无法更改的位置?基本上符号出现,无法编辑。
如果我需要显示更多代码,请告诉我。
<label>Price</label>
Symbol must display here- example: ($)
<input type="text" name="price" value="<?php value('price'); ?>" />
我的错误部分:
<?php
$errors = array();
if(isset($_POST['submit'])) { //Check for postback
if($_POST['price'] == '')
$errors['price'] = 'Please enter a price.';
if($_POST['date'] == '')
$errors['date'] = 'Please enter a date.';
if(count($errors) == 0){
//edit funds
$sql = "UPDATE funds SET price='" . $_POST['price'] .
"', date='" . $_POST['date'] . "' WHERE id = " . $_GET['id'];
query($sql);
set_flashdata('success', 'Fund updated');
redirect('index.php');
}
} else {
$id = $_GET['id'];
$sql = 'SELECT * FROM funds WHERE id = ' . $id;
$results = query($sql);
$_POST['price'] = $results[0]['price'];
$_POST['date'] = $results[0]['date'];
}
?>
答案 0 :(得分:0)
<?php
function chk_symbol($id)
{
global $sym;
$array_symbol=array("$","@","%","#");
$c=count($array_symbol);
$i=0;
for($i;$i<$c;$i++)
{
if($id==$i)
{
$sym=$array_symbol[$i];
}
}
}
//call function which set a value of variable $sym and echo it wherever you want
chk_symbol(0);
echo $sym;
?>