0

I want to call a function printPager($max_pages,$pg); to show up after the last value in the table. I've failed with inserting exit() and end().

<?php
function catPosts($id) {
    $id = (int) $id;
    $pgsize=2;
    $pg=(is_numeric($_GET["p"]) ? $_GET["p"] : 1);
    $start=($pg-1)*$pgsize;
    $img_total=mysql_query("SELECT COUNT(1) FROM posts WHERE SubcategoryID = '$id'");
    $img_total=mysql_fetch_row($img_total);
    $img_total=$img_total[0];
    $max_pages=$img_total / $pgsize; 
    $max_pages=ceil($img_total/$pgsize);
    $query = mysql_query("SELECT * FROM posts WHERE SubcategoryID = '$id' LIMIT $start, $pgsize");
    while($post = mysql_fetch_array($query)) {      
        echo "<tr><td><h2><a href=\"viewArticle.php?id=" . $post['ID'] . "\">" . $post['Title'] . "</a> by " . $post['Author'] .  "</h2></td></tr><tr><td colspan=\"2\">" . $post['Summary'] . "</td><td>"  . $post['Date'] . "</td></tr>";
        echo exit($query);
        printPager($max_pages,$pg);
    }
}
?>

1 Answer 1

1

Since php is a synchronous language, not async like javascript, you can easily return or call the next function after your while-block.

while($post = mysql_fetch_array($query)) {
     echo "<tr><td><h2><a href=\"viewArticle.php?id=" . $post['ID'] . "\">" . $post['Title'] . "</a> by " . $post['Author'] .  "</h2></td></tr><tr><td colspan=\"2\">" . $post['Summary'] . "</td><td>"  . $post['Date'] . "</td></tr>";
     //not working here    
     //echo exit($query);
}
printPager($max_pages,$pg);

The function exit will exit your entire php-runtime.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, moe. I've tried it and it wouldn't work. The problem's appeared to be in <table> tags in my html - once I removed them, everything worked. Anyhow I've solved it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.