Jump to content

Help on re-ordering a list of info.


dipp02

Recommended Posts

Hello.

 

I am creating a function for a site to show a list of companies with phone, addy, email, website, etc.. with about 10 listings that will show up on the page so some listings will be "off the screen".

 

what the client would like to have the list do so each company will have a turn at the top of the page. is when the page refreshes the company at the bottom of the list will go to the top of the list and so on.

 

 

or if anyone has any other idea on how to have each company have a turn at the top of the page...

 

i am using framework codeigniter and mysql database for the site.

 

if i wasn't clear please let me know so i can explain better.

 

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/160751-help-on-re-ordering-a-list-of-info/
Share on other sites

One way is using sessions, like this example:

 

session_start();

if(!isset($_SESSION['list'])){
$_SESSION['list'] = array(
				"Company 1",
				"Company 2",
				"Company 3",
				"Company 4",
				"Company 5",
				"Company 6",
				"Company 7",
				"Company 8",
				"Company 9",
				"Company 10"
			);
}

$tmp = $_SESSION['list'][count($_SESSION['list']) - 1];
$list = array_pop($_SESSION['list']);
array_unshift($_SESSION['list'], $tmp);

echo "<pre>", print_r($_SESSION['list']), "</pre>";

  • 4 months later...

How can i do this so on every computer the company thats next in line comes up on every computer not just on the computer i am on?

 

using sessions will only happen to that one computer.

so if company 1 is up and i refresh the page company 2 comes up. but on a totally different computer company 1 shows up and not company 3 which is next in line.

 

should i just use a simple for loop?

 

any ideas? i was going to make a field in the database under the company table called 'position' and add/minus the position number everything the page refreshes.

 

Any help on this would be great!

 

Thanks in advance!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.