Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/AJAX posts limit per page
    primarykey
    data
    text
    <p>so I started developing a blog for myself, and I came to the first setback. I want to replace the posts that this function returns with ajax with the next 10. I know javascript quite well but I don't know so much about ajax (all I know that it sends a request to the server where the results are posted back, and then you can replace the data with the new data on your site)</p> <pre><code>function get_posts($i = 0,$max = 10) { global $con; $query = 'SELECT * FROM post'; $result = mysqli_query($con, $query); $rows = mysqli_num_rows($result); for (;$i &lt; $rows&amp;&amp;$i &lt; $max;$i++) { $row_res=mysqli_fetch_array($result); printf("&lt;h1&gt;%s&lt;/h1&gt;&lt;p class='user'&gt;Posted By: %s&lt;/p&gt; &lt;p class='date'&gt;%s&lt;/p&gt; &lt;p&gt;%s&lt;/p&gt;", $row_res["title"],$row_res["user"],$row_res["date"],$row_res["content"]); } } </code></pre> <p>this returns well. I made links that execute an AJAX function that should return the next ten. this is the function:</p> <pre><code>function func1() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById("test").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","connect.php?func=1",true); xmlhttp.send(); </code></pre> <p>} The connect.php?func=1 points to an if that executes the get_posts() function with new args. but it doesn't show anything or it shows the first post at the top of the page and another first post in the content section.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload