• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

php/html question

kwmarc

Limp Gawd
Joined
Aug 26, 2003
Messages
204
Sorry to bother you all again with this purchase order ordeal. I have a quick question regarding a peice of the puzzle that needs to be figured out. Since this database is going to be filled up with hundreds of PO's within the first week, i need to way to limit the display of PO's. I want 100 PO's to be displayed on a page at a time and when 100 PO's are display i want at the bottom of the screen to be a link to page 2 of the PO list. However, i do not want to go off to another page, i want to simply redisplay the next list of PO's when the user hits the "2" at the bottom of the page for page number 2 of the PO's.

Basically i want to have what search engines have, when you reach a maximum number of items on a page, automatically display a 2, 3, 4, ... My problem lies in the fact that i have not done much web development before and i am sort of being thrown into the fire designing this purchase order searching system.

cliffs:

1) Sample code to limit the number of displayed items on a page and auto increment numbers at the bottom of the page which correspond to a page number with the next set of PO's on them.

2) Instead of going to a whole new page when the user clicks the number at the bottom of the page to go to the next page of PO's, how can you display them in the same table that i have set up right now

If anyone needs sample code from my searching page, i will be glad to display it. Thank you for the help in advanced.
 
I would make your SQL query dynamic. If you are using mysql an example would be.

<?php
if(!$HTTP_POST_VARS[start]){
$HTTP_POST_VARS[start] = 0;
}

$query = ‘SELECT name FROM customers LIMIT ‘. $HTTP_POST_VARS[start].’ , 10’;
?>


<form id="previous_10" method="POST" onSubmit="filename.php"><input type="submit" value="Previous 10"><? echo '<input type="hidden" name="start" value="'.$HTTP_POST_VARS[start] - 10.'">'; ?></form></td>
<form id="next_10" method="POST" onSubmit="filename.php"><input type="submit" value="Next 10"><? echo '<input type="hidden" name="start" value="'.$HTTP_POST_VARS[start] + 10.'">'; ?></form></td>

This might help you get started... It probably can be done a little more efficiently.
 
In your code i am not understanding how you are dynamically creating the numbers at the bottom of the page for every 100 purchase orders that are put into the database. I understand the method of limiting my search but how do i autoincrament the pages at the bottom as well as what is being grabbed from the database?
 
That is where the $HTTP_POST_VARS is coming in. Initially I will assume it is 0 because we are looking at the beging of the list. (This I would think would only give us the Next 10 option).


The last line of the code/html contains the form for your next button.
<form id="next_10" method="POST" onSubmit="filename.php"><input type="submit" value="Next 10"><? echo '<input type="hidden" name="start" value="'.$HTTP_POST_VARS[start] + 10.'">'; ?></form></td>
If you notice that the value of that hidden field named start is contines your $HTTP_POST_VARS (which would be null if this the frist page) and adds the number you want to adjust pages by.

When the page repload you would preform your search of the db with the query.
$query = ‘SELECT name FROM customers LIMIT ‘. $HTTP_POST_VARS[start].’ , 10’;
With the LIMIT function the firs it where to start since we are on the first page and going to the second we are assiging it the value just sent. In my example it would 0 + 10, and echoing the query should look like this
$query = ‘SELECT name FROM customers LIMIT 10 , 10’;

Hitting the Previous or Next button then should adjust this number accordingly each time you hit a button.

You will still need to work out some logic on showing the buttons and setting an initial value for the $HTTP_POST_VARS[start] variable for the initial page load...

That may be a little better or I may have caused some more confusion.... I am pretty good at that...
 
do your query, then use a "for" loop to limit the list to 100. lastly you could use layers and <div> tags to display everything on one page. you would have to use nested loops.

something like:
$counter=0;
$number=0;
while (mysql_fetch_assoc($sql)){
do {
print something;
$counter++;
$number++;

} while (counter <= 100)
echo $number;
}
you would use $number to make the links at the bottom and associate some display actions with that

this is a start. i would have to play with the code and it would take some time to work out. i am trusting that you know HTML and how that use layers.
 
The for loop would work but if the db gets really large say 10,000 rows your start to pull back 9000 rows that are useless to you. The more users you have it will begin to stress the db for querying all of that data and the web server to a lot of time on the loop.

I am not sure of you resources.... I kinda had a similar problem with a lot on not needed data and it spiked a 4 processor (2.0 Ghz Xeon) box... The boss was not happy.
 
Couple of notes:

1) $HTTP_POST_VARS and the like are deprecated, use the superglobals $_POST or $_REQUEST instead.

2) To determine the 1..2..3.. without overloading the DB, use the following (taken from the MySQL manual)
FOUND_ROWS()
A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To get this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, then invoke FOUND_ROWS() afterward:
mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
WHERE id > 100 LIMIT 10;
mysql> SELECT FOUND_ROWS();

The second SELECT will return a number indicating how many rows the first SELECT would have returned had it been written without the LIMIT clause.
 
appreciate all of the comments, i am out of the office right now but i will take a look tomorrow. If i have any questions i know where to come. Thanks
 
What does the mysql_fetch_assoc($sql) do, i am used to doing:

$query = mysql_query 'select some argument from sql'
$row = mysql_fetch_array$query);
extract($row);

after playing around with it for about an hour i can only get 100 of the same PO's to come out of the database, and i believe it has something to do with the way i have the initial while loop set up. What does mysql_fetch_assoc($sql) do?

My code right now is:

$counter = 0;
$numofpo = 0;
while($row = mysql_fetch_array($query)) {
extract($row);

do {

<whole bunch of formatting and printing>
$numofpo++;
$counter++;
} while (counter <= 100);
 
kwmarc said:
What does the mysql_fetch_assoc($sql) do?
Documentation is your friend.
http://www.php.net/mysql_fetch_assoc
Fetches a result row as an associative array

As for the problem, I'll blame the fact that you have nested loops for no good reason. It looks like you never reset $counter to 0, which is the direct problem, but the root is that you've got unnecessary stuff. Use LIMIT in your query to restrict the result set. It's more efficient for the DB, saves a useless PHP loop, and removes the immediate problem.
 
pagination is pretty complex. you might want to google "php pagination" and see if you can find a script you can just hack to fit your needs.
 
Back
Top