tonyalepski Posted August 25, 2014 Share Posted August 25, 2014 Hi, I am trying to convert a php function into perl and need to understand the following line in red : function pagination($query, $per_page = 10,$page = 1, $url = '?'){ $query = "SELECT COUNT(*) as `num` FROM {$query}"; $row = mysql_fetch_array(mysql_query($query)); $total = $row['num']; $adjacents = "2"; $page = ($page == 0 ? 1 : $page); $start = ($page - 1) * $per_page; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total/$per_page); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1) { ......................................... What will be the output of this line above in red. Thank you very much. Regards. Tonya Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 25, 2014 Share Posted August 25, 2014 It's the ternary operator. Perl has it as well. The expression $c ? $r_1 : $r_2 yields the value of $r_1 if $c evaluates to true, otherwise it yields the value of $r_2. Quote Link to comment Share on other sites More sharing options...
tonyalepski Posted August 25, 2014 Author Share Posted August 25, 2014 Thank you Jacques, Another one : for ($counter = 1; $counter <= $lastpage; $counter++); what will be equivalent for it in perl as I am getting errors on it Many thanks !! Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 25, 2014 Share Posted August 25, 2014 What errors? This is a plain for loop which is one of the basic features of virtually every language. No offense, but if you know neither PHP nor Perl nor the basics of programming, this task will be tough. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 25, 2014 Share Posted August 25, 2014 What errors are you getting on that line? BTW - there is a semi at the end of the line - doesn't belong there. Quote Link to comment Share on other sites More sharing options...
davidannis Posted August 25, 2014 Share Posted August 25, 2014 (edited) An example might look like this: $lastpage=3; for ($counter = 1; $counter <= $lastpage; $counter++){ echo "We're on page $counter <br>"; } echo "done"; which would output We're on page 1 We're on page 2 We're on page 3 done Edited August 25, 2014 by davidannis Quote Link to comment 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.