English 中文(简体)
您能否就不同表格提出2个询问,以创建检查箱,并“检查”?
原标题:Can you have 2 queries on different tables to create check boxes and have them "checked"?

我目前正在使用一个表格,使用<条码>how栏,以便把所有栏目纳入核对箱。 下面的法典就是这样做的。 我试图在问询中设定另一个查询权,以寻找一个有相同栏目的不同表格,如果表中的行文有0或1个显示“检查”箱。 之所以使用“单列”查询,是因为各项目总是增加一栏。

/////EDIT after posting I realized that it will be better just to use the same table since the "Columns" represent all the "checkboxes" when output anyway. But the same problem still exists. I am trying to double up on the queries. Query 1 = Extract all columns and create checkboxes Query 2 = use row that matches $newloc and if checkboxes are in specific columns mark out put columns with "Checked" boxes. I have another query on the same page that populated user information which works fine. This page works as a confirmation page which has all user information as well as certain items they have (the Checkboxes) and then they can edit on this page and submit if needed. I want to be clear on all that is in this page just in case that effects this part. One other thing I need to add is since I am using the same table I need to skip the first 3 columns since that is other data that I dont want as columns.

 <?php 
  $conc = new mysqli("127.0.0.1:3306", "root", "", "mydb");
  $res= $conc ->query("SHOW COLUMNS from matmemmatrix");
  
  // this part here is what I was imagining would work
  $sql = "SELECT * FROM matmemmatrix WHERE memid1 =  $uid  AND memlocid =  $newloc ";
  $datam = mysqli_query($conc, $sql);
  $a = 1;
  $row1 = $datam[$a]; // first column ?? 
  //      


  echo "<html>";
  echo "<body>";               
  echo "<table>";
  $i = 0;
  while ($row = $res->fetch_assoc()) {
     $id = $row[ Field ]; 


       // EDIT : check to see if $id matches $row1
     if($id = $row1){
        $checked = 1;
        }else{
        $checked = 0;
        }
        //



     if($i > 5 ){
        $i== 0 ;
    
     if($i== 5 ){
        echo "</tr>";
        echo "<tr>";
        $i = 0 ; 
     ;   
     if ($i == 0  ){
        echo "<tr>";
  };
  echo "<td>";
  echo  <input type ="checkbox"  
                       value=" .htmlspecialchars($id). "  
                           id=" .htmlspecialchars($id). "          
                          name=" .htmlspecialchars( mat[] ). "  
                        checked=  .$checked. >
                        </option> ;
 echo  <label for =" .htmlspecialchars($id). "> .htmlspecialchars($id). </label> ;
 echo "</td>";
 $i++;
 // EDIT Increment next column to see if 0 or 1
 $a++;
//
 }
  echo "</table>";
  echo "</body>";
  echo "</html>";   
?>

我试图利用下文中的询问,以获得“检查”栏。 但失败。

$sql = "SELECT * FROM matmemmatrix WHERE memid1 =  $uid  && memlocid =  $newloc ";

I couldn t get any results from that query to work with the above query.

我试图利用上述询问本身,提取所有栏目作为检查箱使用,并使用1或0的浏览数据作为检查但失败的标志。

能否从这个栏目中提取一栏作为检查箱,并利用浏览数据显示,如果1或0,将进行核对? 我想确保表格中的所有栏目都表明它们是否受到检查。

问题回答

I got this code to work from 2 queries. Needs a little cleaning though.

<?php
$conc = new mysqli("127.0.0.1:3306", "root", "", "database");           
$sqla = "SHOW COLUMNS from matmemmatrix";
$res= mysqli_query($conc, $sqla);
$uid = $_SESSION[  uid  ];
$newloc = $_SESSION[  newloc ];

$sql = "SELECT * FROM matmemmatrix WHERE memid1 =  $uid  AND memlocid =  $newloc ";
$resu = $conc->query($sql);
$datam = $resu->fetch_assoc();
$a = "0";
echo "<html>";
echo "<body>";               
echo "<table>";             
$i = 0;
while ($row = $res->fetch_assoc()) {
$id = $row[ Field ]; //prints column names
$id1 = $rowa[ MatName ]; 
if ($datam[array_keys($datam)[$a]] == "1")
{ $checked = "checked";
}else{
$checked = "";
}
$a++;
if($i > 5 ){
$i== 0 ;
};

if($i== 5 ){
echo "</tr>";
echo "<tr>";      
$i = 0 ;           
};
if ($i == 0  ){
echo "<tr>";
};
echo "<td>";
echo  <input type ="checkbox"  value=" .htmlspecialchars($id). "  id=" .htmlspecialchars($id). "  name=" .htmlspecialchars( mat[] ). "   .$checked. >
</option> ;
echo  <label for =" .htmlspecialchars($id). "> .htmlspecialchars($id). </label> ;
echo "</td>";
$i++;
                  
}   
echo "</table>";
echo "</body>";
echo "</html>";   
$_POST[ access_listb ];
?>




相关问题
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 ...

热门标签