Jump to content

Strange Function problem


Mutley

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>   ";
}
//
?>

 

???

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.