Echo <a href>

Good day!

I want to know if how can I edit my code to echo my <a href>

here is my <a href> code


<a href="machine1.php?pageno=1&field_name=<?php echo $data_sort; ?>&sorting=<?php echo $sort; ?>">FIRST</a>
<a href="machine1.php?pageno=<?php echo $prevpage;?>&field_name=<?php echo $data_sort; ?>&sorting=<?php echo $sort; ?>">PREV</a>
 

Thank you so much

Does the current implementation not work? If not, why not?

my colleagues gave me an example of the link of page:


$paging = '<a href="?page=1">First</a> | ';
$paging .= '<a href="?page=1">Next</a> ';
$paging .= 'Page 1 of 5 ';
$paging .= '<a href="?page=1">Previous</a> | ';
$paging .= '<a href="?page=5">Last</a>';

$tpl->set_var(array('pagination' => $paging,
));

then he puts {pagination} in his html code

but in my case I have an if and else condition, so I tried this code.and I encountered problem.


if ($pageno == 1) {
   echo " FIRST PREV ";
} else {
 $myLink = ' <a href="machine1.php?pageno=1&field_name='.$data_sort.'&sorting='.$sort.'">FIRST</a>';
   $prevpage = $pageno-1;
 $myLink .= ' <a href="machine1.php?pageno='.$prevpage.'&field_name='.$data_sort.'&sorting='.$sort.'">PREV</a>';
}
 $paging = 'Page $pageno of $lastpage ';
//echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
   echo " NEXT LAST ";
} else {
  $nextpage = $pageno+1;
  $pagination2 .= ' <a href="machine1.php?pageno='.$nextpage.'&field_name='.$data_sort.'&sorting='.$sort.'">NEXT</a>';
  $pagination2 .= ' <a href="machine1.php?pageno='.$lastpage.'&field_name='.$data_sort.'&sorting='.$sort.'">LAST</a>';
}

and I set_var


$tpl->set_var(array('pagination' => '$myLink',
					'paging' => '$paging',
					'pagination2' => '$pagination2'
));


and i add in my html this code:


{pagination} {paging} {pagination2}

and the output is:
$myLink FIRST PREV

whats wrong with my code?

Apparently nothing. :cool:

However, this looks suspicious.


$tpl->set_var(array('pagination' => '$myLink',
                    'paging' => '$paging',
                    'pagination2' => '$pagination2'
));

Try changing it to:-


<?php
$tpl->set_var(array(
  'pagination'  => $myLink,
  'paging'      => $paging,
  'pagination2' => $pagination2
));

I tried your suggestion and the output is FIRST PREV the $myLink was gone.

Ask your collegues?

If $myLink disappeared, it means that $myLink was never assigned a value.

Looking over your code, it doesn’t really make sense. It looks like there are some major gaps which are hiding some of the pieces we need to help with this. For example, I never see where set_var is used… just where you explained what you set it to. Are you using some sort of framework?

This is my whole code for better understanding


<?php
session_start(); 
if(empty($_SESSION['logged_in'])) {
    header('Location:index.php');
    die();
}

error_reporting(E_ERROR | E_WARNING | E_PARSE);
include('includes/config.sender.php');
include('includes/template.inc');

 $id=$_GET['id'];
 

/*Sorting of Data*/
 $sort = "ASC";
  $data_sort = "Emp_ID";
  
  if(isset($_GET['sorting']))
	{
		if($_GET['sorting'] == 'ASC'){
			$sort = "DESC";
		}
		else{
			$sort = "ASC";
		}
	}

	if (isset($_GET['field_name'])) {
		if($_GET['field_name']  == 'Emp_ID'){
			$data_sort = "Emp_ID";
		}
		elseif($_GET['field_name'] == 'Last_Name'){
			$data_sort = "Last_Name";
		}
		elseif($_GET['field_name'] == 'First_Name'){
			$data_sort = "First_Name";
		}
		elseif($_GET['field_name'] == 'Birthday'){
			$data_sort = "Birthday";
		}
	}


	
	
/*Pagination, Sorting and Limit*/

if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} else {
   $pageno = 1;
} 


$sql_select = "SELECT COUNT(*) as numrows 
                FROM  
                    machine_problem_rhoda"; 
$result = $_DB->opendb($sql_select); 

if(isset($result[0]['numrows'])) 
{
   $numrows = (int)$result[0]['numrows']; 
}
else
{
   $numrows = 0; 
}

$rows_per_page = 5;
$lastpage      = ceil($numrows/$rows_per_page);

$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
} 
if ($pageno < 1) {
   $pageno = 1;
} 

$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;

$sql_select = "SELECT
					Emp_ID,
					Last_Name,
					First_Name,
					Birthday
				FROM
					machine_problem_rhoda
				ORDER BY $data_sort $sort $limit
				";
$rows = $_DB->opendb($sql_select);


$tpl = new Template('.', 'keep');
$tpl->set_file(array('handle' => 'html/machine1.html'));


$tpl->set_block('handle', 'block_list', 'tag_list');
foreach($rows as $row) {
	$tpl->set_var(array('emp_id'=> $row['Emp_ID'],
						'lastname' => htmlentities($row['Last_Name']),
						'firstname' => htmlentities($row['First_Name']),
						'birthday' => htmlentities(date('d-m-Y', strtotime($row['Birthday']))),
						'sorting' => $sort,
						'id' => $row['Emp_ID']
	));
	
	$tpl->parse('tag_list', 'block_list', true);
}

$tpl->set_var(array('pagination' => $myLink,
					'paging' => $paging,
					'pagination2' => $pagination2
));

$tpl->parse('handle', array('handle'));
$tpl->p('handle');

 if(isset($_GET['sorting']))
	{
		if($_GET['sorting'] == 'ASC'){
			$sort = "ASC";
		}
		else{
			$sort = "DESC";
		}
	}
				
if ($pageno == 1) {
   echo " FIRST PREV ";
} else {
 $myLink = '<a href="machine1.php?pageno=1&field_name='.$data_sort.'&sorting='.$sort.'">FIRST</a>';
   $prevpage = $pageno-1;
 $myLink .= '<a href="machine1.php?pageno='.$prevpage.'&field_name='.$data_sort.'&sorting='.$sort.'">PREV</a>';
}
 $paging = 'Page '.$pageno.' of '.$lastpage.' ';
//echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
   echo " NEXT LAST ";
} else {
  $nextpage = $pageno+1;
  $pagination2 = '<a href="machine1.php?pageno='.$nextpage.'&field_name='.$data_sort.'&sorting='.$sort.'">NEXT</a>';
  $pagination2 .= '<a href="machine1.php?pageno='.$lastpage.'&field_name='.$data_sort.'&sorting='.$sort.'">LAST</a>';
}
?>

Thank you

Yes he is. It’s a framework used by his company, as he explained in another post.

It looks to me like the OP has been programming in his own style, and now he has to adapt to the company style, using the framework and several standard classes, functions, ways of programming.

Rhodarose, instead of trying to bend the framework to your way of coding, what you should do (IMO), is learn how that framework works. Study the documentation (I’m sure your company has documentation about their framework and their way of coding?), study your collegues code, ask them for explanation, and then start writing your code the company way.
Don’t try to fix your existing code. I think it would be easier to take an existing script and change that so it does what you need.

Thank you…I resolved my problem by inputting set_var below of the condition for paging…

He also needs to acknowledge and reply to questions people ask him too. Mind you, from yesterdays problem he can’t tell the difference between $sel_select and $result so I have to question whether he is capable of reading documentation or not.

He never replied to yesterdays problem saying he’d fixed it so i can only assume its still outstanding yet he doesn’t reply to those requests for further information.

Sorry for what happened yesterday:(