The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving Languages to Database
#8
So, this would be if each line of the db is an entire language... To generate the form... Note that you can pass in an array of columns you don't want to show (such as id)

Code:
function generateForm($table,$id, $skip=[]){
Code:
$db = DB::getInstance();
Code:
$fields = [];
Code:
$q=$db->query("SELECT * FROM {$table} WHERE id = ?",array($id));
Code:
$r=$q->first();

Code:
foreach($r as $field => $value) {
Code:
if(!in_array($field, $skip)){
Code:
echo '<div class="form-group">';
Code:
echo '<label for="'.$field.'">'.ucfirst($field).'</label>';
Code:
echo '<input type="text" class="form-control" name="'.$field.'" id="'.$field.'" value="'.$value.'">';
Code:
echo '</div>';
Code:
}
Code:
}
Code:
return true;
Code:
}
Here's the usage...

$t = 'language';
$skip = ['id'];
generateForm($t,$id,$skip);


And here's how you update...
Code:
function updateFields2($post, $skip=[]){
Code:
$fields = [];
Code:
foreach($post as $field => $value) {
Code:
if(!in_array($field, $skip)){
Code:
$fields[$field] = sanitize($post[$field]);
Code:
}
Code:
}
Code:
return $fields;
Code:
}

Here's the usage...
Code:
$skipFields = [];
Code:
$updateFields = updateFields2($_POST, $skipFields);
Code:
$db->update('language',1,$updateFields);
  Reply


Messages In This Thread
Moving Languages to Database - by Brandin - 11-26-2016, 08:22 PM
Moving Languages to Database - by mudmin - 11-26-2016, 08:46 PM
Moving Languages to Database - by Brandin - 11-26-2016, 10:23 PM
Moving Languages to Database - by winterswolf - 11-29-2016, 06:25 AM
Moving Languages to Database - by Brandin - 11-29-2016, 01:09 PM
Moving Languages to Database - by mudmin - 11-29-2016, 02:02 PM
Moving Languages to Database - by Brandin - 11-29-2016, 02:03 PM
Moving Languages to Database - by mudmin - 11-29-2016, 02:09 PM
Moving Languages to Database - by mudmin - 11-29-2016, 02:12 PM
Moving Languages to Database - by Brandin - 11-29-2016, 02:14 PM
Moving Languages to Database - by mudmin - 11-29-2016, 02:24 PM
Moving Languages to Database - by Brandin - 11-29-2016, 03:17 PM
Moving Languages to Database - by mudmin - 11-29-2016, 03:19 PM
Moving Languages to Database - by Brandin - 02-05-2017, 02:59 PM
Moving Languages to Database - by Brandin - 02-11-2017, 05:09 PM
Moving Languages to Database - by mudmin - 02-11-2017, 10:30 PM
Moving Languages to Database - by Brandin - 02-12-2017, 08:33 PM
Moving Languages to Database - by Brandin - 02-13-2017, 03:02 AM
Moving Languages to Database - by Brandin - 02-13-2017, 03:17 AM
Moving Languages to Database - by Brandin - 07-18-2017, 12:41 AM
Moving Languages to Database - by firestorm - 07-19-2017, 07:17 AM
Moving Languages to Database - by Brandin - 07-19-2017, 12:07 PM
Moving Languages to Database - by karsen - 07-21-2017, 06:39 PM
Moving Languages to Database - by firestorm - 07-21-2017, 07:08 PM
Moving Languages to Database - by Brandin - 07-22-2017, 10:08 PM
Moving Languages to Database - by karsen - 07-22-2017, 11:41 PM
Moving Languages to Database - by Brandin - 07-23-2017, 05:46 PM
Moving Languages to Database - by firestorm - 07-23-2017, 09:26 PM
Moving Languages to Database - by Brandin - 07-24-2017, 12:17 AM

Forum Jump:


Users browsing this thread: 11 Guest(s)