-5

when i run this code it give error unexpected else please suggest mi how to write it i am confused with open and close bracket

     <?php
     } 

     for ($i = $start_loop; $i <= $end_loop; $i++) 
     {

    //if ($cur_page == $i)
    if($i != $page)?>

     <a href="javascript:callonce_search( <?php echo $i?>,'<?php echo        $txt?>')"> $i </a>



  <?php 
    else
      echo " <a class='paginationcurrnt'><b> $i</b>";
     }


    // TO ENABLE THE NEXT BUTTON
   if ($next_btn && $cur_page < $no_of_paginations) 
    {
    $nex = $cur_page + 1; ?>

2 Answers2

0

Curly braces are your friend when you want to explicitly define code blocks:

if($i != $page) { ?>
    <a href="javascript:callonce_search( <?php echo $i?>,'<?php echo        $txt?>')"> $i </a>
<?php 
} else {
    echo " <a class='paginationcurrnt'><b> $i</b>";
}

Sometimes, in the case of single-line code blocks, you can get away with not using them. But when mixing code with markup like this, the concept of "a line of code" becomes pretty effectively blurred. In that case, always explicitly use curly braces.

David
  • 208,112
  • 36
  • 198
  • 279
0

This is very poorly written code. The syntax error is because your else comes out of nowhere. This is the format for if/else statements:

if(condition){
    //if condition is true
} else {
    //if condition is false
}

This is yours:

if(condition)
else
}

So change the if/else to:

if($i != $page) { ?>
    <a href="javascript:callonce_search( <?php echo $i?>,'<?php echo $txt ?>')"> $i </a>
<?php } else {
    echo " <a class='paginationcurrnt'><b> $i</b>";
}
Ben
  • 8,894
  • 7
  • 44
  • 80