Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a problem and did not solve.
What i want is that listing photos side to side
like that:
The problem is that when i have 50 photos , this happens
What i want is that listing ten photos per columns. How can i do that ?
When looping to display the images you need to break every 10 photos like so:
$photosPerLine = 10;
for ( var $i = 0; $i < $totalNumPhotos; $i++ )
{
drawPhoto(); // This does the actual drawing - perhaps echo a <IMG> or whatever
// Now we check if we've reached 10 in a row, we do this by dividing the
// photo counter by 10 and checking for a reminder, only numbers in leaps
// of 10 will divide without a reminder. If we don't have a reminder it means
// we're at 10, 20, 30 ... so we break the line
if ( ( $i + 1 ) % $photosPerLine == 0 )
{
echo( '<br/>' ); // Or create a new row in a table or whatever
}
}
Or just place the images in a container (<div> for example) with a specified width to hold exactly 10 images and let the browser break lines to fit the content.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
I'm trying to find the sum of numbers by querying a database using PHP and MYSQL. I need a while loop or any other solution that can add numbers that are >= 40 from a sequence of numbers. I'm only able to make the query but don't know how to go about the rest.
$selectMARK="SELECT mark FROM resultstbl WHERE mark >= 40";
$queryMARK=mysqli_query($dbCon, $select);
$sum=0;
while($rowz=mysqli_fetch_assoc($queryMARK))
{
// need some code to add the numbers here
}
You maybe need an
$iterator = 0;
outside the loop, that you can increment inside of it.
$sum += $rowz[$iterator];
$iterator++:
Then do your condition around it by checking $rowz[$iterator] <= 40
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
i've got a album site for photos but i want to count the amount of photos from the Database with the amount of images each page can be changed by Admin in PHP.
PHP Code
<button>Last page</button>
count($view) = 5
count($view) = 4
so he counts 1.25 and goes to page 1 as last page. but on page 2 is still one photo. so the last page is 2.
in an other example i got
count($view) = 20
count($view) = 4
Then he is going to page 5 correctly because it is rounded to the good amount.
Anyone knows a function?
Figuring out paging is relatively simple.
Imagine you have 42 records, and display ten per page.
$numPerPage = 10; // this is your limit clause in sql
$page = $_GET['page'] ?: 1; // default to 1 if not set.
$offset = ($page * $numPerPage) - $numPerpage;
$totalPages = ceil($numRecords / $numPerPage);
Offset eg page 3 = (10 * 3) - 10; // offset 20
TotalPages eg 42/10 = 4.2, ceiling makes it 5
So then in your SQL:
SELECT xFROM y WHERE z='a' OFFSET $offset LIMIT $numPerPage
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
$result contains a non specific amount of records.
I need to loop through $result, and after every 100 records, do something, and then continue the loop, but include 5 records from the previous loop (overlap).
Like this:
Get records 0-100
Do something with these records
Get records 95-195
Do something with these records
Get records 190-290
Anyone have a suggestion how this is done in the most efficient way?
first of all I agree with the commentators. We are here to help with problems you've ran in, but not to write your script.
Neverthelesse I wrote a perlish solution of your problem:
$results; #your results
for($i = 0; $i <= #{$results}, $i++){ #loop through all results
my #tempList;
push(#tempList, #{$results}[$i]); #push every result in a temporary list
if (#{$results} == 100 || $i == #{$results}) { #do sth, if the tempList hast 100 entries or you're at the last round of your loop
#do sth with the 100 records
$i -= 5; #decrement i to get the 5 entries overlap
}
}
You can see that it's a simple loop through your results. Every 100th round the if will evaluate to true and you can do sth with your data.
The overlap is realised by decreasing the counter every 100th round. Be careful in the last round when finishing your loop! You will get an infinite loop if you don't escape the $i -= 5; in the last round!
$slimit=0;
$flimit=100;
while($flimit<=total_records_in_your_table)
{
$q="select * from table_name limit $slimit,$flimit";
while($data=mysql_fetch_row($q))
{
//opration
}
$slimit=$flimit-6;
$flimit=$flimit+$slimit;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Okay, so for my website, I made a tests system, where you can take quizes. It all works, but getting the percentage of correct answers is broken.
I have 3 variables I am trying to use to get the percentage.
$incorrect // Int value of incorrect answers
$correct // Int value of correct answers
$perc // Percentage of correct answers from 0 to 100
Currently, I use this, but it does not work:
if($incorrect===0){
$perc = 100;
}elseif($correct===0){
$perc = 0;
}else{
$perc = ($incorrect / $correct)*100;
}
$perc = $correct*100/($incorrect+$correct)
User1950001, as Barmar mentioned, you need to calculate the TOTAL number of answers as a percentage is calculated by (NUMBER OUT OF TOTAL x 100 / TOTAL).
In this case, CORRECT. is your NUMBER OUT OF TOTAL and INCORRECT + CORRECT is your TOTAL, which is what you were missing.
With your original code, perc = ($incorrect/$correct) * 100 where total questions is 25, 20 are incorrect and 5 are correct would return 400% as the value. Obviously this is way off.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
When I print out the integers (1 or 0), all the iterations (there are 3 of them in this case) print out the correct number. First and the second one return 1, the last one returns zero. BUT, 'if' statement seems to display everything in it anyway. What am I doing wrong?
All the code below is inside a bigger 'for' loop.
$yn = 0;
if(!in_array($pos, $blocks)){
$blocks[$x] = $pos;
$x++;
$yn = 1;
}
print_r($blocks);
print "YN: ".$yn; # this prints out 1, 1 and 0 on the last iteration
if(yn){
# show some stuff (is displayed in all three iterations, but it shouldn't be on the last)
}
Try:
if($yn){
PHP is interpreting yn as a string, rather than as the variable you should be using.