PDA

View Full Version : echo <a href>



newphpbees
12 May 2011, 02:10 AM
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
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?

Alan
12 May 2011, 06:43 PM
I've only glanced at your code, but there was an obvious problem.

Single quotes are literal strings. You should use expanded strings (double quotes) if you want variables to expand within a string. Although, in this case you don't need string delimiters at all; and using them would add an unnecessary extra process.



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