PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
I have a page that searches mssql and returns a result set. I use $num_of_rows = mssql_num_rows ($msresults); to get the number of results. So far so good. After this comes my for statement and each line item of my results. I use an if statement to determine whether the line item is allowed to be viewed by the end user. So, my result set may have 15, but only 5 of those are being displayed to the end user. What I want to know is how do I make $num_of_rows reflect only what I am showing to the viewers instead of the total of all records found from the sql search... I can create a variable with a 1 if the viewer is allowed to see the data, and a 0 if they are not, but I do not know how to get that sum into the $num_of_rows variable... hopefully this is clear enough that someone could enlighten me...
<?php
SQL SEARCH DONE HERE
$num_of_rows = mssql_num_rows ($msresults);
for($i=0; $i<$RowPerPage; $i++) {
$row = mssql_fetch_array($msresults);
if(!$row){ break; }
VARIABLES SET HERE
If (Statement to determine which data is viewable) {
echo DATA;
}
Laura
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
What is in the conditional statement? Two if statements in a loop will be a performance hit. Can you not just pull out exactly what you want from the database. i.e put the conditions in the query?
The problem is that you want to display the number of rows earlier in the page than where you show the actual rows?
Rather than outputing the rows directly, store them in a variable. Then, in your for() loop, increment a counter every time an allowed row is encountered. After your for() loop is done, output the counter, then output the variable that's storing your row data.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
What is in the conditional statement? Two if statements in a loop will be a performance hit. Can you not just pull out exactly what you want from the database. i.e put the conditions in the query?
Unfortunately the conditions do not exist (nor can they exist) in the database. It is pretty complicated...
The problem is that you want to display the number of rows earlier in the page than where you show the actual rows?
Rather than outputing the rows directly, store them in a variable. Then, in your for() loop, increment a counter every time an allowed row is encountered. After your for() loop is done, output the counter, then output the variable that's storing your row data.
This sound like what I need... I am going to give this a try - thanks so much everyone!