Jump to content

change order


web_master

Recommended Posts

hi,

 

I will try to explain what I want to do:

 

I want to put on the site every day a few news. Every news had a ID. The order of news listing ( in admin ) is ID DESC.

 

Sometimes I need to change the order of news. in listing I can "switch" on or off the news.

 

What is the best way to change the order of news which is "on"?

 

- ID: 256, headline: NEWS ONE, onoff=1

- ID: 255, headline: NEWS TWO, onoff=1

- ID: 254, headline: NEWS THREE, onoff=1

- ID: 253, headline: NEWS FOUR, onoff=0

- ID: 252, headline: NEWS FIVE, onoff=0

- ...

 

 

And I want to change th order of news like:

 

- ID: 256, headline: NEWS ONE, onoff=1

- ID: 254, headline: NEWS THREE, onoff=1

- ID: 255, headline: NEWS TWO, onoff=1

- ID: 253, headline: NEWS FOUR, onoff=0

- ID: 252, headline: NEWS FIVE, onoff=0

- ...

 

or maybe to a another order... I hope You understand what I want.

 

thnxs

Link to comment
Share on other sites

He means that if you throw a PROBLEM at a forum, people aren't likely to help - we have our own work to do, without doing everything for someone else, especially if the problem isn't very well explained.

 

What is your database layout? What have you tried? In what context are  you trying to re-order.

 

If you want to display 3 before 2, you're looking at re-ordering an array. If you know which you want to move to where, it's fairly simple. There are several techniques (moving then re-ordering etc)

 

On the other hand you could just have a seperate table "homepage items", and just put in the ID's of the news items you want?

 

That would give a shorter array, all useful. You can just swap items into and out of the array, have as many or as few as you want and more easily order them to any order you want.

Link to comment
Share on other sites

so, deadonarrival give me some explanation, what I dont know - but its maybe interresting:

 

another table for a re-ordering?

 

here is a "upload" code for a news table:

 

<?php 
$query = mysql_query("INSERT INTO `news` (
	`news_headline`,
	`news_day`,
	`news_month`,
	`news_year`,
	`news_expire_day`,
	`news_expire_month`,
	`news_expire_year`,
	`news_lead`,
	`news_text`,
	`news_author`,
	`news_press`,
	`news_photocaption`,
	`news_photographer`,
	`news_datetime`,
	`news_ip`
) VALUES (
	'".$_POST['news_headline']."',
	'".$_POST['news_day']."',
	'".$_POST['news_month']."',
	'".$_POST['news_year']."',
	'".$_POST['news_expire_day']."',
	'".$_POST['news_expire_month']."',
	'".$_POST['news_expire_year']."',
	'".$_POST['news_lead']."',
	'".$_POST['news_text']."',
	'".$_POST['news_author']."',
	'".$_POST['news_press']."',
	'".$_POST['news_photocaption']."',
	'".$_POST['news_photographer']."',
	'".date("Y-m-d H:i:s")."',
	'".getenv("REMOTE_ADDR")."'
)");

// Check query
if(!$query){
	print mysql_error();
	exit;
}

// Retrieves the last ID
$news_id = mysql_insert_id();

// Reload from dBase
$query_return = mysql_query("SELECT * FROM `news` WHERE `news_id` = '".$news_id."'");

// Check query
if(!$query_return){
	print mysql_error();
	exit;
}

// Request query
$request = mysql_fetch_array($query_return);
?>

 

additional columns are:

 

news_order

news_onoff

 

these columns use when I listing the news

 

 

when I list the news, listing code is in ADMIN:

 

<?php 

$query_return = mysql_query("SELECT * FROM `news` ORDER BY` news_id` DESC");

// Check query
if(!$query_return){
	print mysql_error();
	exit;
}

// Request query
while($request = mysql_fetch_array($query_return)) {



}

?>

 

 

when I list the news, listing code is in WHAT USERS SEE:

 

<?php 

$query_return = mysql_query("SELECT * FROM `news` WHERE `news_onoff` = '1' ORDER BY`news_id` DESC");

// Check query
if(!$query_return){
	print mysql_error();
	exit;
}

// Request query
while($request = mysql_fetch_array($query_return)) {



}

?>

 

Link to comment
Share on other sites

reorder news on the page? or reorder news in the database?

 

if you just need to order news differently on the page, use 'ORDER BY news_date' or some other column. news is usually added by date, so i suggest you use a date field to order your news.

Link to comment
Share on other sites

ok, well look one example:

 

I put the news up, after came the director of the news and he change the order of the news...

 

the problem is that if there in dBase a hundreds of news, and I want to change the order of a last 10-15 news. But, maybe in archive need to chage the order (not a big possibility) too...

Link to comment
Share on other sites

ah, so you need to change the news order by a criteria other than date. i would use an order_by row. when an article is moved up, switch it's order_by with the one before it. if an article is moved down, switch it's order_by with the one after it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.