How can I write this if condition in switch method?
if( $k != 'pg_id' && $k != 'pg_tag' && $k != 'pg_user' )
{
$result = $connection->run_query($sql,array(...));
}
to…?
switch($k)
{
case 'pg_id': false;
case 'pg_tag': false;
case 'pg_user': false;
default:
$result = $connection->run_query($sql,array(...));
}
EDIT:
Sorry I think I didn’t make it clear earlier, below is how I want to use it,
$editable_fields = array(
'pg_id',
'pg_url',
'pg_title',
'pg_subtitle',
'pg_description',
'pg_introduction',
'pg_content_1',
'pg_content_2',
'pg_content_3',
'pg_content_4',
'pg_backdate',
'pg_highlight',
'pg_hide',
'pg_cat_id',
'ps_cat_id',
'parent_id',
'tmp_id',
'usr_id'
);
$sql_pattern = array();
foreach( $editable_fields as $key )
{
if( $key != 'pg_id' && $key != 'pg_tag' && $key != 'pg_user' ) $sql_pattern[] = "$key = ?";
}
as you can see I repeated the condition there –
if( $key != 'pg_id' && $key != 'pg_tag' && $key != 'pg_user' )
and it may grow long at some point.
(Borrowing from a previous question which I believe spawned this one – A short-cut to update a table row in the database?)