Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by denno020

  1. Good work. So from the looks of it you chose to use jQuery, at least that makes it nice and easy. As for your question about having to do it 10 times, no you don't. Instead of giving the button an ID of check, give it the class check, and then you can use that as the handler for the click Here is an example: <button class="check">Check</button> <script> $(".check").click(function() { var $button = $(this); //This is the button that was clicked on var $parentLi = $button.closest("li"); //Find the closest li parent, starting from the button, working up the DOM var value = $parentLi.find("input").val(); //From the li, work back down the DOM until an input field is found, and get the value of it }); </script> That's how you get the value out of the input field, then to display it, change the span ID of display to a class: <span class="display"></span> //using the variables from the previous code block, and therefore still inside the function for the click() var $displayField = $parentLi.find(".display"); //Starting from the parent li again, search down the DOM until an element with a class display is found $displayField.html(value+"<i class='fa fa-check'></i>"); //Set the value of the element that has the display class Obviously you'll use your if statements to display the check or cross appropriately. Don't get too worried about the way I've named my variables either. It's a notation that I've picked up through work. Having the $ at the start means it's a jQuery object, not a static value, but it doesn't matter how you name your variables. So provided each of your questions, answer fields and buttons are together in their own li, the code should work for however many you choose to have on the page. Let me know if you have any more questions. Denno
  2. I am about to go to bed, got notified on your reply just before I was about to shut down my PC, so to help, I will provide you with what you should search Google for. Ideally, I would suggest that you find some javascript tutorials on YouTube, users like Adam Khoury, mybringback, and JReam have fantastic tutorial series for beginners to follow. You're guaranteed to learn from their videos. As for your specific question, you will want to know these things from Google: "How to include jQuery" //Only if you choose to use the jQuery plugin, you could very well choose to use plain (vanilla) javascript "How to attach click handler to element with jQuery" //If you included jQuery above "How to attach click handler to element with vanilla js" //If you chose not to use jQuery "jQuery read value from input field" //if jQuery "javascript read value from input field" //if not "javascript addition" //This will be the same whether you choose to include jQuery or not. It's pretty much the same as other programming languages though "jQuery add element after another" //you will be looking for insertAfter() "vanilla javascript add element after another" If you can start with those searches, you should be able to figure out how to achieve your goal. If not, come back with the code that you try, and I, or someone else here, will be able to guide you further. The absolute easiest thing to do would be to choose to add jQuery to your project, and use the functions it provides, however using plain javascript will help you to understand what a plugin like jQuery does for you in the background. Hopefully that can get you started. Denno
  3. What javascript have you written? Are you using jQuery or vanilla javascript?
  4. I know this has been marked as solved, but just wanted to add that you don't have to go back to PHP and edit your data to get the behaviour you want. You could just do something like this: $.each(jsonData, function() { var titlePrinted = false; $.each(this, function(){ if (!titlePrinted) { //add the title titlePrinted = true; } //add the rest of the comment }); });
  5. Personally, I would use $.each() to loop through your output. Here is the code which will work: $.each(jsonData, function() { //Loop through each blog_id section $.each(this, function(){ //Loop through each comment in this blog_id output += Template.blog(this); //output the current comment }); }); example: http://jsfiddle.net/A3r7H/ Hope that helps Denno
  6. First step would be to debug whether clicking .del-action does anything. Open up the Network tab in either Chrome DevTools or Firebug (depening on the browser you're using), then click on the delete button. You should see the delete.php page show up in the network tab as soon as you press that button. The first thing I'm noticing is: $(function(){ }); inside $(document).ready(function(){ }); I'm not sure if that affects anything, or why you would need it.. Try changing your JS to: $(document).ready(function() { $(".del-action").click(function() { var commentContainer = $(this).parent(); var id = $(this).attr("id"); var string = 'id='+ id ; $.ajax({ type: "GET", url: "delete.php", data: string, cache: false, }); }); }); I think I've got the brackets right there.. :/ Oh and I think you should set up your data parameter in your ajax call like this data: {id: id} //don't use the string var But I may be wrong about that, it might work both ways..
  7. I'm struggling to follow exactly what you want here.. You keep saying about using a file from fork_folder if it exists, which keeps leading me back to using file_exists().. Like this: if (file_exists($fork_folder."/image.jpg")) { include/echo/return $fork_folder."/image.jpg"; } else { include/echo/return $main_folder."/image.jpg"; } If this isn't what you're after, then you'll have to try and explain the problem a bit better, because as I said, I'm struggling to follow exactly what you want..
  8. Nothing can be written better with globals. Does this mean that if main_folder() is called in a php file that is not inside a fork_folder directory, you want main_folder() to be replaced with fork_folder()? If that's the case, then you could use __DIR__ to find out the absolute path of the current PHP file, then search the path for a folder that you would expect to find in a fork_folder file, if it's not there, then that mean's you're not currently in one of the fork_folders, so switch main_folder() to fork_folder(), like: $currentDir = __DIR__; if (preg_match("/fork_folder_name/", $currentDir)) { fork_folder(); } else { main_folder(); }
  9. You could use a combination of is_dir() and file_exists() to determine if the $fork_folder/$fork_file exists.
  10. If you want to do it using an array, and provided your mysql results array looks like this $results = array( array( "blog_id" => "2", "content" => "Blog2Text", "comment_id" => "4", "comment_text" => "comment4text", ), array( "blog_id" => "2", "content" => "Blog2Text", "comment_id" => "7", "comment_text" => "comment7text", ), //etc. ) Then you can create your array like this: $outputArr = array(); foreach ($results as $result) { //Initialise array for the blog ID of the current $result, if it's not already done so if (!isset($outputArr[$result['blog_id']])) { $outputArr[$result['blog_id']] = array(); } //Append the comment_text for this result to the array for this blog_id $outputArr[$result['blog_id']][] = $result['comment_text']; } $output = json_encode($outputArr); Which will result in an output array looking like this: $outputArr = array( 2 => array( "comment4text", "comment7text", ) ); Hopefully that helps you out. Denno
  11. Shouldn't your while be $date < $closing_time
  12. Have you called your refresh function?
  13. How are you using str_replace? str_replace(' & ', ' ', $variable); Should do the job fine.. Grabbing the space from either side of the & symbol and replacing with 1 space will fix a problem if you simply find the & symbol and replace it with nothing.
  14. The first thing I notice is that the if statement doesn't seem to have it's closing curly brace? Apart from fixing that, there are 3 things I would check: 1. var_dump() as the very first thing in the constructor, this will tell you if the object is being instantiated or not (speaking of which, can you show us the code where you create a new validation class) 2. var_dump() is_store_closed() outside of the if statement, to make sure that's returning true. 3. var_dump() the $_SESSION variable, even though doing a var_dump of $this->store_name should display null. I think you problem is either you haven't created a new class properly (you can't just include the script, you actually have to call $validation = new validation() ), or you is_store_closed() function is returning false. Hope that helps. Denno
  15. Seeing as though $attr is being treated as an array (it's the variable used in the foreach), then you should initialise it to be an empty array, not an empty string. Also, you should indicate that the parameter has to be an array by adding 'array' before it: public function table_rows_and_columns(array $attr=array(),$data_name="",$data="") { Next, if $attr isn't always required, then you need to make it the last parameter in the function signature. These two calls: echo $table->table_rows_and_columns("Name:","<input type='text' name='name' id='name'>"); //First call echo $table->table_rows_and_columns("Phone:","<input type='number' name='phone' id='phone'>"); //Second call effectively do this: $attr = "Name:"; $data_name = "<input type='text' name='name' id='name'>"; $data = "" //First $attr = "Phone:"; $data_name = "<input type='number' name='phone' id='phone'>"; $data = "" //Second So as you can see, you're getting the error because the second two calls to your function don't pass an array as the first parameter. Have a crack at fixing the problem and let us know how you go. Then we can help you further if you need it. Denno Edit: oh and your line $row = "<tr><td{$key.'='.$value}>{$data_name} </td> <td>{$data}</td></tr>"; isn't in the foreach, so it won't use the $key and $value variables..
  16. Firstly, I like the message to the user if they're already in the database, but please, update "Your" to be "You're".. Anyway, to your problem. If you var_dump $query2, you'll see that it is actually false, which means you're doing count(false). which gives 1. Therefore, your if condition should be as such if ($query2 !== false) { } //OR if (!$query2) { } Hope that helps. Denno
  17. So I figured out what the problem was, in case anyone was wondering. I had a temporary URL, as I'm moving the website to a different hosting company, and it turns out that when I was reading the http_host in my php file, it was only pulling the ip address in, it wasn't also pulling in the my username which corresponded to my folder on their server. Anyway, that probably doesn't explain it very well, but it's all fixed now, so that's the main thing.
  18. Is this something like what you were after, http://jsfiddle.net/2ggL6/1/
  19. I've been using htaccess in my web projects for a little while now, both at home and at work. I'm currently working on a website for a friend, which is a wordpress one, and I'm trying to set up my htaccess in the root of my website which will handle old links, and forward people on the the new location (they previously had presta shop, which uses a different link structure). Anyway, I've got my public folder on my host, which has my htaccess, an index.php file, and a wordpress folder, which has all of the wordpress stuff. The plan was to capture links that weren't already going to a wordpress subdirectory, pass them to the index.php file, and then that will work out where the user should be redirected to. Sounds simple enough, but for whatever reason, it's just not working and I can't for the life of me figure out why. The following is my htaccess file: # Use PHP5.4 Single php.ini as default AddHandler application/x-httpd-php54s .php RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^((?!wordpress).)*$ index.php?url=$0 [QSA,L] So as you can see, it's very simple. The first few lines before RewriteEngine are specific for my host. Anyway, this works perfectly on my local server (wamp), however running it on my live server, I continually get "404:File Not Found". The index file is in the exact same location as the htaccess file, so there isn't any problem with that. I've also tried putting junk into my htaccess, to see if it's actually being used, and it is. If I put "some junk" (literally that string) into my htaccess just before the RewriteEngine on directive, I get this message: [an error occurred while processing this directive] So I know my htaccess is being read.. Can anyone see something that I'm missing? Thanks, Denno
  20. You have opened a connection to the database haven't you? I'm not sure if you get exceptions thrown if you try and execute a query without first selecting the database..
  21. That's what appears to have happened..
  22. Are you sure you're actually getting results from your SQL query? Have you got phpmyadmin or something similar that you can use to test your query? Also, can you post your code inside [ code ] tags, makes it much easier to read
  23. Then you'll need to add a var_dump($row);die(); just after $row is set, so you can have a look-see at what's actually in that array. Perhaps you're getting your index incorrect..
  24. Try this then: echo "<input id='FirstName' type='text' maxlength='20' name='FirstName' value='".$row['FirstName']."' pattern='^[a-zA-Z]{2,20}$' required /><br>"; Oh and don't change all of your input fields, just change one, until you get that one working, then apply the same changes to the rest. Will save you a tonne of time debugging Denno
  25. The way you are trying to print the value from $row is like this: $row[FirstName] It needs to be like this: $row['FirstName'] Notice the quotes. Easy to miss that because you have a tonne of single and double quotes going on in your code. Give that a try and see if it helps. Denno
  • 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.