Jump to content

Search the Community

Showing results for tags 'sort'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 13 results

  1. I want to display 10 products from each category from database, I started to display the categories but how to make displaying the products from each one. Here is the code I make so far. I'm not sure am I doing it right with doble sql select , or it can be done only with one. <div class="inner shadow"> <?php $query = 'SELECT id, title_bg AS `title_cat` FROM categories'; $result = $this->db->query($query); ?> <?php foreach ($result->result() as $row): ?> <?php $title_cat = stripslashes($row->title_cat); ?> <div class="prod-sec"> <div class="prod-head"> <h2><?= $title_cat?></h2> <div class="clear"></div> </div> <?php $query1 = 'SELECT t1.id, t1.title_bg AS `Title`, t1.text_bg AS `Text`, t1.price, t1.discount, t1.category_id, t1.promo_page, t2.id AS FileID, t2.ext, FROM products t1 LEFT JOIN products_pictures t2 ON t1.id = t2.object_id LEFT JOIN categories t3 ON t3.id = t1.category_id WHERE t1.promo_page = 0 AND t1.is_active = 1 AND t3.title_bg = '$title_cat' ORDER BY RAND() LIMIT 10'; $result1 = $this->db->query($query1); ?> <div id="classeslist2"> <ul class="home_middle_products"> <?PHP foreach($result1->result() as $row1) { $f = 'files/products_first_page/' . $row1->id . '.jpg'; if(is_file(dirname(__FILE__) . '/../../' . $f)) { $img = site_url() . "files/products_first_page/".$row1->id.".jpg"; } else { $img = site_url() . "files/products/".$row1->id."/".$row1->FileID."_2.".$row1->ext; } $title = stripslashes($row1->Title); $text = character_limiter(strip_tags(stripslashes($row1->Text)),250); $title_url = getLinkTitle($title); $link = site_url()."products/product/".$row1->id."/{$title_url}"; ?> <li style="width: 185px; height: 270px; margin-left: 3px; margin-top: 10px;"> <div class="thumb"> <a href="<?=$link?>"><img src="<?=$img?>" alt="<?=$title?>" width="182" /></a> <div class="price"><?PHP echo product_price($row1, array('show_discount' => false,"show_old_price"=>false, 'show_label' => false, 'view' => 'no')); ?> </div> </div> <h2></h2> <h2><a href="<?=$link?>"><?=$title?></a></h2> <? $text = substr($text, 0, 100); ?> <? if (strlen($text) == 100) $text .= '...' ; ?> <p><?=$text?></p> </li> <?php } ?> <div class="clear"></div> </ul> </div> </div> <?php endforeach; ?> <div class="clear"></div> </div>
  2. I'm seeking to change a download counter script: http://www.phpkode.com/source/s/dscript-php-file-download-counter/dscript-php-file-download-counter/Includes/functions.php so that it sorts by descending date order of filename as seen by the server instead of sorting in descending alphanumeric order of filename as now. The script counts downloads for files stored on a server, saves the download counts in a log file, then using an array built from the log file, outputs the download count for each file to a web page. This is the function I believe needs to change // Function to read the log file, and return an array as (filename => downloads) function read_log() { global $path; // Declare Array for holding data read from log file $name = array(); // array for file name $count = array(); // array for file count $file = @file("$path/Includes/log"); if(empty($file)) { return null; } // Read the entire contents of the log file into the arrays $file = fopen("$path/Includes/log","r"); while ($data = fscanf($file,"%[ -~]\t%d\n")) { list ($temp1, $temp2) = $data; array_push($name,$temp1); array_push($count,$temp2); } fclose($file); // $file_list contains data read from the log file as an array (filename => count) $file_list=@array_combine($name,$count); ksort($file_list); // Sorting it in alphabetical order of key return $file_list; } The log file syntax is file name then a TAB then download count (0 or higher). New files are added frequently which the script has to count. I need the latest added file to be at the top of the web page but I now need to change the file names of new files which causes them not to come to the top of the list if sorted as now. I looked at these http://stackoverflow.com/questions/16733128/sort-array-by-date-in-descending-order-by-date-in-php http://stackoverflow.com/questions/6401714/php-order-array-by-date https://stackoverflow.com/questions/3302900/how-to-sort-output-from-several-log-files-by-date but I don't get a specific enough idea of what I must change in the script above the lines where ksort is invoked.
  3. Hi first tyvm for reading my help request me and my friend ar trying to build a order form (see png file ^^) so the main idea is some on go to order form.php in that order form they fil in thear info like name, adress you know ^^ thean here is the treaky part at the and of the form they kan add products to there order by selecting it or search it from the drop down list the items in the dropdown list come from msql the client can add more or delete items by clicking - or + whean the clint click send the client need to get a mail whit there a list of what theay have orderd and there unic order number wel so far we can do that but we wont to send another list to the company of order where the added products in the order ar sorted out based on the product id number this is what we have so far http://clientconstruction.publishvision.nl/valeri/ tyvm again voor anyone who read this ^^
  4. Hi, This is the output from a var_dump($array); command: array (size=381) 0 => array (size=2) 'Name' => string 'apple' (length=6) 'Number' => float 0.368844763 1 => array (size=2) 'Name' => string 'Blueberry' (length= 'Number' => float 5.59E-6 2 => array (size=2) 'Name' => string 'Cinnamon' (length=5) 'Number' => float -0.0006947 3 => array (size=2) 'Name' => string 'Date' (length=10) 'Number' => float 0.001584453 ... ... ... I want to sort this array from the highest 'Number' float value to the smallest. I tried sorting it with rsort($array,SORT_NUMERIC); but that doesn't give the correct output. What kind of 'sort' should i use to do this?
  5. Ugh - title should say sort, not sport, sorry. This should be easy, but for the life of me, I cannot get this to work. I've been staring at it for so long, I'm going nuts. Ultimately, what I'm trying to do is combine the unique results of a query (of 3 columns of a table) to populate a drop-down menu. I have a function in place, however, that function only grabs data from one of the 3 fields I designate, not all 3. So I'm trying to create a new query to search all 3 fields, remove duplicates, sort alphabetically, and then display them in the drop-down list. Here's the function I originally had, but I don't know how to alter this (if possible) to include combining 3 fields instead of having to list 1: function filldropdown($sql, $sfieldname) { $result=mysql_query($sql); while($row=mysql_fetch_assoc($result)){ echo "<option value='" . $row[$sfieldname] . "'>" . $row[$sfieldname] . "</option>"; } mysql_free_result($result); return; } And then this is the code that adds the list to the page, except you'll notice at the end of the query, I have to list only 1 field to pull from (TW), instead of it listing TW1, 2 and 3. <? filldropdown("SELECT distinct TW, TW2, TW3 from TABLE", "TW"); ?> So instead, I'm trying to do this (I've simplified this to hopefully make it easier to understand my thought process of what I'm trying to do). What am I doing wrong? $TW1 = mysql_query("SELECT distinct TW from TABLE"); $TW2 = mysql_query("SELECT distinct TW2 from TABLE"); $TW3 = mysql_query("SELECT distinct TW3 from TABLE"); // combine and sort results of TW, TW2, TW3 fields into a single list $TW1result = mysql_fetch_array($TW1); $TW2result = mysql_fetch_array($TW2); $TW3result = mysql_fetch_array($TW3); $CombinedTW = array_merge($TW1result, $TW2result, $TW3result); $UniqueTW = array_unique($CombinedTW); $ALLTW = asort($UniqueTW); while($ALLTW) { echo "<option value='" . $ALLTW . "'>" . $ALLTW . "</option>"; }
  6. Hello. This is my PHP/MySQL code <?php $result = mysqli_query($con,"SELECT * FROM tutorials"); ?><table border="1"> <?php while($row1 = mysqli_fetch_array($result)) { echo '<tr>'; echo '<td><p>'; echo $row1['Name'] . "</p></td><td>" . $row1['ShortDescription']; echo '</p></td>'; echo '</tr>'; } ?></table> When it displays, it shows the newest columns in the table last. How do I reverse that.
  7. Greetings all, I have a script that creates an array from a folder of images. // Create Array $files = array(); if( is_dir( $thumbs_dir ) ) { if( $handle = opendir( $thumbs_dir ) ) { while( ( $file = readdir( $handle ) ) !== false ) { if( $file != "." && $file != ".." ) { array_push( $files, $file ); } } closedir( $handle ); } } If I echo this array out into a table or what have you it lists them in a strange way. 4_Photo1.jpg 4_Photo11.jpg 4_Photo12.jpg ......and so on up to 19 4_Photo2.jpg 4_Photo21.jpg 4_Photo22.jpg .....and so on up to 29 4_Photo3.jpg 4_Photo31.jpg 4_Photo32.jpg As you can see the array comes out in, well, a numeric order but a weird one. Instead of loading 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, it loads like above 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 21, 22..... How can I go about sorting this so that it comes out how one would count normally? Preferably in reverse order, counting down would be better. I tried: sort( $files, SORT_NUMERIC ); But that got really messy and threw the order all over the place. Best Regards, Nightasy
  8. Basically, I am writing a script in PHP, which can take YouTube videos from playlists, items from RSS feeds and podcasts, and individual YouTube videos and files, and places them into an XML document, so they can browsed and kept in one place. I also have a script which removes these items, if the user wants. The problem I'm facing is with characters. Because I can't control what the user will name their videos/files, or how they're named in the feed, the titles could have quotes, brackets, ampersands, hashes etc, which causes problems when they're being removed and Because I'm using Xpath (which can be temperamental at the best of times) in the remove script, any items with titles with these characters won't get removed. Here's my remove code: <?php $q = $_GET["q"]; $q = stripslashes($q); $q = explode('|^', $q); $counts = count($q); unset($q[$counts-1]); $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->Load("../$userid.xml"); $xpath = new DOMXPath($dom); foreach ($q as $r) { $r = preg_replace("|&|", '&', $r); $r = preg_replace('|"|', '"', $r); $query1 = 'channel/item[title='.$r.']/title'; $query2 = 'channel/item[title='.$r.']/media:content'; $query3 = 'channel/item[title='.$r.']'; $entries = $xpath->query($query1); $entries2 = $xpath->query($query2); $entries3 = $xpath->query($query3); foreach ($entries as $entry) { foreach ($entries2 as $entry2) { foreach ($entries3 as $entry3) { $oldchapter = $entry->parentNode->removeChild($entry); $oldchapter2 = $entry2->parentNode->removeChild($entry2); $oldchapter3 = $entry3->parentNode->removeChild($entry3); $dom->preserveWhiteSpace = false; } } } } $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->save("../$userid.xml") ?> How it works is when the user selects the items they want to remove, using a select box, the selections are put into the URL. My code extracts the titles from the URL, separated by "|^" (For example title1|^title2|^title3|^). Because the "|^" is appended to the end of each title, I have to remove the empty value from the array. Then I load a new DOMdocument, and find the titles from the URL in my existing XML document. Then I want the code to remove the whole items (titles, urls and the item itself) which have the same titles as the ones in the URL, and then save the document, but because some of the titles could have &, ", * or #, they don't get removed. Is there a way that I can maybe screen, and change the characters to get it to work (I tried this with "preg_replace", but it didn't work), or even change them before they're saved to the XML in the first place? Any advice?
  9. I'm trying to scan a directory and return a single specific folder,( the last one created) This is for a photo website and I would like to use images from current weeks images for the header images without having to upload them to a rotator folder. So here's where I'm at $dir = './This/2013/Goes to specific class of race/'; $files1 = scandir($dir); rsort($files1); print_r($files1); Returns all files in DESC order, including a photo.xml file generated by album builder, Array ( [0] => photos.xml [1] => 09_01_2012 [2] => 08_25_2012 [3] => 08_18_2012....ect,ect I want it to always ONLY return the NEWEST album folder, which in this example its ([1] => 09_01_2012) That's why I resorted into descending figuring the newest would always be on top of list. But I can not figure out how to JUST GET that single folder. ____________________________________________________________ Then I need to access that NEWEST folder and randomly select a .jpg file form it. If I manually insert the correct path I can get it to select a random file using this [/size][/font][/color] <?php //path to directory to scan $directory = "a/2013/direct/path/"; //get all files in specified directory $files = glob($directory . "*"); //print each file name foreach($files as $file) echo $file; } } ?> Above code with below code returns a random .jpg file, i CAN NOT GET THEM TO WORK COMBINED [color=#000000][font='Times New Roman'][size=1] [/size][/font][/color]/<?php // retrieve one of the options at random from the array $file = $files[rand(0,count($files))]; print_r($file); ?> I know very little about PHP, have done some CF coding but either way I hack my way through.... Any help or suggestions would be greatly appreciated, If you get me leaning the right direction, I can usually figure out the logic and complete it.... Hope I made sense to someone! LOL Steve
  10. Hello,I am new to here and apologise if this is posted in the wrong section, I would like to set the order that categories load within this script, basically i would like to load category ID 14 then 4 then 13. I have pasted my code below, if anyone can assist I would greatly appreciate it as I am pretty useless with PHP modifications! The output is a box within a wordpress site see attached image: http://ajswebsites.c...t.jpg ignore the bit at the bottom about the read morenot working that was something else that has been fixed! Thanks in advance. Let me know how I buy whoever a beer <?php function tie_home_tabs(){ $home_tabs_active = tie_get_option('home_tabs_box'); $home_tabs = tie_get_option('home_tabs'); $Posts = 5; if( $home_tabs_active && $home_tabs ): ?> <div id="cats-tabs-box" class="cat-box-content clear cat-box"> <div class="cat-tabs-header"> <ul> <?php foreach ($home_tabs as $cat ) { ?> <li><a href="#catab<?php echo $cat; ?>"><?php echo get_the_category_by_ID($cat) ?></a></li> <?php } ?> </ul> </div> <?php foreach ($home_tabs as $cat ) { $count = 0; $cat_query = new WP_Query('cat='.$cat.'&posts_per_page='.$Posts); ?> <div id="catab<?php echo $cat; ?>" class="cat-tabs-wrap"> <?php if($cat_query->have_posts()): ?> <ul> <?php while ( $cat_query->have_posts() ) : $cat_query->the_post(); $count ++ ;?> <?php if($count == 1) : ?> <li class="first-news"> <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?> <div class="post-thumbnail"> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"> <?php tie_thumb('',272,125); ?> <span class="overlay-icon"></span> </a> </div><!-- post-thumbnail /--> <?php endif; ?> <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2> <p class="post-meta"> <?php tie_get_score(); ?> <?php the_time(get_option('date_format')); ?> <?php comments_popup_link( __( 'Leave a comment', 'tie' ), __( '1 Comment', 'tie' ), __( '% Comments', 'tie' ) ); ?> </p> <div class="entry"> <?php tie_excerpt_home() ?> <a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Read More ยป', 'tie' ) ?></a> </div> </li><!-- .first-news --> <?php else: ?> <li> <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?> <div class="post-thumbnail"> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php tie_thumb('',60,50); ?></a> </div><!-- post-thumbnail /--> <?php endif; ?> <h3><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3> <p class="post-meta"> <?php the_time(get_option('date_format')); ?> <?php comments_popup_link( __( 'Leave a comment', 'tie' ), __( '1 Comment', 'tie' ), __( '% Comments', 'tie' ) ); ?> <?php tie_get_score(); ?> </p> </li> <?php endif; ?> <?php endwhile;?> </ul> <div class="clear"></div> <?php endif; ?> </div> <?php } ?> </div><!-- #cats-tabs-box /--> <?php endif; } ?>
  11. Hi all I have a function below that searches an array and assigns it to $totalmonthlycost. I need to know how I get the array key of the chosen array value ($m12 - $m60) How do I return the array key in the below code? $monthvalues = array($m12,$m18,$m24,$m30,$m36,$m42,$m48,$m54,$m60); function closest($monthvalues, $number){ #does the array already contain the number? if($i = array_search( $number, $monthvalues)) return $i; #add the number to the array $monthvalues[] = $number; #sort and refind the number sort($monthvalues); $i = array_search($number, $monthvalues); #check if there is a number above it if($i && isset($monthvalues[$i-1])) return $monthvalues[$i-1]; //alternatively you could return the number itself here, or below it depending on your requirements } $totalmonthlycost = closest($monthvalues, $idealcostpermonth); Thanks for your help. Pete
  12. hackalive

    Imap

    Hi guys, I am using PHP's IMAP functions to create a basic web-mail client to go with a dashboard I have. I am using imap_fetch_overview which it listing the emails nice and quick - but not in order of date recieved (newest first). How can I rectify this? Simply adding in an imap_sort before imap_fetch_overview seems to break the code and stop it from running the IMAP quiries. Any help is much appreciated - cheers.
  13. Hello, i have a question. I've recently started a website with videos, and I was looking for something like this. http://video.xnxx.com/tags/ . But i want to make a list with a to z. sorry for the link but this is basically what i'm looking for. ( My website is not based on porn ) so how to echo all the list form my table in the database. From videos Where title LIKE '%Funny%' as Funny Thanks.
×
×
  • 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.