<?php
$connect = mysqli_connect("localhost","root", "","nets") or die("Couldn't connect to database");
$query = mysqli_query($connect,"SHOW columns FROM users");
while($row = $query->fetch_assoc()) {
if( (strcmp($row['Field'],"Name") !== 0) ||
(strcmp($row['Field'],"ID") !== 0)||
(strcmp($row['Field'],"Password") !== 0)||
(strcmp($row['Field'],"Email") !== 0)||
(strcmp($row['Field'],"Company") !== 0)||
(strcmp($row['Field'],"Gender") !== 0)||
(strcmp($row['Field'],"Citizen") !== 0)){
?>
<input type="radio" name="admin" value="'$row'">
<?php
echo $row['Field'];
}
?>
<br/>
<?php
}
?>
Please suggest how to skip the "Name", "ID", "Password", "Email", "Company", "Gender", "Citizen" rows and print the rest of them.
Instead of fetching all columns and applying PHP if condition, it will be better if you fetch only the required columns.
Try this query:
SHOW columns FROM users WHERE field NOT IN ('Name', 'ID', 'Password', 'Email', 'Company', 'Gender', 'Citizen')
If you don't want to modify your code too much, then I think you just have to change ||
to &&
because your code will currently print a radio button if even one field doesn't match.
Like this:
<?php
$connect = mysqli_connect("localhost","root", "","nets") or die("Couldn't connect to database");
$query = mysqli_query($connect,"SHOW columns FROM users");
while($row = $query->fetch_assoc()) {
if( (strcmp($row['Field'],"Name") !== 0) &&
(strcmp($row['Field'],"ID") !== 0) &&
(strcmp($row['Field'],"Password") !== 0) &&
(strcmp($row['Field'],"Email") !== 0) &&
(strcmp($row['Field'],"Company") !== 0) &&
(strcmp($row['Field'],"Gender") !== 0) &&
(strcmp($row['Field'],"Citizen") !== 0)){
?>
<input type="radio" name="admin" value="'$row'">
<?php
echo $row['Field'];
}
?>
<br/>
<?php
}
?>