Jump to content
  • Who's Online   0 Members, 0 Anonymous, 155 Guests (See full list)

    • There are no registered users currently online

All Activity

This stream auto-updates

  1. Today
  2. Yesterday
  3. I'm sure there are many such libraries but this one has been used by many people: https://github.com/ddeboer/imap This one comes up as the most used in packagist: https://github.com/barbushin/php-imap
  4. This looks like homework .... I understand the idea, and it smells like a recursive exercise, which teachers love, and yet are rarely employed due to the huge overhead involved in building a functional stack. 2 things here: You have code that "looks" ok. Obviously you are having some problems with it, but you have no examples or debugging of what doesn't work Do you expect us to set up an environment and run your code and debug it for you? See #1. So in general, yes, I would say that yes, if this is an assignment, this is an exercise that should involve recursion. This code looks very suspect for a few reasons including that repeat is not shown to be initialized anywhere, and it should be local to the running function on the stack: $repeat = $repeat * $data[$i]['number']; Just off a quick browse of your code, you are trying to combine the reading of the array with the processing of a repeat/close_repeat. You want a recursive function that only handles the repeat/close cycle. So what you need in terms of variables is: index of global array temporary array built, which is return when function completes and is returned to be added to the finalized array. Inside your recursive function you can encounter 1 of 3 things: An entry which you add to your temporary array A repeat, where you calls the function recursively having advanced the start/end index an end_repeat where you duplicate the temp index the #repeat times and return it you increment the index internally, so you need to pass this by reference One trap you probably have is trying to control the other process with a for loop. What you actually want is a repeat--until pattern where you will process starting with index=0 until the index = count(array) -1. PHP does not have repeat/until but it does have do..while, so that is what your control should be based on. Hopefully this leads you to a solution, otherwise, again we need specific code, with your debugging and specific problems you are having with select sections of the code.
  5. I provided you a solution that should work. Just keep in mind that rules are processed in order. You need this "catchall" to come at the end/after all the other more specific rules or those other rules will never be reached. So you want: www rewrite rule specific pseudo directory rules like your news/ the catchall to *.php Just looking at where you are going with this, having a routing class and using a front controller pattern where you route everything through index.php which acts as a router, is essentially the direction you are taking your site from the look of it. You can make everything simpler and cleaner by either porting to symfony or laravel (which have many benefits in terms of access to all the other features of those frameworks) or just integrate some routing class into what you have. This looks like a possible solution for you: https://phprouter.com/ With that said there are myriad others, but that one appears to be functional, simple and minimal.
  6. The courses I mentioned in the other reply cover design and include layouts with flexbox and grid. https://scrimba.com/learn/flexbox https://scrimba.com/learn/cssgrid You want to keep in mind that your goal is to end up proficient with making "responsive layouts" so you should be at some point absorbing some of the ideas involved in how to have a design that adapts to device viewport. Of course you need to get down the basics first and then I think you can add in the elements that really make things responsive. Responsiveness involves a judgement call on your part... what things should shrink or be hidden at smaller sizes. When it's a mobile phone user, do you stack a menu or replace it entirely with a hamburger button? You figure these things out based on your preference. I mentioned Kevin Powell recently. Go through the free Scrimba course they have with him instructing. If you particularly like his style, then you might want to look at his paid courses. Some are free and some are paid either directly or through a Scrimba membership. In my opinion the Scrimba membership gets you the most bang for your buck, but he has a course on flexbox you can enroll in directly: See links to his various course at https://www.kevinpowell.co/courses/ Powell has this "free" course: https://courses.kevinpowell.co/conquering-responsive-layouts It is being done as a 21 day challenge, with new material being released day by day. The course is just being released now, and only has the first few days of content, but it could be a really good place for you to start. I personally like the idea of Scrimba for people learning as it gets you right to where you want to be within the courseware environment. It also has a very active Discord community you should join if you go the Scrimb route. You can also take the scrimba files and download them, fork your solutions etc, and they host all that for you. But of course for your own projects you need a local environment and code editor, and he is likely presenting that material in a local environment using Visual Studio Code and the "Live Server" extension. One nice thing about Visual Studio Code is that you can add the PHP Intelephense plugin and use it for your PHP development as well. Most pro PHP developers are using the PHPStorm commercial editor, but VSCode is the choice of javascript developers at this point, so if you're doing a lot of both, then VSCode + Intelephense is a good alternative. Powell's free responsive course has an early lesson on the environment and that might be helpful to you to see what he's using for his course.
  7. you have far too much code for this task. it is filled with repetitive logic, copying of variables to other variables for nothing, and while it is adding user/validation errors to an array, it isn't testing that array for the main activity of executing the INSERT query, which is why it is always inserting the new data values. i recommend that you start over, with just the logic you need - Keep It Simple (KISS) and Don't Repeat Yourself (DRY.) you should make one database connection in your main code, then supply it to any function that needs it, as a call-time parameter. you should use the much simpler and more modern PDO database extension. you should also use exceptions for database statement errors (the PDO extension always uses exceptions for any connection error and starting with php8 always uses exceptions for the rest of the statements that can fail - query, prepare, execute, and exec.) your post method form processing code should - detect if a post method form has been submitted keep all the form data as a set, in a php array variable trim all the input data at once. after you do item #2 on this list, you can trim all the data using one single line of code validate each input separately, storing user/validation errors in an array, using the field name as the array index after the end of the validation logic, if there are no errors (the array holding the errors will be empty), use the submitted form data as already stated, the correct way of determining if uniquely defined database columns/fields are duplicate, is to just attempt to insert the data and test if the query produced a duplicate index error number in the exception catch logic. for all other error numbers, just rethrow the exception and let php handle it. since you have more than one unique field, it is at this point where you would execute a (one) SELECT query to find which fields contain duplicate values. you would add error messages to the array holding the user/validation errors for each field that is found to contain duplicate values. after the end of post method form processing logic, if there are no errors, redirect to the exact same url of the current page to cause a get request for the page if you want to display a one-time success message, store it in a session variable, then test, display, and clear that session variable at the appropriate location in the html document. if there are errors at step #5 or #7, the code will continue on to display the html document, display any errors, redisplay the form, populating the fields with any existing form data. any dynamic value that gets output in a html context needs to have htmlentities() applied to it to help prevent cross site scripting.
  8. This refers to an sql statement as to the actual php in context of my question.. I really appreciate your input. But a little bit more help is needed as to my question..
  9. thank you for the example, ive managed to make it work. However, since i want to save attachments as well, isn't there any "known" library that has all these functions so i don't lose time to develop all these functionality? some sort of "Plug and play" library?
  10. Hello! I am making a shortcode to display photos the way I would like. And I can’t transfer photos from the slider plugin, can you tell me please? Here is my code: <?php $_rand = wp_rand(5); $thumbnail = isset($settings['image_size']) && $settings['image_size'] ? $settings['image_size'] : 'tevily_medium'; $post_id = $post['ID']; $ba_post = BABE_Post_types::get_post($post_id); $url = BABE_Functions::get_page_url_with_args($post_id, $_GET); $image = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $thumbnail); $image_srcs = wp_get_attachment_image_src( get_post_thumbnail_id( $post['ID'] ), $thumbnail ); $arr1 = array(); $arr2 = array(); $i=0; $babe_post = BABE_Post_types::get_post($post->ID); $files = isset($babe_post['images']) ? (array)$babe_post['images'] : array(); foreach ( $files as $file ) { if (is_array($file) && isset($file['image_id']) && $file['image_id']){ $image_full_arr = wp_get_attachment_image_src( $file['image_id'], $full ); $image_thumb_arr = wp_get_attachment_image_src( $file['image_id'], $thumbnail ); $arr2[i] = $image_thumb_arr[0]; $i++; } } $babe_post = BABE_Post_types::get_post($post->ID); ?> <section class="s-top-bunner b-zoom-gallery"> <div class="b-zoom-gallery_main"> <div class="b-zoom-gallery_main_big-image"> <img src="<?php echo esc_url($image[0]) ?>" alt="<?php echo esc_attr( $post['post_title'] ) ?>" class="image1"> </div> <div class="b-zoom-gallery_main_preview-images"> <div class="b-zoom-gallery_main_preview-images_entry"> <img src="<?php echo esc_url($arr2[0]) ?>" alt="<?php echo esc_attr( $post['post_title'] ) ?>" class="image1"> </div> <div class="b-zoom-gallery_main_preview-images_entry"> <img src="<?php echo $image_thumb_arr[0] ?>" alt=""> </div> <div class="b-zoom-gallery_main_preview-images_entry"> <img src="https://wow-paris.com/wp-content/uploads/2022/11/cocktails-top-1-e1668007709619.jpg" alt=""> </div> </div> </div> </section> I can only pass the featured image, but the slider array of photos does not work. ($image[0]) Here is the slider code: ** * Add unitegallery to booking_obj page. * @param array $post - we're looking for $post['images'] array here * @return string */ public static function block_slider($post){ $output = ''; $files = isset($post['images']) ? (array)$post['images'] : array(); if(!BABE_Settings::$settings['unitegallery_remove'] && !empty($files)){ $thumbnail = apply_filters('babe_slider_img_thumbnail', 'thumbnail'); $full = apply_filters('babe_slider_img_full', 'full'); // Loop through them and output an image foreach ( $files as $file ) { if (is_array($file) && isset($file['image_id']) && $file['image_id']){ $image_full_arr = wp_get_attachment_image_src( $file['image_id'], $full ); $image_thumb_arr = wp_get_attachment_image_src( $file['image_id'], $thumbnail ); $description = isset($file['description']) && $file['description'] ? ' data-description="'.$file['description'].'"' : '' ; $output .= ' <img src="'.$image_thumb_arr[0].'" /> '; } } //// end foreach if ($output){ $unitegallery_settings = BABE_Settings::$unitegallery; $js_arr = array(); foreach($unitegallery_settings as $key => $value){ if ($value === null){ $value_str = 'null'; } elseif ($value === true){ $value_str = 'true'; } elseif ($value === false){ $value_str = 'false'; } elseif (is_float($value) || is_int($value)){ $value_str = $value; } else { $value_str = '"'.$value.'"'; } $js_arr[] = $key.':'.$value_str; } $js = implode(', ', $js_arr); $add_class = !empty(BABE_Settings::$settings['content_in_tabs']) ? ' babe_slider_tabs_content' : ''; $output = ' <div class="babe_slider'.$add_class.'" id="unitegallery" style="display:none;"> '.$output.' </div> '; } } return $output; } Here is the slider call: public static function shortcode_item_slideshow( $atts, $content = null ) { global $post; $output = ''; if ( is_single() && $post->post_type == BABE_Post_types::$booking_obj_post_type) { $args = shortcode_atts( array( 'title' => '', ), $atts, 'babe-item-slideshow' ); $babe_post = BABE_Post_types::get_post($post->ID); $output .= BABE_html::block_slider($babe_post); } return $output; } Can you help me?
  11. Hello, I have an array that I want to transfer it into another format. The array look like: $data = [ [ "id"=>1, "type"=>"title", "data"=> "Title goes here" ], [ "id"=>2, "type"=>"repeat", "number"=>3, ], [ "id"=>3, "type"=>"media", "data"=> "path to media" ], [ "id"=>4, "type"=>"close_repeat" ], [ "id"=>5, "type"=>"repeat", "number"=>3, ], [ "id"=>6, "type"=>"title", "data"=> "Title goes here" ], [ "id"=>7, "type"=>"repeat", "number"=>2, ], [ "id"=>8, "type"=>"text", "data"=> "Text goes here" ], [ "id"=>9, "type"=>"close_repeat" ], [ "id"=>10, "type"=>"close_repeat" ], [ "id"=>11, "type"=>"cover", "data"=> "Cover data goes here" ], ]; And I want to transform it into: { "0": [ { "id": 1, "type": "title", "data": "Title goes here" } ], "1": [ { "id": 3, "type": "media", "data": "path to media" }, { "id": 3, "type": "media", "data": "path to media" }, { "id": 3, "type": "media", "data": "path to media" } ], "2":[ { "id": 6, "type": "title", "data": "Title goes here" }, { "id": 8, "type": "text", "data": "Text goes here" }, { "id": 8, "type": "text", "data": "Text goes here" } ], "3":[ { "id": 6, "type": "title", "data": "Title goes here" }, { "id": 8, "type": "text", "data": "Text goes here" }, { "id": 8, "type": "text", "data": "Text goes here" } ], "4":[ { "id": 6, "type": "title", "data": "Title goes here" }, { "id": 8, "type": "text", "data": "Text goes here" }, { "id": 8, "type": "text", "data": "Text goes here" } ], "5": [ { "id": 11, "type": "cover", "data": "Cover data goes here" } ] } The idea is that each object can appear once or multiple times. If an object comes between objects of type repeat and close_repeat then it should be repeated based on number:x. The problem is when the repeat is nested as in id=5 to id=10. Here it should be that id=6 appear once with two repeated id=8. But in total, this whole id=6 and id=8 (twice) should appear three times since the repetition at id=5 is 3. I hope this is clear. I tried using loops: public function dataTraversLoop($data, &$newData, $i){ $dataCount = count($data); if($i>=$dataCount){ return; } $objectIndex=0; for(;$i<$dataCount;$i++){ if($data[$i]['type']=='repeat'){ $objectIndex++; $repeat = $data[$i]['number']; $i++; for($j=0;$j<$repeat;$j++){ $tmpData = $data[$i]; $newData [$objectIndex][$j] = $tmpData; } } else if($data[$i]['type']=='close_repeat'){ $i++; $objectIndex++; } else{ $tmpData = $data[$i]; $newData [$objectIndex][] = $tmpData; } } } And also recursion: public function dataTravers($data, &$newData, &$repeat, $i, $objectIndex){ $dataCount = count($data); for( ; $i<$dataCount; $i++){ if($data[$i]['type']=='repeat'){ $repeat = $repeat * $data[$i]['number']; return $this->dataTravers($data, $newData, $repeat, $i+1, $objectIndex); } if($data[$i]['type']=='close_repeat'){ $repeat = 1; return $this->dataTravers($data, $newData, $repeat, $i+1, $objectIndex+1); } if($i >= $dataCount){ return $newData; } $tmpData = $data[$i]; $newData [$objectIndex][] = $tmpData; return $this->dataTravers($data, $newData, $repeat, $i+1, $objectIndex); $objectIndex++; }
  12. It only works with this trick SELECT movies.movieid, movies.title, movies.year, movies.imdbid, CAST ( SUBSTRING ( movies.title FROM '#(\d+)\.\d+' ) AS INT ) AS major, CAST ( SUBSTRING ( movies.title FROM '#\d+\.(\d+)' ) AS INT ) AS minor FROM movies WHERE movies.title ILIKE ('%$risultato%') ORDER BY major, minor and inserting this without any reference with the field (number, it does not exist in the query) <td><?php echo $row->numero; ?></td> in datatables "order": [[ 3, "asc" ]], Only in this way orders correctly, But I don't understand the logic, since the number does not exist πŸ™„ anyway thanks πŸ˜‰ result
  13. i believe you now, it is just hard to get away from the laptop before i have fixed my issue, if i do go away i just feel like i am wasting time .. but all in all i appreciated your help.πŸ˜„
  14. Like I said, sometimes you need to step away from the computer for a while. I really did mean to do that, you know. Wasn't even joking.
  15. dang thank you i dont know what i was thinking , and i might be tired .. how can someone be so blind πŸ˜‚
  16. I'm not talking about a column in a table. I'm talking about the PHP variable you have there called $voucher_code_in_transaction. Where is the line of PHP code that declares that variable?
  17. this variable is in in the transaction table , it is the collumn holding the voucher codes linked with their transaction
  18. but you are right this query effectively returns nothing ... i am lost again πŸ˜…
  19. Okay, now I'm done. $stmt->bind_param('s', $voucher_code_in_transaction); Where is the $voucher_code_in_transaction variable coming from?
  20. i just dont understand why it would not be working since i use the same setup to update the voucher table down below and it is getting updated, i could be using the value from the transaction of the transaction table but i preferred opting for the direct source of the funds instead of a kind of copy of the data.
  21. This might be one of those times when you should step away from the computer for an hour or so, get something to eat, watch TV, and come back to the code with a fresh pair of eyes. As a reminder, this works: $stmt = $con->prepare('SELECT request_receiver_id, request_receiver_name FROM transactions WHERE voucher_code_in_transaction = ?'); $stmt->bind_param('s', $_POST['voucher_code_in_transaction']); and this does not work: $stmt = $con->prepare('SELECT voucher_value FROM voucher_codes WHERE voucher_code = ?'); $stmt->bind_param('s', $voucher_code_in_transaction);
  22. in fact all other queries works perfectly vouchers and transactions are getting updated only the accounts query is stalling there. if i was setting a condition that avoid continuing the script if the accounts query isnt successful , i am pretty sure it would stop there
  23. yup this one works or it would not go through the rest of the code because of the condition right after
  24. Almost had my fun. This query works, right? $stmt = $con->prepare('SELECT request_receiver_id, request_receiver_name FROM transactions WHERE voucher_code_in_transaction = ?'); $stmt->bind_param('s', $_POST['voucher_code_in_transaction']); There's a big difference between the two of them.
  1. Load more activity
  • 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.