English 中文(简体)
我如何从数据库和产出中获取所有价值,作为检查箱工作? (PHP/Mysql)
原标题:How do I get this php statement that gets all the values from database and outputs as checkboxes to work? (PHP/Mysql)
  • 时间:2010-04-12 16:44:45
  •  标签:
  • php

I am a bit lost in all these "" and and . in this statement. Basically this query is to get all the tagname from table "tag" and display them for the users as checkboxes. If they have clicked submit and they missed another field(say the title of a post), it would still have the tag they chose displayed. The part I need help with is the echoing part. It doesn t seem to remember the tag when they click submit.

      $query4 = "SELECT * FROM tags  ORDER BY tagname";
  $data4 = mysqli_query($dbc, $query4);
  while ($row4 = mysqli_fetch_array($data4)) 
  {
  echo "<li><input type= checkbox  name= postingtag[] ";
  if (!empty($postingtag)){
   echo "value= $postingtag ";
  }
  else{
   echo "value= {$row4[ tagID ]} ";
  }
  echo ">{$row4[ tagname ]}</li>";
  }
最佳回答

为此:

$query4 = "SELECT * FROM tags  ORDER BY tagname";
$data4 = mysqli_query($dbc, $query4);
while ($row4 = mysqli_fetch_array($data4)) {

 echo "<li><input type= checkbox  name= postingtag[{$row4[ tagID ]}]  value= 1 ";

 if (isset($postingtag[$row4[ tagID ]]))
  echo " checked= checked ";

 echo "/> {$row4[ tagname ]}</li>";
}

<代码>postingtag将是一个阵列,配有已经检查的标签。 在<代码>postingtag阵列中添加一个可识别的索引,就可以检查其是否有人居住,然后可以据此确定核实的属性。

问题回答

为了确定用户是否对提交表格的某些检查箱进行检查,你需要测试是否提交了检查箱。 你们看到,浏览器只有在检查时才会寄出检查箱的价值,否则就得不到任何东西。 因此,为了检验这一点,你需要一种办法,在所提交的参数中独一无二地确定这一检查箱。 在本案中(以及大多数其他(如果不是其他所有)最可靠的办法是将独一无二的标签作为检查箱名称的关键,例如:

... <li><input type="checkbox" name="postingtag[  . $row4[  tagID  ] .  ]" ...

之后,在提交检验中:

$checked = isset( $_POST[  postingtag  ][ $row4[  tagID  ] ] ) ?   checked="checked"  :   ;

将所有的人聚集在一起,就象:

$checked = isset( $_POST[  postingtag  ][ $row4[  tagID  ] ] ) ?   checked="checked"  :   ;
$checkbox =  <li><input type="checkbox" name="postingtag[  . $row4[  tagID  ] .  ]"  . $checked .  >  . $row4[ tagname ] .  </li> ;




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

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 = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签