Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Can you have 2 queries on different tables to create check boxes and have them "checked"?

$
0
0

I am currently using a table that uses a show columns query to echo all the columns into checkboxes. The below code works for that. I tried to create another query right under the query to search a different table that has the same columns and if the row in this table has a 0 or 1 it will show a "checked" box. The reason I use the "show columns" query is because of always adding more columns for items.

<?php       $conc = new mysqli("127.0.0.1:3306", "root", "", "mydb");      $res= $conc ->query("SHOW COLUMNS from matmemmatrix");      echo "<html>";      echo "<body>";                     echo "<table>";      $i = 0;      while ($row = $res->fetch_assoc()) {         $id = $row['Field']; //prints column names         if($i >'5'){            $i=='0';         }else{};         if($i=='5'){            echo "</tr>";            echo "<tr>";            $i ='0';          }else{};            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++;     }      echo "</table>";      echo "</body>";      echo "</html>";   ?>

I tried to use the query below with the one above to get the check box "checked" columns. But failed.

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

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

I tried using this query above by itself to extract all the columns to use as checkboxes and use the row data with a 1 or 0 to mark as checked but failed.

Is it possible to get the columns from this query to use as checkboxes and use the row data to show it checked if 1 or 0? I want to make sure all columns in the table are showing whether or not they are checked.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>