Jump to content

maxxd

Gurus
  • Posts

    1,659
  • Joined

  • Last visited

  • Days Won

    52

Everything posted by maxxd

  1. What about the suggested code isn't working and how is it not working?
  2. You've got a syntax error and a couple logical errors in the code you've posted. Here's an example of what I think you're trying to do: function AutoPost() { $.ajax({ type: "POST", url: "<?php echo AJAX_URL; ?>", data:$('#lastviewer').serialize(), }).done(function(data) { if(data.success == true){ $("#lastviewer").html(data.processed) ; }else{ $('#lastviewer').html('<p>Sorry, there was an error</p>'); } }).fail(function(jqXHR, status){ $('#lastviewer').html('<p>Server error: ' + status + '</p>'); }); } <?php function doAjax($data){ $rnd = rand(0,2); if($rnd == 0 || $ret == 2){ $ret['success'] = true; $ret['processed'] = 'This is your data after processing'; }else{ $ret['success'] = false; } print(json_encode($ret)); die(); } ?> Obviously I'm skipping any actual processing and just checking a random number, but other than that... First off, your success() callback was improperly placed inside the AJAX object as opposed to chained to it. It's also been deprecated, so I've replaced it with the done() callback. Now, the done() callback will fire regardless the outcome of the php processing - as long as the AJAX object receives any legitimate return value(s), AJAX considers that success. So add a 'success' index to the return array that gets set to true if the php processes successfully or false if it doesn't, and check that in the done() callback before any processing takes place. Along those lines, you're going to want to check for server errors as well - that's where the fail() callback comes in. Using WordPress, your AJAX_URL constant is going to be a set path that resolves to /whatever_your_content_path_is/wp-admin/admin-ajax.php so don't set that as the action parameter of your form. WordPress will use the contents of the hidden 'action' field in your form to know what php function to call, as long as you've added the following lines in your functions.php file (assuming THEMEX_PREFIX is 'mine_'): add_action('wp_ajax_mine_update_user', 'doAjax'); WordPress uses a front-end pattern approach, so everything is going to go through index.php - just leave the action parameter of your form empty. That will hopefully get you pointed in the right direction and makes any sense at all and is close to what you were looking for...
  3. As Barand is suggesting, some simple error-checking can - and will - go a long way.
  4. Where are you instantiating $user_level and $active? I see them as query parameters for your select query, then they're assigned values returned from the the query, but they're not set before you use them in the bind_param() statement.
  5. You're missing quotes right and left, it looks like. Start with the line where you echo the timezone definition (any reason you're outputting that instead of actually defining the constant?) and go from there. If your code editor doesn't support syntax coloring, take a look at one that does - I think maybe Notepad++ does? The system I'm using at work doesn't have it installed and I can't remember off the top of my head.
  6. There's a few things going wrong in the code you've posted. First and foremost, you don't want to create buttons in the foreach() loop, you want to create options. The value of the option should be only $cal->cal_id, and there shouldn't be a link tag in there. Looking at your code, it looks like you want a listing of open time slots on each day, right? I'd recommend building a table listing the dates down the left, then having a drop-down with the open time slots for each of those days in a column to the right. A third column in the row with a submit button would be good - that way you don't have to write the onChange() javascript to submit the form when a time slot is chosen from the drop-down. Basically, each row is a separate form with the following hidden fields: dtstart (for the date), task (always going to be 'create', according to your code), and option (always going to be 'com_pbbooking' according to your code). Name the select element 'cal_id', and when you're creating the options (your foreach() loop), put $cal->cal_id in the value parameter. If you assign the action parameter of your form 'index.php' and the method parameter 'get', the form should work just like the link you posted originally once you click the 'submit' button next to the day you've selected. Obviously I've not tested this, but theoretically it should work.
  7. Personally, I'd go ahead and document the exception with a @throws tag because when another method calls that method, there's a chance it's going to have to catch and deal with the exception the child method throws. I guess there are arguments you could make depending on the visibility or scope of each of the methods, but I like my documentation thorough and have a bit of a tendency to overdo it some times.
  8. You'll need to add a submit button (which I incorrectly called a 'select button' in my last post) to submit the form to your processing script. You can do it via AJAX if you'd rather the page doesn't refresh.
  9. The structure is already there in what you've got, you just need to finesse it to a different output - create the form, get rid of the table-specific interior tags (tr, th, td), then convert your opening and closing table tags to a select element, and update your foreach() loop to print option elements. Add a select button and you should be good to go.
  10. Post your code here again in full so we can see what it looks like at this point.
  11. You're now overwriting the value of $countries with every iteration of the loop. You wanted the array, which is why I corrected that line in my post and pointed it out specifically in the description following the code block. $countries[$Ctry_info['CID']] = $Ctry_info['Country']; What this line is doing is creating an associative array ($countries) containing the country names as values with that country's database ID as the index. Like so: $countries[0] = 'United States'; $countries[1] = 'England'; $countries[3] = 'France'; $countries[4] = ... Also, if you have the <select /> element in your HTML, you don't need it again in your buildSelectOptions() function. At line 6, $Ctry_info doesn't exist yet - you don't define it until line 31, and this should be throwing an error. You're not looping through the array correctly in the buildSelectOptions() function - remember the country names are indexed by their ID's. so you need to use $id => $label, as in my earlier example. You're still assigning an unused variable with the wrong error message if there are no records returned from the database.
  12. I agree with Jacques1 on caching. While in some very specific situations caching can be a good thing, most times it's an enormous source of headaches. Think through your application, make sure you're gathering only the data you need for the page, write sensible queries, and make sure your database is well tuned and you'll be able to get by without caching 9.5 out of 10 times. Plus, debugging is easier because you don't have to clear you cache with every freaking change you make to the code before you refresh your browser.
  13. From the PHP documentation: $a !== $b Not identical TRUE if $a is not equal to $b, or they are not of the same type. Just in case the confusion was on the part of the comparison operator, not the WordPress function...
  14. Just got a chance to come back to this thread and realized you were using mysqli_*, not mysql_*. Sorry about that. One would think I would've learned by now not to post before my fourth cup of coffee in the morning...
  15. Couple changes and updates. This hasn't been tested and I'm still only on my second cup of coffee, but give it a shot and let us know how it goes. <?php //don't use short tags to open your file - not all servers recognize them and it's bad pracatice include("AddStats_admin_connect.php"); //connect to database doDB(); //Function to build select options based on passed array function buildSelectOptions($options) { $optionsHTML = ''; foreach($options as $id => $label) { $optionsHTML .= "<option value='{$id}'>{$label}</option>\n"; } return $optionsHTML; } //Run query to get the ID and Name from the table //Then populate into an array $clist_sql = "SELECT CID, Country FROM Countries"; $clist_res= mysqli_query($mysqli, $clist_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($clist_res) < 1) { //this Country not exist - actually, the user hasn't selected a country yet so this is just an empty result set, not user error. $display_block = "<p><em>You have selected an invalid Country.<br/>Please try again.</em></p>"; //Also, you do nothing with $display_block, so why set it? } $countries = array(); while($Ctry_info = mysqli_fetch_array($clist_res)) { $countries[$Ctry_info['CID']] = $Ctry_info['Country']; } $countryOptions = buildSelectOptions($countries); ?> <!DOCTYPE html> <html lang="en"> <head> <title>Stats</title> <link rel="stylesheet" href="stylesheets/style.css" /> <!--[if IE]> <script src="http://html5shim.goo...5.js"></script> <![endif]--> </head> <body> <!-- Deleted the echos and the many, many line breaks --> <!--Later in the HTML for the page --> <form action="Ctrystats.php" method="post"> <!-- You need to set up the select element to house the options. This will be set in $_POST as $_POST['country'] --> <select name="country"> <?php echo $optionsHTML; ?> </select> <input type="submit" value="Submit Choice"> </form> </body> </html> Other things: Don't use the mysql_* functions. They were deprecated about a decade ago and will be removed from php at some point in the future. Look into PDO and prepared statements. When posting code to the board, please use the code formatting button (< > in the toolbar) - it preserves whitespace and tabs, which makes everything easier to read. Take a close look at line 27 - the closing square bracket for the $countries array was misplaced and has been moved. Hope that helps a little.
  16. Turn on error reporting - white screens are typically fatal errors in the php that aren't being displayed to screen. Put error_reporting(-1); ini_set('display_errors',true); at the top of your file.
  17. Also, make sure that php is enabled on your server.
  18. The five separate media queries shouldn't matter. Create a media query with 'max-width=largest width that shouldn't display the effect' and turn off the visibility. Any resolution below that will not display the effects. I think (don't quote me on this one - I haven't tested it) if you make the main class (.float-shadow) display:none; and visibility:hidden; you shouldn't have to adjust anything for the children - the dipslay:none removes the element from the DOM.
  19. SELECT pts.cashReward ,pts.pointsReward ,COUNT(ip.id) AS iptsCount FROM pts INNER JOIN ignored_pts AS ip ON pts.id = ip.ptsId' AND ip.user = :username AND ip.id = :id WHERE pts.signupsAvailable > 0 AND pts.status = "active" AND pts.id = :id Completely untested, but I think it should get you there.
  20. I haven't delved into traits too much yet, so I can't speak to that, but composition could work in much the same way. Instead of inheriting from a common Product parent class, though, the disparate child classes would implement a Product interface. Then you can use Product as a type hint, and the base class still couldn't care less what specific product it's working with or how it works, as long as the product classes are coded to the interface's contract. So all products have a getPrice() method defined in the interface, but ProductA and ProductB return a straight number while ProductC, ProductD, and ProductE all perform complicated mathematical equations to arrive at their prices. The using class doesn't care, 'cause it knows it can simply call $this->product->getPrice() and $this->product will do whatever it needs to and return the price. That being said, you could combine this idea with the inheritance pattern described by Jacques1 quite easily to corral any common functionality between product suites as necessary and override and/or expand the base product functionality in some or all of the leaf classes.
  21. And, in all honesty, you don't have to use inheritance. A composition-style setup would be doable as well. Granted, it might take a bit more thought and work at the outset, but it would be less coupled and potentially easier to modify if the need arises.
  22. If that's the case, you can use multiple levels of inheritance. For instance, create the abstract Product() class, extend that in the ProductGroupA() class, then extend that for each product in group A. Do the same for group B, C, etc. You'll create the new middle class based on the similar functionality. Because everything is extending from the base Product() superclass, you can use that as a type hint in your code and everything will work. If I'm not mistaken in the labels, it's kind of a combination of both factory and strategy patterns.
  23. You could create a folder with the desired name, then insert an index.php file into that folder. So, if you want http://www.mydomain.com/gallery/pictures you'd place index.php inside the pictures directory, which is inside the gallery directory, which is in your webroot. Then make the links point to the directory, not the actual file.
  24. I don't know what framework you're using, but I'd do an else on the Input::exists() and Token::check(Input::get('token')) if's to see if that's where it's barfing. If not, it may be the DB methods - again, hard to tell without knowing what you're using. I don't see any egregious typos or anything like that, though...
  25. It'd be easier to help if we knew what we were looking for. What's it doing? What's it not doing? Are there any errors?
×
×
  • 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.