Jump to content

Recommended Posts

I have a functions.php, which works fine until I add this function to the bottom of the file:

 

function pageMe($p,$no_of_page,$page_name,$no_rows,$list){
if($p==0 || $p==1){$x=1;}else{$x=($p-1)*$list;}
$y=$x+$list; 
if($y>$no_rows){$y=$no_rows;} 
//if($x==1){$y=$list;} 
if($y<=$list){$y=$no_rows;}
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
	<td class="graytext1"><? //print "Displaying <b>".$x."</b> to <b>".$y." </b>of <b>".$no_rows."</b> "; ?> </td>
	<td class="graytext1">
	<div align="right">

		<!--//---first----->
		 <a href="<?=$page_name?>?p=1" >First</a> <?
		//-------------
		if($no_of_page>5)
		{
			//------ for next and previous -----
			if($p==0){$p=1;}

			$prev=$p-1;
			$next=$p+1;

			//---previous---
			?>  <a href="<?=$page_name?>?p=<?=$prev?>" >Prev</a>   <?
			//-------------
			for($i=$p;$i<=($next+3);$i++)
			{ 
				if($i==($no_of_page+1)){ break;}
				if($p==$i)
				{
				 print "<u><b>".$i."</b></u>";
				}
				else
				{
				?>
					<a href="<?=$page_name?>?p=<?=$i?>" ><?=$i?></a>
				<?
				}
			}

			//---next---
			if($p<$no_of_page){?>   <a href="<?=$page_name?>?p=<?=$next?>" > Next</a>  <? }

			//-----------
		}
		else
		{//----------if pages less than 5
			for($i=1;$i<=$no_of_page;$i++)
			{ 
				if($p==$i)
				{
				 print "<u><b>".$i."</b></u>";
				}
				else
				{
				?>
					<a href="<?=$page_name?>?p=<?=$i?>" ><?=$i?></a>
				<?
				}
			}
		}

		//---last---
		?>  <a href="<?=$page_name?>?p=<?=$no_of_page?>" >Last</a>   
	</div>
	</td>  
 </tr>
</table>
<?
}?>

 

Then I get the error:

Parse error: syntax error, unexpected '}' in /home/graphics/public_html/clients/stp/inc/functions.php on line 1

 

But there is no broken brackets, the other functions work flawlessly when the above function isn't in the file.

 

I don't get it, there isn't even a bracket on line 1.

 

The rest of my functions.php is:

<?php 
require_once('inc/config.php');
$connection = mysql_connect($host, $user, $pwd) or die("&error1=".mysql_error());
mysql_select_db($db, $connection);

function level($id){
$res=mysql_query("SELECT `level` FROM `users` WHERE `id` = '$id'");
while($row=mysql_fetch_array($res)){
	return $row["level"];
}
}

function getCat($cat){
$res=mysql_query("SELECT `name` FROM `categories` WHERE `id` = '$cat'");
while($row=mysql_fetch_array($res)){
	return $row["name"];
}
}

function all_news($catid){
$val=0;
$sql_f="SELECT id, cat, date, title, content FROM news ORDER BY date DESC";
$res_f=mysql_query($sql_f);
$no_f=mysql_num_rows($res_f);
$val=$no_f;
return $val;
}

 

Config.php is just a list of variables for the database details.

 

Any ideas?

 

Thanks in advance,

Nick.

Link to comment
https://forums.phpfreaks.com/topic/135134-strange-function-problem/
Share on other sites

so it it looks like this do u still have problems?

 

<?php

require_once('inc/config.php');

$connection = mysql_connect($host, $user, $pwd) or die("&error1=".mysql_error());

mysql_select_db($db, $connection);

 

function level($id){

  $res=mysql_query("SELECT `level` FROM `users` WHERE `id` = '$id'");

  while($row=mysql_fetch_array($res)){

      return $row["level"];

  }

}

 

function getCat($cat){

  $res=mysql_query("SELECT `name` FROM `categories` WHERE `id` = '$cat'");

  while($row=mysql_fetch_array($res)){

      return $row["name"];

  }

}

 

function pageMe($p,$no_of_page,$page_name,$no_rows,$list){

if($p==0 || $p==1){$x=1;}else{$x=($p-1)*$list;}

$y=$x+$list;

if($y>$no_rows){$y=$no_rows;}

//if($x==1){$y=$list;}

if($y<=$list){$y=$no_rows;}

?>

<table width="100%" cellpadding="0" cellspacing="0" border="0">

  <tr>

      <td class="graytext1"><? //print "Displaying <b>".$x."</b> to <b>".$y." </b>of <b>".$no_rows."</b> "; ?> </td>

      <td class="graytext1">

      <div align="right">

     

        <!--//---first----->

          <a href="<?=$page_name?>?p=1" >First</a> <?

        //-------------

        if($no_of_page>5)

        {

            //------ for next and previous -----

            if($p==0){$p=1;}

           

            $prev=$p-1;

            $next=$p+1;

           

            //---previous---

            ?>  <a href="<?=$page_name?>?p=<?=$prev?>" >Prev</a>   <?

            //-------------

            for($i=$p;$i<=($next+3);$i++)

            {

              if($i==($no_of_page+1)){ break;}

              if($p==$i)

              {

                print "<u><b>".$i."</b></u>";

              }

              else

              {

              ?>

                  <a href="<?=$page_name?>?p=<?=$i?>" ><?=$i?></a>

              <?

              }

            }

           

            //---next---

            if($p<$no_of_page){?>   <a href="<?=$page_name?>?p=<?=$next?>" > Next</a>  <? }

           

            //-----------

        }

        else

        {//----------if pages less than 5

            for($i=1;$i<=$no_of_page;$i++)

            {

              if($p==$i)

              {

                print "<u><b>".$i."</b></u>";

              }

              else

              {

              ?>

                  <a href="<?=$page_name?>?p=<?=$i?>" ><?=$i?></a>

              <?

              }

            }

        }

       

        //---last---

        ?>  <a href="<?=$page_name?>?p=<?=$no_of_page?>" >Last</a>   

      </div>

      </td>

    </tr>

</table>

<?

}?>

I can't remember if this will make a difference or not but just try it, replace your PageMe function with this...

 

function pageMe($p,$no_of_page,$page_name,$no_rows,$list){
if($p==0 || $p==1){
	$x=1;
}else{
	$x=($p-1)*$list;
}
$y=$x+$list;
if($y>$no_rows){
$y=$no_rows;
}
//if($x==1){$y=$list;}
if($y<=$list){
$y=$no_rows;
}
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
   <tr>
      <td class="graytext1"><? //print "Displaying <b>".$x."</b> to <b>".$y." </b>of <b>".$no_rows."</b> "; ?> </td>
      <td class="graytext1">
      <div align="right">
      
         <!--//---first----->
          <a href="<?=$page_name?>?p=1" >First</a> <?
         //-------------
         if($no_of_page>5)
         {
            //------ for next and previous -----
            if($p==0){$p=1;}
            
            $prev=$p-1;
            $next=$p+1;
            
            //---previous---
            ?>  <a href="<?=$page_name?>?p=<?=$prev?>" >Prev</a>   <?
            //-------------
            for($i=$p;$i<=($next+3);$i++)
            {
               if($i==($no_of_page+1))
			{
				break;
			}
               if($p==$i)
               {
                print "<u><b>".$i."</b></u>";
               }
               else
               {
               ?>
                  <a href="<?=$page_name?>?p=<?=$i?>" ><?=$i?></a>
               <?
               }
            }
            
            //---next---
            if($p<$no_of_page){
			?>   <a href="<?=$page_name?>?p=<?=$next?>" > Next</a>  <?
		}
            
            //-----------
         }
         else
         {//----------if pages less than 5
            for($i=1;$i<=$no_of_page;$i++)
            {
               if($p==$i)
               {
                print "<u><b>".$i."</b></u>";
               }
			else
               {
               ?>
                  <a href="<?=$page_name?>?p=<?=$i?>" ><?=$i?></a>
               <?
               }
            }
         }
         
         //---last---
         ?>  <a href="<?=$page_name?>?p=<?=$no_of_page?>" >Last</a>   
      </div>
      </td> 
    </tr>
</table>
<?
}?>

I've altered the function a little, just cleaning the code up and now get an $end error, however there is no broken brackets... as I have said it works fine without the pageMe() function?

 

Parse error: syntax error, unexpected $end in /home/graphics/public_html/clients/stp/inc/functions.php on line 1

 

Full file (functions.php):

 

<?php 
require_once('inc/config.php');
$connection = mysql_connect($host, $user, $pwd) or die("&error1=".mysql_error());
mysql_select_db($db, $connection);

function level($id){
   $res=mysql_query("SELECT `level` FROM `users` WHERE `id` = '$id'");
   while($row=mysql_fetch_array($res)){
      return $row["level"];
   }
}
function username($id){
   $res=mysql_query("SELECT `username` FROM `users` WHERE `id` = '$id'");
   while($row=mysql_fetch_array($res)){
      return $row["username"];
   }
}
function getCat($cat){
   $res=mysql_query("SELECT `name` FROM `categories` WHERE `id` = '$cat'");
   while($row=mysql_fetch_array($res)){
      return $row["name"];
   }
}

function pageMe($p,$no_of_page,$page_name,$no_rows,$list){
if($p==0 || $p==1){$x=1;}else{$x=($p-1)*$list;}
$y=$x+$list;
if($y>$no_rows){$y=$no_rows;}
//if($x==1){$y=$list;} 
if($y<=$list){$y=$no_rows;}
//---first----->
echo "<a href='$page_name?p=1'>First</a> ";

	if($no_of_page>5)
	{
		//------ for next and previous -----
		if($p==0){$p=1;}
		$prev=$p-1;
		$next=$p+1;
		//---previous---
		echo "<a href='$page_name?p=$prev'>Prev</a>   ";
		//-------------
		for($i=$p;$i<=($next+3);$i++)
		{
			if($i==($no_of_page+1)){ break;}
			if($p==$i){
			print "<u><b>".$i."</b></u>";
			}else{
			echo "<a href='$page_name'?p=$i'>$i</a>";
			}
		}
		//---next---
		if($p<$no_of_page){ echo "  <a href='$page_name?p=$next'> Next</a> ";}
		//-----------
	}else{
//----------if pages less than 5
		for($i=1;$i<=$no_of_page;$i++){
			if($p==$i){
				print "<u><b>".$i."</b></u>";
			}else{
				echo "<a href='$page_name?p=$i'>$i</a>";
			}
		}
	}
//---last---
echo " <a href='$page_name?p=$no_of_page'>Last</a>   ";
}
//
?>

 

???

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.