loaded

How to dynamically retrieve data to div on page scroll

I have been searching for an answer for hours with no luck, so I decided to come here. I want my page to dynamically load data from my database to a

when a user scrolls to the bottom of the page. Each new set of data should be 5 records after the last set. If anybody could please take time to look through my codes I will forever be grateful. This is my CODE:
      body < font-family:helvetica; background-color:#58ACFA; width:100%; >h1 < text-align:center; font-size:35px; margin-top:50px; color:#0B173B; >#all_rows < overflow-y: scroll; height: 400px; >#load   

Load Results From Database On Page Scroll Using jQuery, Ajax And PHP

connect_error) < die("Connection failed: " . $conn->connect_error); > $sql = ("SELECT * FROM insertion LIMIT 0,5"); $result = $conn->query($sql); while ( $row = $result-> fetch_array()) < echo "
"; echo "
" . $row['Title'] . "
"; echo "
" . $row['Description'] . "
"; echo "
" . " Get This file
"; echo "
"; > $conn->close(); ?>

Источник

DIV with scroll not working [closed]

It’s difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.

I have a php file with a DIV which has mysql table content. I also have other links and info on this page. I want only the div content to have a scrollbar, I have used overflow=scroll; but the scrollbar is not working for DIV. Need help ! Here is my code:

       "; echo ""; echo ""; echo ""; echo ""; echo ""; $recs=mysql_query("SELECT * FROM INVHDR ORDER BY Invno DESC"); while ($r2=mysql_fetch_assoc($recs)) < $invno=$r2['Invno']; $invdat3=$r2['Invdate']; $invdat2=date("Y-m-d", strtotime($invdat3)); //$invdat2->format('Y-m-d'); $date_array = explode( "-", $invdat2 ); $invdat = sprintf( '%02d/%02d/%4d', $date_array[2], $date_array[1], $date_array[0] ); $acode=$r2['Ac_code']; $amt=$r2['Amount']; //--selecting customer name----------------------------------- $cus=mysql_query("SELECT Ac_desc FROM ACMAST WHERE Ac_code='$acode'"); $cus2=mysql_fetch_assoc($cus); $acdesc=$cus2['Ac_desc']; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; > echo "
PACE LTD
INVOICE PRINTING


"; ?>
 
Please select Invoice No. to PRINT:

You can choose more than one invoice number from the options, by holding CTRL key on your keyboard and select the numbers.
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); > //////// End of connecting to database //////// $result = mysql_query("SELECT Invno FROM INVHDR ORDER BY Invno DESC"); echo "";// Closing of list box echo "

"; echo "
Inv DateInv No.Customer NameAmount
$invdat$invno$acdesc$amt
"; ?>
     



           

Источник

Scroll to div after php code [closed]

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Hi I would like to scroll to a div after running a php code that runs when i press the it searches the database and posts to a table thats located in that div

 $(document).ready(function () < $('html,body').animate(< scrollTop: $('.graph').offset().top >, 'slow'); >) "; else < $query = "SELECT * FROM `users`"; $result = mysqli_query($conn,$query); >?> 

What have you tried so far to get that to work that has you stumped? And is the PHP you posted called from ajax of some sort? You did not include any js code samples.

Try to enclose the animate function in a $(document).ready(function() < . >) block as .graph probably doesn’t exist until the page is loaded

1 Answer 1

The session_start() needs to be before any HTML output so that means somewhere above the tag. The rest of the code should be in the body of the document so you can run the script .

Also, use the $( window ).load(); instead of $(document).ready(); to be sure that the whole HTML page is loaded including CSS and javascript files.

Here is the corrected code:

       $( window ).load(function() < $("html,body").animate(< scrollTop: $(".graph").offset().top >, "slow"); >); '; else < $query = "SELECT * FROM `users`"; $result = mysqli_query($conn,$query); >?>  

Источник

Scroll top function in php code example

Solution 2: You can use jquery code to do scroll top Solution 3: I am not good in this, but still check below process if that works, check onbeforeunload event if that event occurs set the cookie, and on page check if the cookie is set then fire scroll to top event. If value specified is greater than maximum scroll amount, then the value is set to maximum number.

Scroll to top after history.back

Use below script in that page, in which you want to go to top of page.

 $(window).bind("pageshow", function() < $("html, body").animate(< scrollTop: 0 >, 600); >); 

You can use jquery code to do scroll top

I am not good in this, but still check below process if that works,

check onbeforeunload event if that event occurs set the cookie, and on page check if the cookie is set then fire scroll to top event.

After that once scroll to top event occurs change the cookie value again.

Not at all sure this will work and it is a right solution, but just tried to think how it can be implemented.

Using scrollTop to show pixels scrolled

Next time try a little harder before you ask:

It’s really as simple as the following:

(function(window, document, $, undefined) < $(function() < var win = $(window), ele = $('.pixels'); win.scroll(function() < ele.text(win.scrollTop()); >); >); >)(window, document, jQuery); 

Try using document.getElementsByTagName(«body»)[0].scrollTop

JQuery scrollTop(), The jQuery scrollTop method is used to set or return the vertical scrollbar position for the selected element. When the scrollbar is on the top, it specifies the position 0. To return the position: When this method is used to return the position, it provides the current vertical position of the first matched element in the set.

Div scrolls to top after refresh need to stop auto scroll to the top

from the scars infos I can gather here I think your best bet would be to save your current scroll position before you refresh and after the ajax call scroll to that saved position. use jQuerys .scrollTop() function for both reading and setting the scroll.

some pseudo code for illustration:

at ajax refresh function var curPos $(element).scrollTop(); . do ajax call .. ajax callback: $(element).scrollTop(curPos); 

HTML DOM Element scrollTop Property, Get the number of pixels the content of «myDIV» is scrolled: const element = document.getElementById(«myDIV»); let x = elmnt.scrollLeft; let y = elmnt.scrollTop; Try it Yourself ». Scroll the contents of «myDIV» TO 50 pixels horizontally and 10 pixels vertically: const element = document.getElementById(«myDIV»); …

HTML | DOM scrollTop Property

The DOM scrollTop property is used to return or set the number of pixels an element is scrolled vertically. If the element’s content doesn’t generate a scroll bar, then its scrollTop value is 0.

Where value specifies the number of pixels the element’s content is scrolled vertically.

  • It’s value can’t be negative.
  • If value specified is greater than maximum scroll amount, then the value is set to maximum number.

Источник

php, scroll page to specified html control on form

First question after starting with netbeans and wamp server 2 days ago. Only have some desktop vb background, so my jargon may be off. In vb I would want to set the focus on a control. I have a long, as in a lot of scrolling, webpage form in html that displays the way I want it. There are about 300 controls, almost all checkboxes. When the Submit button is clicked at the bottom of the form I want to find any incomplete data, scroll the page to that control and give the user a message so I don’t insert unfinished records. How do I do that?

They form may be generated by PHP, validation and scrolling will have to be done client side, in Javascript. You should also run the validation server side as well, because the user controls the client.

Thanks Dan, javascript it is. I had thought i only needed php and mysql when i started, now I’m adding javascript to html and css.

3 Answers 3

I think you need to validate data with javascript and with a function to do scroll. Check this:

In the form, add the ‘required’ attribute to each input tag. EX:

When the form is submitted, the first input tag with the ‘required’ attribute will be scrolled to, and the user will be notified.

What you are looking for is called validation. You should validate data on the server with PHP to make sure that the data meets your defined criteria (since the data could come from a manipulated form and users can deactivate javascript). You should also look into escaping data, for example with mysqli_real_escape_string to prevent SQL injection (an attack where a malicious user enters SQL statements in your form to alter/expose data in your database). And you should sanitize your data.

But that is all server-side. What you also want is to have a good user experience and not even send data to the server unless is is valid. This is done with javascript on the client side. The upside is: Immediate feedback without a page load. But it has little to do with security since it’s easy to manipulate that or turn javascript off.

I would recommend using jQuery and then a plugin like jQuery Validation. And for the scrolling part you could use jQuery scrollto. You could combine those two with a callback from jquery validation. For example (just a quick and dirty example):

$(".form-selector").validate( < invalidHandler: function(event, validator) < // 'this' refers to the form var errors = validator.numberOfInvalids(); if (errors) < var message = errors == 1 ? 'You missed 1 field. It has been highlighted' : 'You missed ' + errors + ' fields. They have been highlighted'; $("div.error span").html(message); $("div.error").show(); // Now scroll to the first error message var first_element = validator.errorList[0].element; $(window).scrollTo(first_element); >else < $("div.error").hide(); >> >); 

But the best thing would be to start with a jQuery tutorial and then dig into that.

Источник

Читайте также:  Android java code reader
Оцените статью