Knowledgebase

every 3rd one?

Posted by ti_nhatrang, 12-27-2007, 10:06 AM
Hi all, I have a php script that executes about 6 outputs, I would like it to display an image after every 3rd output. So I have a total of 8 images showing, instead of just 6 from the DB: Here's what I got so far: please help, almost done with project, last step. Thank you so much! I basically want to put: in between every 3 images above.

Posted by dollar, 12-27-2007, 10:27 AM
Declare a variable somewhere outside of the loop and set it to 1 such as: Inside of the loop use some logic like this to determine if you want to display the image or not:

Posted by ti_nhatrang, 12-27-2007, 05:08 PM
I've tried your recommendation, but it doesn't seem to work for me: here's what I have:

Posted by dollar, 12-27-2007, 05:10 PM
From the code you posted it looks like you didn't close the else from the if/then statement.

Posted by ti_nhatrang, 12-27-2007, 08:00 PM
I actually did in my original php file... But what I have above, is it correct to what you are recommending?

Posted by FluffyTheRabbit, 12-28-2007, 05:01 AM
You are performing 7 MySql queries every time the page is loaded? Should be able to merge them, or something. However, I will go ahead and show you what you are wanting to know. You need to count and see exactly when you have 3 rows, (every three rows), just like the previous poster. Best way to do that, is first, create a variable outside of the LOOPs that have a default value, lets call it 'count' and the value is 1. Now, inside the loop, you test to see if the count is equal to 3, or not, if it is, display the image and reset the counter, if not, then keep counting. The first person to respond had it right. Let me show you. This is just an example of how to go through a loop and work with counting. This is what he was trying to show you. Now I will modify your code to work with this (I am not saying it will work because I am not connecting to a database, but it should). Ok, hopefully that works. In your sample code, you had left out an ending double quote and semi colon for the echo statement. As well as a closing curly brace, may be other things missing but I am not sure. Hopefully this helps, any questions, let me know

Posted by ti_nhatrang, 12-29-2007, 05:03 AM
yes!!! It work perfectly! Thank you so much!!! However, was wondering if there's a better place to put so you can click on the background image to the link



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
Godaddy/WildWest Down (Views: 660)
New member (Views: 586)


Language:

Client Login

Email

Password

Remember Me

Search