PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
//i am assuming all DB connections have been made
$user_query = "SELECT * FROM site_rights WHERE username='$username'";
$table_query = "SHOW FIELDS FROM site_rights";
$user_result = mysql_query($user_query);
$table_result = mysql_query($table_query);
//get the list of fields to check
while ($table = mysql_fetch_array($table_result)) {
//exclude the username field cause we're not checking it
if ($table['Field'] != 'username') {
$fields[] = $table['Field'];
}
}
$user_fields = mysql_fetch_array($user_result);
//loop through each available field
foreach($fields as $key => $field) {
if ($user_fields[$field] != 0) {
//check each fieldname for a non-zero value
$editable_fields[$field] = $user_fields[$field];
print_r($editable_fields);
}
}
?>
It pulls the info properly... but the problem I have is that when it gets the information from a single field in the MySQL db, it resets to the first field, prints it, and then prints the next one.. until it gets through all the fields. L
probably I missed the point but excatly is the problem?
In each iteration of foreach it might add an element to $editable_fields and if so it print_rs the whole resulting array $editable_fields.
foreach($fields as $key => $field) {
if ($user_fields[$field] != 0) {
//check each fieldname for a non-zero value
$editable_fields[$field] = $user_fields[$field];
}
}
print_r($editable_fields);
if ($user_fields[$field] != 0) {
//check each fieldname for a non-zero value
$editable_fields[$field] = $user_fields[$field];
echo $field, ' => ', $editable_fields[$field], "\n";
}