Do you have a primary key or unique field in the table and what type it is? This is cruical for some control of which record to access.
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
Something like this maybe. It's a little nasty - and perhaps only increment on success from DB.
session_start();
if(!isset($_SESSION['table_start'])){
$_SESSION['table_start'] = 0;
}else{
$_SESSION['table_start']++;
}
$this_start = $_SESSION['table_start'];
$sql = "SELECT ... FROM ... ORDER BY ... LIMIT $this_start, 1";
diafol
Keep Smiling
10,611 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57
OK, you forgot to mention what type it is. So if it is an integer and autoincreased by the DB then the id fields probably increase as you add records and you can use this approach:
whenever you read and display the record save the id in the session. If there is no id in the session you are displaying the first record otherwise you just go for the next record. The rest is documended in the code below:
// start the session
session_start();
// if this is the first run of your script the id has not been stored in the session yet
if(!isset($_SESSION['current_id'])) {
// this query will select the record with the lowest id, presumably the first record
$query = 'SELECT * FROM table_name ORDER BY id ASC LIMIT 1';
} else {
// this query will read the record just after the current id
$query = 'SELECT * FROM table_name WHERE id > {$_SESSION['current_id']} ORDER BY id ASC LIMIT 1';
}
// read the row, display it and store the current id in the session
...
$_SESSION['current_id'] = $row['id']
More precise solution would be to have a field with timestamp so you could be always sure that the displayed records follow correctly each other.
Hopefully this is what you wanted to know.
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
Why are you ordering by RAND() if you want ordered results? The way I see it you have a choice with regard to modifying the WHERE or modifying the LIMIT clause.
As broj states - WHERE `id` > $var LIMIT 0,1
or - ORDER BY id ASC LIMIT $var,1
Not sure which would be the fastest. I think broj may have it - but you'd need to test.
diafol
Keep Smiling
10,611 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57
Did you try my code? Or broj1's?
diafol
Keep Smiling
10,611 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57
Now I get what you want. You do not want to display a contents of one record on one page but a page with a URL which is stored in a record. Is that true? Well, if it is the best way I know would be using iframes which you do. But if the framebreakers on those pages redirect ot original page then as far as I am aware you loose control. I am not aware of a way how to avoid this (actually have no much experience in it). Maybe someone else on this forum knows more about that?
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
Darn, we're back to this. A framebreaker code may have js check whether window.top is the same as window.self. If not then, a redirect ensues. So iframe content can't really be changed. Other sites may have X-Frame-Options: SAMEORIGIN as a response header. Again you're stuffed.
So cURL may be required in order to place the site into a div container. But as mentioned on a previous thread, 'domain-less' file references will try to access your server for the relevant files. The only way I can think of to circumvent this is to replace all file references to include the host domain:
e.g.
<img src="images/myimg.png" />
to
<img src="http://www.example.com/images/myimg.png" />
A preg replace may be able to make wholesale changes to the string before you echo it out.
Also as previously mentioned, the CSS and JS files, if you can get them resolved, may cause clashes with your own site resources. Additonally, if you have certain formatting, but the remote css file doesn't, you may find that your 'embedded' site looks totally different to the original. I can't think of a suitable workaround for this. DO these 'embedded sites' need to be functional? Could you not use images?
Headache.
diafol
Keep Smiling
10,611 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57
if you want to display one by one in sequece like 1,2,3
then i will suggest you to find next
intitially pass 0 as id
$id=0;//this must be not part of fetch script, it may be passed in post or get
now search next maximum active id from pass id
$nextid="select max(id) from websites where active=1 and userid=$id";
$query="select * from websites where active=1 and userid=$nextid";
now run query and return result to your div, and also save nextid in some another div or hidden field
so next time page refreshed, pass that hidden field your fetch script as id
I hope i explained it well
urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24
other sites style is forcely working on body tag
said so.
diafol
Keep Smiling
10,611 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57
Thanks broj1
No worries. But I think I have contributed the least in this thread :-).
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13