Jump to content

Recommended Posts

Posted

Right now I have some queries in a block that will throw an error when it looks up a record and it has been deleted. This screws up the whole page instead of just skipping the record.

Is there a way to check the table for the record before doing this in order to skip the record?

Here is my code

{{$wDB  = \IPS\Db::i()->select( 'field_48, field_51, field_59, field_52, field_450, field_522', 'cms_custom_database_9', array( 'primary_id_field=?', $wID) )->first();}}

I know that the error I receive is for past entries where I deleted records that it is looking for.

Any help on how to not throw an error and just go on it's merry way would be appreciated.

Posted

Use try/catch for your query:

{{try{ $wDB  = \IPS\Db::i()->select( 'field_48, field_51, field_59, field_52, field_450, field_522', 'cms_custom_database_9', array( 'primary_id_field=?', $wID) )->first();}catch( \UnderflowException $e ){ $wDB = NULL; } }}
	{{if $wDB}}
		Record was found, do something with it.
	{{endif}}

 

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...