Jump to content

alphanumetrix

Members
  • Posts

    167
  • Joined

  • Last visited

Everything posted by alphanumetrix

  1. Um... I never really figured out a solution using just SQL, but I re-did it with some PHP, and a modified table, now I have the same desired result. Since no one seems to know how to figure this out, I'll just close this as solved.
  2. notice how there are no duplicate series & it shows the maximum placement for each of those series, as well as it is ordered by date
  3. This code isn't exactly right... I need the ENTIRE row WHERE the max placement is, and the results have to be DISTINCT based on the SERIES... So I don't want any duplicate series...I basically just want the ENTIRE ROW where HIGHEST placement is from EACH series and order them by date.. Make more sense? The code you had gave me a result like this: max(placement) 12 13 13 13 24 13 25 45 26 25 The result I'm looking for is going to be like this: Series Placement date 314 12 December 30, 2009, 9:04 am 313 13 December 30, 2009, 9:02 am 312 13 December 30, 2009, 9:02 am 309 13 December 30, 2009, 8:59 am 306 24 December 26, 2009, 6:01 pm 307 13 December 26, 2009, 5:59 pm 308 25 December 26, 2009, 5:58 pm 303 45 December 26, 2009, 4:13 pm 41 90 December 26, 2009, 4:06 pm
  4. Nope, that's not what I'm looking for. I'm looking for the highest Placement of EACH series ordered by date.
  5. No one can help me with this??? I know of several alternatives to this problem, but I would MUCH rather do it with just this SQL statement.
  6. Yeah, no problem. I tried to keep it simple in my description above, because the design is a little more complex in actuality, because of the purpose of the website. Here is a dump of the two tables (not data actually added--i would, but the database has in excess of 10 thousand, so you can see why i didn't... & it's actually data that is not meant to be disclosed publicly): -- phpMyAdmin SQL Dump -- version 3.1.5 -- http://www.phpmyadmin.net -- -- Host: mysql1026.servage.net -- Generation Time: Dec 30, 2009 at 08:49 PM -- Server version: 5.0.85 -- PHP Version: 5.2.42-servage13 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `bliljerk10121` -- -- -------------------------------------------------------- -- -- Table structure for table `links` -- CREATE TABLE IF NOT EXISTS `links` ( `id` int(6) NOT NULL auto_increment, `placement` int(10) NOT NULL, `owner` int(10) NOT NULL, `date` text NOT NULL, `type` varchar(255) NOT NULL, `ext` varchar(255) NOT NULL, `size` int(6) NOT NULL default '0', `quality` varchar(120) NOT NULL default 'N/A', `link` text NOT NULL, `hits` int(10) NOT NULL default '0', `series` int(6) NOT NULL, `episode` varchar(50) NOT NULL, `details` text NOT NULL, UNIQUE KEY `id` (`id`), KEY `type` (`type`,`series`,`episode`), KEY `ext` (`ext`), KEY `size` (`size`), KEY `owner` (`owner`), KEY `quality` (`quality`), KEY `hits` (`hits`), KEY `placement` (`placement`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=10146 ; -- -------------------------------------------------------- -- -- Table structure for table `series` -- CREATE TABLE IF NOT EXISTS `series` ( `id` int(6) NOT NULL auto_increment, `date` varchar(255) NOT NULL, `published` int(10) NOT NULL default '1', `name` varchar(255) NOT NULL, `site` varchar(255) NOT NULL, `picture` text NOT NULL, `status` varchar(125) NOT NULL, `description` text NOT NULL, UNIQUE KEY `id` (`id`), UNIQUE KEY `site` (`site`), KEY `date` (`date`), KEY `name` (`name`), KEY `published` (`published`), KEY `status` (`status`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=315 ;
  7. Okay, so I have two tables... "series" & "links" Series Table looks like: id, name The links table looks like: id, placement, date, series Now I'm basically trying to get the latest links (latest means the highest "placement") for EACH series in order of the DATE of the link... What I've come up with is this, but it's not working at all: "SELECT MAX( placement ) AS max_placement, max( date ) AS max_date FROM links GROUP BY series ORDER BY max_date DESC LIMIT 0 , 30"
  8. Hey, I think we are working on the same (or at least a similar) project. Mark asked me to help you out. I am not sure how to do this with MySQL, but there are a couple ways of doing this using PHP. How many users are you working with?
  9. Hmm... If you are going to strip all the tags, then maybe you should try the "fgetss" function. Should be here: http://php.net/fgetss
  10. PCRE functions are slow & inefficient. Just try the DOMDocument parser (depending on your PHP configuration, you should be able to use it). *Note, parsing XML with DOMDoc. is also slow & inefficient, if there are better alternatives available... but this is definitely a better choice than PCRE from what you said. IE: function parseTagData( $tag, $xml, $single = false, $dir = true ) { $parser = new DOMDocument(); if ( $dir === true ) $parser->load( $xml ); else $parser->loadXML( $xml ); $data = $parser->getElementsByTagName( $tag ); if ( $single === false ) { $collected = array(); foreach ( $data as $d ) array_push( $collected, trim( $d->nodeValue, "\n" ) ); } else { $collected = $data->item(0)->nodeValue; } return $collected; } /* should print "title here" */ echo ( parseTagData( "h3", "file.html", true ) ); /* should print "first paragraph of text here - another one here - " */ $paragraphs = parseTagData( "p", "file.html" ); foreach ( $paragraphs as $p ) echo $p . ' - ';
  11. Are you running your site through an index (single file)? If so, just put the array in your main script, and all your files can have access to it. If you mean that you are creating an array for every user, a good idea would be to create a multi-dimensional array instead. IE of multi-dimensional array: $building_array = array( 'user1' => array('castle', 'storage', 'barracks', 'hospital', 'tower', 'inn'), 'user2' => array(1, 2, 3, 4, 5, 6) ); You can then access the data like this: echo $building_array['user1'][0]; // will display "castle" echo $building_array['user2'][0]; // will display "1" You can make the arrays more detailed by changing it like so: $building_array = array( 'user1' => array( 'castle' => 'some castle name', 'storage' => 'some storage name' ) ); echo $building_array['user1']['castle']; // will display "some castle name"
  12. You weren't kidding when you said it's big. You said it's only the one part giving you problems, right? Replace this part of the code: ////// BEGIN THUMBNAIL AND GALLERY CREATION... $imagenum++ ; $galleryname = $galleryname . $galnum . ".html" ; // Build full file name for gallery. $thumbfileread = opendir($thumbimages) ; // Read the file name of the thumb images. while($readthumb = readdir($thumbfileread)) { echo "$readthumb" ; } With this: ////// BEGIN THUMBNAIL AND GALLERY CREATION... $imagenum++ ; $galleryname = $galleryname . $galnum . ".html" ; // Build full file name for gallery. $thumbfileread = opendir($thumbimages) ; // Read the file name of the thumb images. $newarray = array(); while($readthumb = readdir($thumbfileread)) array_push($newarray, $readthumb); sort($newarray); foreach ($newarray as $n) echo $n; Battery is going to die any second, so I can't check it. But should fix it.
  13. Well, I can't do much with jus that bit of code. It doesn't even show the array you are storing the data in. In essence though, you typically have to give order to file results, by using sort(); IE: sort($array); Simple, no?
  14. I'll tell you the basics: never trust data from users, so always filter. It's considered tainted data. As far as the authentication goes IE: sessions/cookies. Make sure they can't be easily hijacked. IE: if you were allowing admins access by recognizing $_COOKIE['admin'] == 'admin' - then it could easily be hijacked via the URL using javascript: javascript:document.cookie='admin=admin'; Hope that helps some.
  15. Oh, well that's a completely different story. Neither of those will work for you. At least, not with the .php extension and <?php/?> tags (as file_get_contents renders what the server renders, so if the server can't recognize the php to parse, file_get_contents will display the php). Display the current PHP's source, would be a little more complicated. I would say the best way to do it, would be to open the file for reading, then echo out the contents in a textarea. Maybe like so: $filename = "CURRENT FILE HERE"; $h = fopen ($filename, "r"); $contents = fread ($h, filesize($filename)); fclose ($h); echo '<textarea cols=10 rows=20>' . $contents . '</textarea>'; See if that works... (don't forget to specify the file where I put "CURRENT FILE HERE")
  16. You don't need the single quotes. It'll work with/without/and with double quotes. As for the code, you need to echo out your $start to see what you're getting. At first glance, I don't think that algorithim of your's is going to work properly. Try this one instead: if($num_pages > 1){ $current_page = $start * $display; if($current_page != 1){ echo '<a href="test.php?s=' .$start.'&np='. $num_pages.'">Previous</a>'; } } I am really tired right now, but your algorithim looked like it would display a decimal if let alone, so that *would* be an invalid mysql resource if I'm right. As for the rest of your code, I'm too tired to even look at it...
  17. Well, what exactly are you trying to use it for? You know, it's for getting the source of a file, right? $var = show_source(__FILE__); echo $var; If you're trying to get the "actual" source-code of a file, try file_get_contents() instead. IE: $var = file_get_contents('http://google.com'); echo '<textarea cols=10 rows=20>' . $var . '</textarea>'; *I added the textarea, just so you can see what it actually displays; otherwise, it would have just shown a knock-off of google.
  18. The [0] & [1] are positions. You're using an associative array. All arrays, whether you realize it or not, must have a key. If you don't assign a key, PHP will autmatically assign them sequentially. I'm a little confused as to what you've wrote, so I'm just going to show how to randomize a query past the actual SQL (which should be used to the randomization actually, not this way): $results = array(); $query = mysql_query($sql, $connection) or die( 'Error: ' . mysql_error() ); while ( $row = mysql_fetch_array( $query, MYSQL_ASSOC ) ) array_push( $results, $row ); shuffle($results); print_r($results); // You'll see them in a randomized order now... Since your if/else statements make no sense whatsoever, I didn't put them in the example above. Basically, run a nice, clean, query. Then shuffle() your results (essentially does just that, randomizes the arrays' order).
  19. awesome banner. whoever made that haz mad skillz... *wink wink*
  20. Are you asking if it's safe? I would say probably yes. I would recommend defining a constant in the file you want this flatfile to run through though; then check if the constant isn't defined in the file, and kill the script if it is. That will prevent people from accessing it without your specific script. Script to run though: <?php define ('HeLLoPeOpLzZ', 1); ?> flatfile: <?php if ( !defined('HeLLoPeOpLzZ') ) die (''); ?> I think that's what you intend with the die() function, but I don't really understand how that works in your situation.
  21. That's not how I'd write it to begin with, but I figured I'd keep it to your style, in case you had a reason for doing so. This is how I'd do it: <?php session_register("breadcrumb"); if ( isset($_GET['pageNum_worksRS']) ) $breadcrumb = "index.php?pageNum_worksRS=" . $_GET[pageNum_worksRS]; elseif ( isset($_GET['category']) ) $breadcrumb = "workCategories.php?category=" . $_GET[category]; if ( isset($breadcrumb) ) $_SESSION['breadcrumb'] = $breadcrumb; ?> Tested it, and works...
  22. Well, a cheat way to use it would be to do as radi8 said, and then just define your $link variable as a global in your methods. However, I recommend you don't do this with classes. Instead, create a class for your database, and create a query method. Then, just query your DB through the method. Have the method require sql or something. Like this: $connection = new DatabaseClass(); /* ... */ $sql = "My SQL code here"; $connection->query( $sql );
  23. Can't edit my post again... but you need to change this: if ( $i > 1 ) $g = $i * 4; to this: if ( $i > 0 ) $g = $i * 4; Because 0 will be the general starting point for the array, it needs to be greater than the first, rather than the "actual" first, which is 1. edit: it's late, and i keep confusing myself, so I'm going to stop now... hope this works for you.
  24. edit: this won't work. need to change it. Edit again: Okay, I didn't test it, but this should work: $row = mysql_fetch_array( $result, MYSQL_ASSOC ); for ($i = 0; $i >= 0; $i++) { if ( $i > 1 ) $g = $i * 4; echo ' <tr> <td width="25%" align="center">' . $row[$i+$g]['prod_name'] . '</td> <td width="25%" align="center">' . $row[$i+1+$g]['prod_name'] . '</td> <td width="25%" align="center">' . $row[$i+2+$g]['prod_name'] . '</td> <td width="25%" align="center">' . $row[$i+3+$g]['prod_name'] . '</td> </tr>'; } not sure why "&#160;" is showing up in my for loop. I think you get what I mean though: for ( $i = 0; $i >= 0; $i++ )
  25. Try writing it differently: session_start(); if ( isset($_GET['pageNum_worksRS']) ) $breadcrumb = "index.php?pageNum_worksRS=" . $_GET['pageNum_worksRS']; if ( isset($_GET['category']) ) $breadcrumb = "workCategories.php?category=" . $_GET['category']; if ( isset($breadcrumb) ) $_SESSION['breadcrumb'] = $breadcrumb;
×
×
  • 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.