web_master Posted May 20, 2008 Share Posted May 20, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/ Share on other sites More sharing options...
MadTechie Posted May 20, 2008 Share Posted May 20, 2008 ~Sighs~ Ahh the good old wish list posts, I want:~ £8,000,000 tax free But wait a minute.. this isn't wishlist.com.. ??? sorry if that sounded rude, but Whats the problem, What do you have so far? Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-545899 Share on other sites More sharing options...
web_master Posted May 20, 2008 Author Share Posted May 20, 2008 hm? Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-545908 Share on other sites More sharing options...
dare87 Posted May 20, 2008 Share Posted May 20, 2008 we need more information, the code, the db structure... the more you can give us, the more we can help Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-545912 Share on other sites More sharing options...
deadonarrival Posted May 20, 2008 Share Posted May 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-545914 Share on other sites More sharing options...
web_master Posted May 20, 2008 Author Share Posted May 20, 2008 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)) { } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-545922 Share on other sites More sharing options...
web_master Posted May 20, 2008 Author Share Posted May 20, 2008 just one thing, I will have a news wich can users see (news_onoff = 1) and news with `news_onoff` = "0" wich is an archive news. mean those news stay in dBase but with onoff=0. Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-545927 Share on other sites More sharing options...
MadTechie Posted May 20, 2008 Share Posted May 20, 2008 And the problem is ? Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-545946 Share on other sites More sharing options...
web_master Posted May 20, 2008 Author Share Posted May 20, 2008 problem? what is the best way to re-ordering "news" - rows ? Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-545949 Share on other sites More sharing options...
BlueSkyIS Posted May 20, 2008 Share Posted May 20, 2008 what do you mean, 'reordering news'? on the page? in the database? no need to reorder them in the database; just modify your sql as needed. Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-546004 Share on other sites More sharing options...
web_master Posted May 20, 2008 Author Share Posted May 20, 2008 so, this is the question, what is the best way to reorder "news"? - is in column "news_order", - is to change rows (news) ID, - or on some other way? Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-546012 Share on other sites More sharing options...
BlueSkyIS Posted May 20, 2008 Share Posted May 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-546019 Share on other sites More sharing options...
web_master Posted May 20, 2008 Author Share Posted May 20, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-546077 Share on other sites More sharing options...
BlueSkyIS Posted May 20, 2008 Share Posted May 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/106498-change-order/#findComment-546083 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.