Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. You need to include the http:// part of the URL when referencing your files. Without it the browser is going to interpret your paths as being folders under your own domain so it is trying to load the jquery file from http://scitec-sportvoeding.nl/www.bamdaa.com/demo/metro-alert/js/jquery.min.js rather than http://www.bamdaa.com/demo/metro-alert/js/jquery.min.js as you intended. You can see this by checking your browsers error console
  2. I have no idea, never used it. Compile it and try it, probably wont take more than a few minutes.
  3. XDebug itself doesn't provide any kind of interface for actually interacting with the script. That is the job of a third-party client like your text editor or IDE. On the XDebug website they have a list of clients that will provide this functionality. In the list there is: If you're not using windows, then look at the list for other possible clients. If you feel comfortable with a compiler, the xdebug source package includes a simple client you can compile and use.
  4. Probably more likely is people debug with their IDE's but you said you don't want an IDE so there's not much to say. For step-through logic debugging I use PHPStorm with XDebug. For quicker informational debugging I just scatter some var_dumps around the code.
  5. Yes, you would add a new unique index to the database for that column. If you use phpMyAdmin to manage your DB I believe there is a icon you can click to add the index. Otherwise you can create it with the following sql create unique index ix_username on users (username)
  6. Your check for the duplicate username is more complicated that it needs to be. There i no need for a while loop at all, nor any need to compare $username to $checkusername, your query's WHERE clause already does that. Just run your query and see if a row is returned. $checkquery = "SELECT * from users WHERE username = ?"; $checkstmt = $db->prepare($checkquery); $checkstmt->execute(array($username)); $row = $checkstmt->fetchObject(); if ($row){ //username taken } else { //username available, do your insert } Rather than doing a select to check if the username is taken however, a better approach would be to create a UNIQUE constraint on the username column and then simply try to insert the data. If the insert fails, the most likely cause is the username is already taken. You could inspect the error code if you want to determine exactly why it failed and provide a different error message. $query = "INSERT INTO users (name, username, password, email, signupdate) VALUES (:name,:username,:password,:email,:signupdate)"; $statement = $db->prepare($query); $result = $statement->execute(array(':name'=>$name, ':username'=>$username, ':password'=>$password, ':email'=>$email, ':signupdate'=>date('m-d-Y H:i:s') )); if (!$result){ //failed query, username probably taken. }
  7. There are various ways you could do what you want, which is best kind of depends on the overall goal of the code and how much the first row would vary compared to the rest. One way is to just fetch the first row, then do your loop for the rest. $first=$result->fetch(); //Process first row while ($row=$result->fetch()){ //Subsequent rows } Another way is to use a flag which is handy if the processing changes only slightly. $first=true; while ($row=$result->fetch()){ if ($first){ $first=false; //first row stuff } //further processing } You could also just fetch all the results into an array then modify index [0] as necessary. $data = $results->fetchAll(); //do something with $data[0].
  8. Join with the appropriate tables and fetch their info. Select from the topics table to start then add the joins needed for the rest of the table. Use a LEFT JOIN rather than INNER JOIN when finding the latest post so that you still get the topic info if there is no comment. You can use the COALESCE function for the last post author vs topic author info.
  9. A composite index is just an index that covers more that one column. You create them the same as you would any other index, you just list multiple columns rather than one. When the table already exists and you are adding the index, I like to use the CREATE INDEX syntax. If you want to add the index to your CREATE TABLE statement you'd just add it at the end. CREATE INDEX IX_MostRecent ON comments (Topic, Date) CREATE TABLE IF NOT EXISTS `comments` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Content` text NOT NULL, `Date` datetime NOT NULL, `Topic` int NOT NULL, `Author` int(11) NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`), INDEX IX_MostRecent (Topic, Date) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  10. Your comments.Topic column needs to be changed to an INT type, not TEXT as you have it now. As for the last post query, what you do is write a query that returns the date of the newest post in each topic using GROUP BY and MAX(). Then you use that as a subquery and join to the comments table to find the details for the comment matching that date. Eg: SELECT c.ID, c.Content, c.Author FROM comments c INNER JOIN ( SELECT Topic, MAX(Date) as Date FROM comments GROUP BY Topic ) mostRecent ON c.Topic=mostRecent.Topic AND c.Date = mostRecent.Date You'll want a composite index on (comments.Topic, comments.Date) so that the sub query will run quickly.
  11. For PHP I've only been using an IDE (PHPStorm) for a few months now, prior to that I used just a simple text editor for years. For C I've been using MS's visual c++ ide for quite a while and only use a simple text editor when doing some fixes/testing on linux. In general I believe IDE's are a good tool and help a lot with developing things better and faster. One of the only real down-sides I've seen is that for people who begin with an IDE they end up never learning the language, they just learn the IDE. I've known people who can't code at all without their favorite IDE. I've even been slightly guilty of this with VB.NET, though that was a language I never really cared to learn I've just had to do a few minor fixes/enhancements in the past for projects. As far as the opinion that a language needs an IDE to even be used, I don't really agree with that. Thus far I've never encountered a language that I feel requires an IDE. Some languages are certainly easier with an IDE but not because of the language itself but rather the development process. For instance C and Java require compilation before running, so having an IDE that integrates that and lets you just hit "Run" is helpful. An integrated debugger is also very helpful. When you're dealing with a large project or with large libraries an IDE is certainly helpful. I've been recently learning how to use Symfony and the features of PHPStorm that allow quickly jumping around to class/method implementations, quick-view documentation, auto-generating interface stubs, etc have been invaluable for the learning process I feel. So, the TL;DR of my opinion is IDEs: - Quicker development - Bugs less likely due automatic validation - Helps with learning new libraries - Some people get dependent on them - Can be cumbersome for small projects Plain editors: - Force people to better learn the language and development process - Easier for small projects/one-off scripts - Possibly slower development.
  12. Building tree structures in PHP using references
  13. MS's manual says: In general, you shouldn't use num_rows to test if a query returned a result. Instead, check if the fetch returned anything useful. $result2 = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC); if (!$result2){ header('Location: index.html'); } else { }
  14. Why do you think you need vc6 builds of stuff? You can get vc9 version of apache from Apache Lounge to use with the vc9 PHP builds. Doesn't really matter how mysql was built since it doesn't integrate directly with Apache or PHP.
  15. My voter registration card says Democrat. In general I don't really care too much who a person is affiliated with though, what matters is how my ideals align with theirs. I tend to stay out of politics for the most part though, except during presidential election years.
  16. You'll likely need to use the odbc functions to connect to sql server 2000, or use an older version of PHP. The sqlsrv_* driver does not support less than 2005 according to the docs. The mssql_* functions were removed in php 5.3 since nobody was maintaining them and sqlsrv_* was better anyway.
  17. Mysql Reserved Words Long is a reserved word, so your query is failing due to that error. You need to either quote this column name with backticks or change the name to something else that is not reserved, such as 'Lng' or 'Longitude' PDO: Errors and error handling You're not inspecting for an error code, as such you are not seeing the error. If you want exceptions, you need to tell PDO to use exceptions by setting the PDO::ATTR_ERRMODE attribute to PDO::ERRMODE_EXCEPTION. You can set this attribute by either using the setAttribute method or by adding it to your parameters when constructing the PDO object, eg: $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
  18. If both databases are on the same server, then you can include the database name as a prefix when querying in mysql, for example: SELECT blah FROM databaseName.tableName If you are selecting essentially the same data from both databases you can do a UNION to combine two queries into a single result, eg: SELECT blah FROM databaseOne.tableOne UNION SELECT blah FROM databaseTwo.tableTwo Otherwise just issue two separate queries and read the results. If the databases are on different servers you'll need to open two connections.
  19. You are calling your cURL stuff regardless of the result of your validation. You need to move the curl stuff into the else block of your if (isset($error)) branch if (isset($_POST['submit'])){ //your validations if (isset($error)){ //display error } else { //your cURL stuff } }
  20. Not really, no. That said, node.js is probably not what you are thinking it is. It is an alternative server-side language environment and not something that helps you interact with browser's JS in any way. It's not going to make your jQuery/ajax stuff any easier to write, especially if you try and mix it with PHP.
  21. When it comes to your printing JS I would recommend you avoid the popup and instead replace the current page with just the image. For example: HTML gets setup like this <style type="text/css"> #printView { display: none; } body.print #printView { display: block; } body.print #buildView { display: none; } </style> <body> <div id="printView"><p>Hit CTRL+P to print</p><img id="printImage"></div> <div id="buildView">...current content...<button type="button" id="printButton">PRINT</button></div> </body> //Using jQuery for simplicity jQuery(function($){ $('#printButton').click(function(){ $('body').addClass('print'); var url = $('#bed').attr('src'); $('#printImage').attr('src', url); }); }); Fiddle demo When I tried the page in Chrome the print didn't do anything because chrome was blocking your popup window. Even after I enabled popups all I got was a blank window with no image. The above solution would work better and more consistently.
  22. In plog-includes/plog-functions.php there is this function: function is_allowed_extension($ext) { // return in_array(strtolower($ext), array('jpg', 'gif', 'png', 'bmp', 'mp4', 'wmv')); return in_array(strtolower($ext), array('jpg', 'jpeg', 'gif', 'png', 'bmp')); } That is probably what you need to modify to allow the psd extension, just add it to the list. That will allow you to upload the files at least, they won't be visible in the browser though unless you make more extensive changes to detect and convert them when uploaded.
  23. For a generic object that can hold any property you can use stdClass rather than that EmptyObject class. $object = new stdClass; $object->blah = 'blah'; If possible however, you should create an object that declares the individual properties that may be set. Some issues with the generic approach like above are- You may need to use isset() to prevent E_NOTICE errors when reading properties if you're not sure whether they were set yet - You get no help from an IDE for auto-complete of property names - You can't use type hinting to enforce a particular type of object For example: class SomeProperties { public $value; } class XClass { /** @var SomeProperties */ protected $data; public function __construct(StatusObject $status){ $this->data = new SomeProperties; $this->data->value = $status->value; } } If you want to make your code even stricter and prevent your structure objects from accepting anything other than the defined properties (possibly helpful to detect typos and such) you can do something like this: abstract class StructureObject { final public function __get($nm){ throw new Exception('Invalid property '.$nm); } final public function __set($nm,$v){ throw new Exception('Invalid property '.$nm); } } class SomeObject extends StructureObject { public $value; } With that, if you happened to make a typo like $object->valeu = 'blah'; you'd get an exception rather than it silently creating that property and possibly causing problems later on.
  24. Where are you getting this list of members from? If it's from a database then just add an ORDER BY clause to your select query and call it a day. Otherwise, you'll want to use usort() as shown above.
  25. Why would you think that? Just pass the users entered zipcode to the API and read the results. It'll do exactly what you want.
×
×
  • 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.