Mutley Posted December 2, 2008 Share Posted December 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/ Share on other sites More sharing options...
jake2891 Posted December 2, 2008 Share Posted December 2, 2008 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> <? }?> Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/#findComment-703854 Share on other sites More sharing options...
Mutley Posted December 2, 2008 Author Share Posted December 2, 2008 Yep, I get the error at Line 1 but if I take that PageMe function out... all works fine however, to make it even more confusing, I can use that function on another page fine as long as its not in the functions.php. Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/#findComment-703867 Share on other sites More sharing options...
Mutley Posted December 3, 2008 Author Share Posted December 3, 2008 Any ideas? Still having issues. Thanks, Nick. Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/#findComment-704771 Share on other sites More sharing options...
GKWelding Posted December 3, 2008 Share Posted December 3, 2008 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> <? }?> Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/#findComment-704786 Share on other sites More sharing options...
Mutley Posted December 3, 2008 Author Share Posted December 3, 2008 Nope, still doesn't work. Makes no sense, even on pages it doesn't use the function it brings the same error on line 1 up. Bizarre. Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/#findComment-704948 Share on other sites More sharing options...
Mutley Posted December 3, 2008 Author Share Posted December 3, 2008 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> "; } // ?> ??? Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/#findComment-705039 Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 Your error is in the config.php file. Post that or look through it to see possible errors. Chances are it is missing a } or ; from the sounds of it. Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/#findComment-705049 Share on other sites More sharing options...
Mutley Posted December 3, 2008 Author Share Posted December 3, 2008 <?php $host = "localhost"; $user = "username"; $pwd = "password"; $db = "database"; Seems fine. Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/#findComment-705059 Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 <?php $host = "localhost"; $user = "username"; $pwd = "password"; $db = "database"; ?> You are missing the end ?> which in return causes the $end error. Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/#findComment-705069 Share on other sites More sharing options...
Mutley Posted December 3, 2008 Author Share Posted December 3, 2008 Doesn't make a difference, I've had it with and without. I've even put those variables into the functions.php instead of in the config.php Quote Link to comment https://forums.phpfreaks.com/topic/135134-strange-function-problem/#findComment-705070 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.