Problem with code execution due to } having to write code multiple times. How to avoid this?

Here is the code for example:

if (
preg_match("/^/", $pere)
) {
$q = "SELECT `opisanie` FROM `daba` where table='' limit 0,2";
$r = mysql_query("$q;") or die("-  .");
while ($r = mysql_fetch_object($re))
print_r($r->opisanie);
}
if (
$a == $b
) {
$q = "SELECT `opisanie` FROM `daba` where table='' limit 0,2";
$r = mysql_query("$q;") or die("-  .");
while ($r = mysql_fetch_object($re))
print_r($r->opisanie);
}

Option:

if (
preg_math("/^/, $pere) &&
$a == $b
)

And option:

if ( ( preg_match("/^/", $pere) ) || ( $a == $b ) ) {
  $sql = "SELECT `opisanie` FROM `daba` where `table`='' limit 0,2;";
  $res = mysql_query($sql) or die("-  .");
  while ( $row = mysql_fetch_object($res) ) echo $row->opisanie;
}

Not suitable.

How to avoid repeating code execution?

UPD: problem resolved, redid code…


Answer 1, authority 100%

Something like this:

if ( ( preg_match("/^/", $pere) ) || ( $a == $b ) ) {
  $sql = "SELECT `opisanie` FROM `daba` where `table`='' limit 0,2;";
  $res = mysql_query($sql) or die("-  .");
  while ( $row = mysql_fetch_object($res) ) echo $row->opisanie;
}

Answer 2

Didn’t it occur to you to simply move the repeating section of code into a separate function?