Jump to content

Goldeneye

Members
  • Posts

    315
  • Joined

  • Last visited

    Never

Everything posted by Goldeneye

  1. I know the formats looked very similar but it did have to do with a different problem. The topic you provided in your reply had to do with getting the results of two tables using a join or subquery. The topic you deleted had to do with trying to retrieve the row with a the lowest (minimum) value (timestamp). (Although it was the same query).
  2. I'm just curious about why whenever I try to access the topic I created last night, I get, "An error has occured! This topic has either been deleted or is off limits to you" (or something to that effect). I have a copy of the topic that seemingly disappeared and I could post it again, but I'm curious why I can no longer access my topic. I didn't see anything in the pinned-topics pertaining to my problem *and* I followed the posting Guidelines for the MySQL Help forum. So my question is: Why is my topic now inaccessible? The editing URL for the topic is: http://www.phpfreaks.com/forums/index.php?action=post;msg=1320828;topic=278987.0
  3. Here's the structures of my two tables (using MySQL build 5.0.51a): CREATE TABLE `boardtopics` ( `topicid` int(10) unsigned NOT NULL auto_increment, `title` varchar(80) character set ascii NOT NULL, `board` int(11) NOT NULL default '0', `pinned` tinyint(1) unsigned NOT NULL default '0', `archived` tinyint(1) unsigned NOT NULL default '0', PRIMARY KEY (`topicid`,`board`), KEY `topiclist` (`board`,`archived`,`userid`), FULLTEXT KEY `topicsearch` (`title`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=26 ; CREATE TABLE `commentary` ( `associd` mediumint(10) NOT NULL, `input` longtext NOT NULL, `from` varchar(21) NOT NULL, `userid` mediumint(9) NOT NULL, `deleted` tinyint(1) unsigned NOT NULL default '0', `ip` bigint(10) NOT NULL, `time` bigint(10) NOT NULL, `type` tinyint(1) unsigned NOT NULL, PRIMARY KEY (`associd`,`userid`,`time`), KEY `type` (`type`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; What I'm trying to accomplish is to select the field-values `commentary`.`from` and `commentary`.`userid` of the row corresponding with MIN(commentary`.`time`). What I have attempted was this query... SELECT `topicid`, `title`, `pinned`, `from`, `commentary`.`userid`, MIN(`commentary`.`time`) as `created` FROM `boardtopics` JOIN `commentary` ON `commentary`.`associd`=`boardtopics`.`topicid` WHERE `board`=1 AND `archived`=0 AND `commentary`.`type`=4 GROUP BY `title` ORDER BY `pinned` DESC, MAX(`commentary`.`time`) DESC But it returns the field values `commentary`.`from` and `commentary`.`userid` corresponding with MAX(`commentary`.`time`). I tried ASC for "SORT BY MAX(`commentary`.`time`)" I'm just uncertain how to this. I've queried a search engine for tutorials but no useful results came up. So, how can I reverse this?
  4. Ah! That fixed the error. The only thing now is that each row from `boardtopics` is repeated "x" times where "x" is the number of posts (which are stored in `commentary`) in that topic. Edit: I fixed that, I grouped by `boardtopics`.`title` and it fixed that repetition problem. It appears to be work just as I want it to. Thank you, DavidAM!
  5. I'm using MySQL build 5.0.51a Here are the structures of my two tables CREATE TABLE `boardtopics` ( `topicid` int(10) unsigned NOT NULL auto_increment, `title` varchar(80) character set ascii NOT NULL, `creator` varchar(21) character set ascii NOT NULL, `created` int(10) unsigned NOT NULL default '0', `userid` mediumint(9) unsigned NOT NULL default '0', `board` int(11) NOT NULL default '0', `pinned` tinyint(1) unsigned NOT NULL default '0', `archived` tinyint(1) unsigned NOT NULL default '0', PRIMARY KEY (`topicid`,`board`), KEY `topiclist` (`board`,`archived`,`userid`), FULLTEXT KEY `topicsearch` (`title`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=26 ; CREATE TABLE `commentary` ( `associd` mediumint(10) NOT NULL, `input` longtext NOT NULL, `from` varchar(21) NOT NULL, `userid` mediumint(9) NOT NULL, `deleted` tinyint(1) unsigned NOT NULL default '0', `ip` bigint(10) NOT NULL, `time` bigint(10) NOT NULL, `type` tinyint(1) unsigned NOT NULL, PRIMARY KEY (`associd`,`userid`,`time`), KEY `type` (`type`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Intertable-relations would be: `boardtopics`.`topicid` corresponds with `commentary`.`associd` These tables are for a forum I'm working on. I've decided to minimize as many redundant columns as possible by using more complex (sub)queries and joins. What I'm trying to accomplish is select all the topics of a given forum (`boardtopics`.`board`) and sort them by the time of the last post in that topic (MAX(`commentary`.`time`)). What I have attempted was a JOIN... SELECT `topicid`, `title`, `creator`, `created`, `boardtopics`.`userid`, `pinned`, `closed`, `category`, `nws`, MAX(`commentary`.`time`) as `time` FROM `boardtopics` JOIN `commentary` ON `commentary`.`associd`=`boardtopics`.`topicid` GROUP BY `commentary`.`time` WHERE `board`=1 AND `archived`=0 ORDER BY `pinned` DESC, `time` DESC" I got the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `board`=1 AND `archived`=0 ORDER BY `pinned` DESC, `time` DESC' -- so then I attempted a subquery. SELECT `topicid`, `title`, `creator`, `created`, `boardtopics`.`userid`, `pinned`, `closed`, MAX(`commentary`.`time`) as `time` FROM `boardtopics`, `commentary` GROUP BY `topicid` WHERE `board`=1 AND `archived`=0 AND `commentary`.`associd`=`boardtopics`.`topicid` ORDER BY `pinned` DESC, `commentary`.`time` DESC And received this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `board`=1 AND `archived`=0 AND `commentary`.`associd`=`boardtopics`.`topic'
  6. It should -- in fact, it works perfectly on my local server running PHP 5.2.5. It worked on my remote server *before* it got upgraded from PHP 4.4.* to PHP 5.2.4. Well I queried the PHP error in a search engine and found a few relevent results. The only other explanation I can think of (that I found from querying a search engine) is that the server got reconfigured not to allow requests to access its files via a (seemingly) remote-HTTP-request. Or perhaps even that the request is being blocked by a firewall on the remote server.
  7. That does work, I might have to switch over to using that as much as I dread making all the changes through my scripts to use an absolute to point at my template files. I'm still curious about why using a URL in fopen() now results in a connection-timeout, though.
  8. I'm trying to access a local-file. I use an absolute-path, though such as "http://foo.bar/tpl/site_header.html"
  9. Hello! Here is the situation: The server I host my website on just upgraded it's PHP build from 4.4.* to 5.2.4. Not just PHP was upgraded, MySQL, postGres, and (I think) Apache were upgraded as well. Before the upgrade, my site worked perfectly. But now, whenever I access my site, it takes a long time to complete a request and all that is returned is "Warning: fopen(<THE_URL>) [function.fopen]: failed to open stream: Connection timed out in..." I know where the error is -- it's in my templating class. I check the remote server's configuration and the directive "allow_url_fopen is enabled and safe_mode is disabled. The strange thing is that my script works on my local server perfectly which is using PHP build 5.2.5. I looked for any differences between my local-server's PHPINFO() and my remote-server's PHPINFO() and, while I didn't find anything eye-catching yet, I noticed that virtual-directory-support is disabled on my remote-server and it is enabled on my local-server. Would that be what's causing the problem? If not, what are some potential causes for fopen() to behave this way?
  10. It's because you're overwriting the $file variable. You have to put the extension-less name in its own variable (which I will call $filename): Replace the current code in your foreach() loop with this: $pieces = explode('.', $file); array_pop($pieces); $filename = implode('.', $pieces); $thelist .= '<li><a href="'.$dir.''.$file.'">'.$filename.'</a></li>';
  11. As mikesta707 suggested, glob would be much easier to use. I should've suggested that in the first place but it was completely absent from my memory. Any way (according to what I comprehended from your explanation), it sounds like, you have to reset your variable before looping through each of the directories (BEFORE THE WHILE() LOOP): $thelist = '';
  12. Well, regarding the extensionless links: remove this from your scripts (I accidentally left this bit of code in there which I shouldn't have because it overwrites the actual filename) -- so remove this: $file = implode('.', $pieces); and that should work. Regarding your file-listing: Are you getting the results of both lists of filenames in your second include? What I mean by this: example... /misc/ -- file1 -- file2 -- file3 /gaming/ -- foo -- bar -- twix would be the structure; does your list from dlright.php look like this? -- file1 -- file2 -- file3 -- foo -- bar -- twix instead of just this (which is what you want)? -- foo -- bar -- twix
  13. I think I found the problem: Try this in your IF-condition: is_dir($dir.$file) === false I believe the problem is that is_dir() works from the directory in which the PHP script is working in. This means if you set your directory to read a subdirectory, the functions inside the loop will not act as if you're looking for files in the parent directory (of the subdirectory you're reading). Edit: Here is the script I used (I copied yours) which works on my server: <?php $thelist = ''; $dir = './downloads/'; $handle = opendir($dir); while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && is_dir($dir.$file) === false){ $pieces = explode('.', $file);array_pop($pieces); $file = implode('.', $pieces); $file_name = implode('.', $pieces); $thelist .= '<p><a href="'.$dir.''.$file.'">'.$file_name.'</a></p>'; } } closedir($handle); echo $thelist;?>
  14. Perhaps, you need to evaluate with an actual boolean value: if ($file != "." && $file != ".." && is_file($file)===true) ...or... if ($file != "." && $file != ".." && is_dir($file)===false) EDIT: As for removal of the file-extension -- it should be something like this: if ($file != "." && $file != ".." && is_file($file)) { $pieces = explode('.', $file); array_pop($pieces); $file_name = implode('.', $pieces); $thelist .= '<li><a href="'.$dir.''.$file.'">'.$file_name.'</a></li>'; } If you overwrite your variable like that, your Hyperlink will point to "/download/file" instead of "/download/file.ext"
  15. Maybe try is_file() instead of !is_dir(). I actually had a very similar problem when creating my templating system. I originally used !is_dir() and for some reason it still gave me directories. I tried is_file() and it worked just as I expected it to. Edit: Also, to remove the file-extension, something like this should suffice: <?php $pieces = explode('.', $file); array_pop($pieces); if(count($pieces) > 1) $file = implode('.', $pieces); ?>
  16. This should do: if ($file != "." && $file != ".." && !is_dir($file)) { $thelist .= '<li><a href="'.$dir.''.$file.'">'.$file.'</a></li>'; }
  17. unset($_SESSION["key"); should be unset($_SESSION["key"]); Your snippet was missing the closing "]" Also, use single quotes around your strings if that string does not contain a variable -- it's slightly faster.
  18. It's simple -- you can't put an entire PHP script inside a CSS background-property. You have to do something like this instead: <?php mysql_connect("localhost", "Master", "pword"); mysql_select_db("Login"); $salute = mysql_query("SELECT * FROM messages WHERE to_user = '$_SESSION[username]' ORDER by id DESC LIMI 1")or die(mysql_error()); while($record = mysql_fetch_array($salute)) { $new = $record['new']; } if ($new=="0") { $template = "http://www.testing.com/templatesmallnew.jpg"; } else { $template = "http://www.testing.com/templatesmall.jpg"; } ?> <style type="text/css"> .stacktemp a { display: block; width: 101px; height: 57px; background: url(<?php $template; ?>); } </style>
  19. What exactly are you looking to encode? Text? If you're looking to encode text, you will want to look at htmlentities and ini_set('default_charset', ...)
  20. This sort of thing is not possible without a database. Whether it's a flat-file database or a Structured-Query-Language Database, you need something to store the information for the games in. Also $_GET['id'] would be the I.D. of the row of the corresponding game in the database. So say you have an database table called `flashgames`: `id` `title` `path` 1 Game1 /games/1.swf 2 Game 2 /games/foo.swf 3 Game 3 /games/bar.swf So in your table, `id` would be the automatically generated I.D. number of the row, `title` would be the title of the game, and `path` would be the file-path to the game-file (flash games are usually in .swf). So then your script might look like this: <?php $id = $_GET['id']; $query = mysql_query("SELECT `title`, `path` FROM `flashgames` WHERE `id`=$id"); $row = mysql_fetch_assoc($query); echo $row['title']; echo '<br />'.$row['path']; ?> So, with those dummy code snippets, if $_GET['id'] = 2, you'd see "Game2" followed by "/games/foo.swf" on the line below "Game2"
  21. This part of your second query does not look right to me: SUBSTRING(postcode,0,2)='".$post."' You're comparing two values (20 = 20) against eachother which doesn't do anything in an SQL-query. instead, use this for your second-query: $result = mysql_query("SELECT SUBSTRING(postcode,0,2) From town WHERE `postcode`=2000"); Keep in my mind, I'm not sure if that'll work, but it's atleast syntactically correct.
  22. This is essentially an advice/correction forum. I think I understand what you want, but in order to give you any advice relevant to you, you'll have to post some code.
  23. Of course, the brackets! I always forget that those sort of things should be encased in brackets, as a subpattern. Thank you very, cags. On to my next obstacle, now.
  24. While I can't pinpoint your problem yet, I'm working on it -- I can give you some advice for better methods. 1) use mysql_num_rows (mysql_numrows has been deprecated and is not supported by newer versions of PHP) 2) instead of using mysql_result to tediously load the retrieved data into the script, use mysql_fetch_assoc or mysql_fetch_row. $rows = mysql_fetch_row($result); // to use the variables, you'd go $row['FIELD_NAME'] // or list($var1, $var2, $var3, $var4 ...) = mysql_fetch_row($result); // to use the data, you'd go $var1, etc. EDIT: Also, I just remembered, MySQL TIME-fields cannot hold a value greater than 838:59:59 or less than -838:59:59. This means, you have to resort to a different field-type.
  25. date only accepts Unix-Timestamps. You have to pass your date through strtotime -- like so: <?php $date_posted = 2009-11-25 22:14:25 $date_posted = strtotime($date_posted); date( "d/m/Y", $date_posted); ?>
×
×
  • 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.