Jump to content

jodunno

Members
  • Posts

    259
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by jodunno

  1. again with these arrays? you'll never learn, eh? I think that array merge will fail you here with these demands and array combine will throw an error due to the key length mismatches. I can only guess that you are trying to preserve the order of array 11, id est, the key 1 not following 0. I also assume that you want the 10 key moved to array 2 1 key. This is really not how one should code arrays. I can only suggest bad coding practices in an attempt to solve your problem but i may not be understanding you correctly. Very vague. I have a way to mix the arrays but it is not professional coding methods by any stretch of the imagination. Yes i'm saying that the following code is bad. Meantime, the final key can be printed to the screen but outside of the loop. Inside of the loop would require an array count and a counter to find the end of the loop. <?php echo <<<RAYS <html> <head> <title></title> <style> div.raybox { display: block; position: static; width: 20em; height: 18em; vertical-align: top; background: #101010; border-radius: 8px; box-sizing: content-box; overflow: hidden; } div.ray { display: inline-block; position: relative; margin: 4px; padding: 4px; width: 9em; height: 94%; vertical-align: top; background: #000000; color: rgba(240, 240, 240, 0.6); box-sizing: content-box; } </style> </head> <body> RAYS; $aRay = (array) [0 => (array) [0 => "a", 1 => "b", 2 => "c", 3 => "d", 4 => "e", 5 => "f", 6 => "g", 7 => "h", 8 => "i", 9=> "j"], 1 => (array) [0 => "a", 1 => ""]]; $bRay = (array) [0 => "1.1.51", 2 => "1.1.51.2", 3 => "1.1.51.3", 4 => "1.1.51.4", 5 => "1.1.51.5", 6 => "1.1.51.6", 7 => "1.1.51.7", 8 => "1.1.51.8", 9 => "1.1.51.9", 1 => "1.1.51.10", 10 => "1.1.52"]; echo '<div class="raybox">'; echo '<div class="ray">aRay:<br>'; foreach ($aRay as $key => $array) { foreach ($array as $index => $value) { echo '[' . $key . '][' . $index . '] => ' . $value . '<br>'; } } echo '</div>'; echo '<div class="ray">bRay:<br>'; foreach ($bRay as $index => $value) { echo '[' . $index . '] => ' . $value . '<br>'; } echo '</div>'; echo '</div>'; $aRay[1][1] = array_pop($bRay); $stingRay = array (); array_push($stingRay, $bRay); array_push($stingRay, $aRay[0]); array_push($stingRay, $aRay[1]); //echo '<br>'; //print_r($stingRay); //echo '<br>'; //foreach ($stingRay as $key1 => $array) { // foreach ($array as $key2 => $value) { // echo $value . '<br>'; // } //} echo '<br>'; foreach ($stingRay[0] as $key => $value) { echo $value . ': '; echo $stingRay[1][$key] . '<br>'; } echo $stingRay[2][1] . ': ' . $stingRay[2][0]; echo <<<RAYS </body> </html> RAYS; ?> the output is what you are seeking, i think. Otherwise, i would say build a new array with array 11 values as keys in the new array. Then add array 2 values (letters) as values for the new array keys. Then add the last key value pair to the new array. Then you could loop over one array printing keys and values to obtain your objective. I'm ashamed to post this awful code but that is how twisted this concept is becoming. Really try to recode your project correctly and these problems disappear.
  2. yes, i know what you mean and it is a complicated network. I decided to scan neighbors while building a grid array so that i know which connections can be made. This data will be useful in path determinations, especially with a second array holding broken connections awaiting validation. But your code is splendid and works around the problem differently. I will try to get my code done soon. The weekend is coming. Woohoo 🙂
  3. have you looked at the code provided by Elvium? I am aware of the definition of scalable but the individual disconnected tiles in his code are breaking like table cells in Firefox 1. My suggestion is to place the rectangles in a single svg, which is what you have done in your grid code. However, i also recommend creating only two possible doors: bottom and right. Your code is very nice, as usual. Great job. I do not care for the database storage but it is well implemented. You are a master coder. I'm still using my free time to finish my grid but my son is back in school now. I have a little less time in the day. Also, today i had some time but i was leaving my flat and i stumbled across an old man with his pants pulled down and saw a pee puddle on the floor. I was pretty mad. Minus details, he said he was in my building to visit the attorney upstairs. I said, in German language, "German is not my native language and i can read the sign on the front door that the attorney's office is closed". I added "Das ist nicht in Ordnung." What a crappy day. Who enters a building and urinates on the floor? The bad part about the story is that a different attorney was contacted by Police (instead of Police coming when i called them to come). The attorney seemed strangely nonchalant about the matter. I exploded and threw some expletives her way and warned her against continuing to talk in my direction. Needless to say, my free time is much less today. What is wrong with people nowadays? Anyway, I am storing intelligence about the grid in arrays, which can be used in JavaScript if it is to be a game (neighbors, borders, corner tiles, median tiles, distance calculations, etc). Elvium should appreciate your code. Nice work!
  4. Hi Elvium, I've been busy lately. My Son starts school again and i'm back to sleeping 5-6 hours per day during the week. Anyway, I have finally completed a center finding algorithm and it is working well. I decided to focus on the svg. Now i have never studied svg, so i have alot to learn about designing images using svg code. I think that your concept of doors is problematic when you handle them as top left bottom and right stubs that are connected with each svg output to the browser. Multiple svg images is also problematic because if one shrinks the browser window then the tiles are no longer connected. I've been wanting to create a single svg with only bottom and right doors. I've finished the code days ago but i've been working on implementing it with a php loop. Calculating the coordinates is not too difficult. However, i made an svg smiley instead of text and that was difficult to calculate. I have spent the last two days of free time building it and calculating it's position. The following code is simply html with the single svg method as an example of what mean with top bottom left and right causing problems. I do not see that the 'doors' are being used in any way other than perception. So why not switch to bottom and right, which will be easier to enable and disable in code. single svg <html> <head> <title></title> </head> <body> <svg width="270" height="180" xmlns="http://www.w3.org/2000/svg"> <rect width="80" height="80" x="0" y="10" rx="10" ry="10" fill="#333" /> <rect width="10" height="20" x="80" y="42" rx="0" ry="0" fill="#444" stroke="#333" stroke-width="4" /> <rect width="80" height="80" x="90" y="10" rx="10" ry="10" fill="#333" /> <rect width="10" height="20" x="170" y="42" rx="0" ry="0" fill="#444" stroke="#333" stroke-width="4" /> <rect width="80" height="80" x="180" y="10" rx="10" ry="10" fill="#333" /> <rect width="20" height="10" x="30" y="90" rx="0" ry="0" fill="#444" stroke="#333" stroke-width="4" /> <rect width="10" height="20" x="80" y="130" rx="0" ry="0" fill="#444" stroke="#333" stroke-width="4" /> <rect width="80" height="80" x="0" y="100" rx="10" ry="10" fill="#333" /> <rect width="20" height="10" x="120" y="90" rx="0" ry="0" fill="#444" stroke="#333" stroke-width="4" /> <rect width="10" height="20" x="170" y="130" rx="0" ry="0" fill="#444" stroke="#333" stroke-width="4" /> <rect width="80" height="80" x="90" y="100" rx="10" ry="10" fill="#333" /> <rect width="20" height="10" x="210" y="90" rx="0" ry="0" fill="#444" stroke="#333" stroke-width="4" /> <rect width="80" height="80" x="180" y="100" rx="10" ry="10" fill="#333" /> </svg> </body> </html> again, i have programmed his single svg into php because coordinates and dimensions need to be dynamically calculated.
  5. I would not design a site in such a manner. I would recognize the errors in my ways and fix them. 'been there, done that' is a common expression that applies here. But because you asked: <?php $p_id='1.1.51|||1.1.51.2|||1.1.51.3|||1.1.51.4|||1.1.51.5|||1.1.51.6|||1.1.51.7|||1.1.51.8|||1.1.51.9|||1.1.52|||1.1.52.2'; $Q_Id = explode('|||', $p_id); $m = count($Q_Id); $theme = 'b|||c|||d|||e|||f|||g|||h|||i|||j|||k'; $sub = explode(',', $theme); $sub = explode('|||', $sub[0]); $sub2[] = 'a'; $sub = array_merge($sub2, $sub); $n = count($sub) - 1; //print_r($Q_Id); echo '<br>'; //print_r($sub); echo '<br>'; $j = 0; $k = substr($Q_Id[0], 0, 6); for ($i = 0; $i < $m; $i++) { $index = substr($Q_Id[$i], 0, 6); if ($index !== $k) { $j = 0; $k = substr($Q_Id[$i], 0, 6); echo '----- looky here ' . $k . '<br>'; } echo $Q_Id[$i] . ': ' . $sub[$j] . '<br>'; $j++; } ?> I do not understand why you have these ids in a variable. You should store them in an array by an index system so that you know when to start back at the letter a. However, the English alphabet runs out of letters at 26 so do you plan on having a solution for that too? Do you see how such code leads us down a dark spiraling vertex of madness? a black hole. Even light cannot escape this madness. Change your code as soon as possible. Meantime, good luck with all of that and goodnight. I am in a different timezone and it's almost bedtime. edit: to avoid more questions, $k has been set to the value of array key 0.
  6. what kind of train wreck code is that? holy and moly and mother of godsmack. so with the limited splatter that you have provided along with empty array values (id est, value ||| value, ), we can only do so much to help you out. <?php $p_id='1.1.51|||1.1.51.2|||1.1.51.3|||1.1.51.4|||1.1.51.5|||1.1.51.6|||1.1.51.7|||1.1.51.8|||1.1.51.9|||1.1.52|||1.1.52.2'; $Q_Id = explode('|||', $p_id); $m = count($Q_Id); $theme = 'b|||c|||d|||e|||f|||g|||h|||i|||j|||k'; $sub = explode(',', $theme); $sub = explode('|||', $sub[0]); $sub2[] = 'a'; $sub = array_merge($sub2, $sub); $n = count($sub) - 1; //print_r($Q_Id); echo '<br>'; //print_r($sub); echo '<br>'; $j = 0; for ($i = 0; $i < $m; $i++) { if ($Q_Id[$i] === '1.1.52') { $j = 0; } echo $Q_Id[$i] . ': ' . $sub[$j] . '<br>'; $j++; } ?> you really must stop using count in a loop. For the love of PHP just make a variable to hold the count. Also, i need glasses because my eyes are getting bad with age but i still can't read your code because of the lack of spaces. Add dome spaces to make it more legible. Your code is like a messy room. Yakety Yak! Take out the papers and the trash ...
  7. let us clarify: tourney is your table name, correct? $groupno = '$group1', $linkno='$link1' = you cannot update a variable with a variable. you are supposed to be updating a column with new data. you are supposed to select a db column by name, which is to be updated with the variable referenced to by the placeholder. could you show us a bit more details about your database tables?
  8. switching to pdo is a wise decision but you forgot to switch your query code as well ($sql) $pdo = new pdo("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=$DB_ENCODING",$DB_USER,$DB_PASS,$options); $sql = 'UPDATE tourney SET groupno = :group, linkno = :link WHERE id=1'; $conn = $pdo->prepare($sql); $conn->execute(array(':group' => $group1, ':link' => $link1)); groupno = :group groupno needs to be the name of the column in the database which is to be updated likewise for linkno. :group is a named placeholder for the $group1 variable (protects against sql injection attacks). likewise for linkno. report back.
  9. Hi Elvium, so now you think that I'm stupid. LOL. I've done that but my point is that you have a predictable method of disabling 'doors'. When i set the variable to false, the grid reverts to a full grid after a certain amount of clicks on top of predictability (which simply moves left-to-right in many sequences, thus defying randomness.) see my attached image of the false setting and the full grid. (cityblocks1 .jpg) The mathematical algorithms mentioned early can help solve your problems. We do not have a true grid here and it is not weighted with vertices, so many algorithms will not function well. However, it is a cross between a city block map with streets (doors) and a maze. Which is why the manhattan distance (taxi cab) and A* algorithms will work to help with the maze like obstacles of your dead-ends. You don't have to think of anything new, just convert algorithms to php and output data that fits your code (a bit more tricky). I only have so much time per day to work on my grid code. Today i started calculating a central axis and center tiles . I've also added corner tiles- vide cityblocks2.jpg attachment. I'm preparing to integrate A* algorithm but i want to read a bit more about maze generating algorithms for a better trapping/obstacle layout. I'm not a math guru so it am a bit slow. Anyway, i'm just trying to help you succeed in the best possible way. Predictability is not good when we are talking randomness. rand is not a truly random algorithm, which leaves us with mathematical methods.
  10. are you having trouble setting up a databse, accessing the database and hashing a password? let's play squeakyToys and build a basic process for you to follow: after you make a database with a table and columns in your database software and insert the appropriate data in the columns: $dbHost = (string) '127.0.0.1'; //127.0.0.1 == localhost $dbName = (string) ''; //your database name $dbUser = (string) ''; //your database software user name $dbPass = (string) ''; //your database software password $dbAttr = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC); $dbConnect = new PDO("mysql:host=$dbHost; dbname=$dbName; charset=utf8mb4", $dbUser, $dbPass, $dbAttr); $dbQuery = 'SELECT user_id, user_pass FROM user_table WHERE user_name = :post_username'; $dbPuppy = $dbConnect->prepare($dbQuery); $dbPuppy->execute(array(':post_username' => $username)); //$_POST['username'] $squeakyToy = $dbPuppy->fetch(); //$squeakyToy['user_id']; //$squeakyToy['user_pass']; //$squeakyToy is a variable that holds the data from the SELECTED database column. here user_id and user_pass //the most common variable names = $field, $row, $result //verify that $_POST['password'] hash matches database user_pass hash for the SELECTed user_name if (password_verify($post_password, $squeakyToy['user_pass']) === true) { //if match is true then the user is now logged in } hash your new password, id est, stop using your now public domain password of 'fredpeabody', and store that hash in your database user_table. example code to show how it works (which does not belong on your publicly accessible website😞 <?php $formPass = "joDunn02024"; $showHash = password_hash($formPass, PASSWORD_BCRYPT); echo $showHash; ?> then you will store the output from $showHash in the user_pass column associated with your username. And don't use fred, peabody, body or pea in your new password, in any lettercase. Even with a full stop interjection (fred.peabody) And all users of your site require a unique user name and a password. Stop sharing your password with people. You're supposed to be the site admin for cryin' out loud. And what is wrong with you? LOL. hopefully, you don't write your banking pin number on your forehead so that you don't forget it. Even backwards. Joke: Another error is using Ubuntu over Mint or OpenSuse. Try one of those distros, then your script will work again 🙂 Honestly, you must at least allow php to process the form on the server side where client users cannot see the processing code. only use javascript as minimal client-side form validation before submitting (such as checking on submit for empty fields, maximum/minimum character violations etc.)
  11. Hi Elvium, The new code script works better than your original script in the original post (no broken paths and no 'walking in circles') but the code often produces the same results for several page loads (not very random). I reloaded the page 5 times and the grid didn't change. You could calculate borders and neighbors very easily and use a function to walk around the grid in search of problems and code solutions to any problems. I have detected borders and neighbors since my last post and even added diagonal neighbors in case the grid would be changed to allow diagonal movements. I've added a function to return opposite directions (north returns south). I've also added a Manhattan distance function and it works well. I wonder what you are building: a game, a path finding exercise or something else? ultimately classes would be better for this project. Imagine calling new grid(), new trap(), new monster() etc. Not necessary in development mode, of course, but a better idea in production. Anyway, if you are happy with your new code, then i suppose that this thread is closed. Otherwise, let us know if you need further assistance. I am going to keep working on my own grid code because i find my grid handling code useful in many ways. Plus, i am intrigued by the mathematics behind path finding. Very fascinating.
  12. I'm trying to avoid rudeness but this post does not belong in a PHP coding thread, since it is clearly a third party reinventing the wheel css implementation problem. The third party css implementation is called Tailwind. I have no interest in reading about Tailwind or the other thing that you mentioned. But have you tried troubleshooting? like change object-contain to object-none or object-fill to see what happens. <img id="modal_image_{{ $comment->id }}" src="" class="w-full h-full object-none" /> empty source tag is interesting. Are you using Javascript to set the source? I'm old school: src="image.ext" and be done with it. tailwindcss.com/docs/object-fit "Use the object-contain utility to resize an element's content to stay contained within its container. Use the object-fill utility to stretch an element's content to fit its container. Use the object-none utility to display an element's content at its original size ignoring the container size." <img class="object-none h-48 w-96 ..."> opinion: css and overlays/modals are not so difficult to warrant a third party re-invent the wheel implementation. example using JavaScript which only requires an on-click event to work. Just pass a menu option integer. function OverlayMenusYay(cardinalOpen) { encodeURIComponent(cardinalOpen); switch (cardinalOpen) { case 1: x.style.display = "block"; x.style.width = "100%"; x.style.height = "100%"; x.style.opacity = "0.4"; break; case 2: y.style.display = "block"; y.style.width = "100%"; y.style.height = "100%"; y.style.opacity = "0.4"; break; } return; } function OverlayMenusNay(cardinalClose) { encodeURIComponent(cardinalClose); switch (cardinalClose) { case 1: x.style.display = "none"; x.style.width = "0%"; x.style.height = "0%"; x.style.opacity = "1"; break; case 2: y.style.display = "none"; y.style.width = "0%"; y.style.height = "0%"; y.style.opacity = "1"; break; } return; } style.opacity to make the background less visible. You can even use CSS3 to create tool tips on hover of the close button x.
  13. users of WordPress and LiteSpeed Cache plugin should be aware of a privilege escalation vulnerability. https://www.bleepingcomputer.com/news/security/litespeed-cache-bug-exposes-millions-of-wordpress-sites-to-takeover-attacks/ recommendation: Update LiteSpeed Cache to version 6.4 or later. Best Wishes, John
  14. so you haven't replied in weeks . I assume based upon your post that you just want to remove the loading bar and display successfully loaded message, yes? <html> <head> <title>5 sec div</title> <style> @keyframes loading { from { opacity: 1; } to { opacity: 1; visibility: hidden; } } @keyframes loaded { from {opacity: 0;} to {opacity: 0;} } .loadingbar { max-width: 100px; border: solid 1px #c0c0c0; } .loading { animation: 5s linear loading; opacity: 0; } .loaded { animation: 5s linear loaded; } .load { position: absolute; top: 0 px; left: 0 px; padding: 8 px; } </style> </head> <body> <div class="load loading loadingbar">Loading ...</div> <div class="load loaded">Successfully Loaded</div> </body> </html>
  15. I did some research last night and i stumbled across grid path algorithms in connection with grid games, which could help you determine a path. Mathematicians have created these algorithms so there is no need for us to re-invent the wheel. http://qiao.github.io/PathFinding.js/visual/ so you must decide if you want to use a path algorithm or if you want to use the tile numbers (re-invent the wheel) to calculate with basic arithmetic (neighbors would require more calculation to avoid misplacing traps and blocking a valid path). i've set up the grid with random start and goal nodes which can be passed to an algorithm (which requires adding this code to the grid build and display code) <?php // Grid settings $maxColumns = (int) 3; $maxRows = (int) 4; if ($maxColumns < 3 || $maxColumns > 10 || $maxRows < 3 || $maxRows > 10) { //screen width must be a factor print 'Please change your mapsize'; exit; } // Images (Icons) $iconMonster = '&#129430;'; // Shows a dinosaur $iconTreasure = '&#127873;'; // Shows a gift $monsters = ceil($maxRows * $maxColumns * 0.15); $treasures = floor($maxRows * $maxColumns * 0.25); $svgSize = 100; $fontSize = $svgSize * 2; // Build the full grid with all information $grid = array(); $displayGridArray = (int) 1; $paths = array(); $trapSize = ceil(($maxColumns * $maxRows) / $maxRows - 1); $availableTiles = $maxColumns * $maxRows - ($trapSize + 2); //create random start and goal nodes $nodes = array(); $nodes['start']['icon'] = '&#128578'; $nodes['start']['row'] = mt_rand(1, $maxRows); $nodes['start']['column'] = mt_rand(1, $maxColumns); $nodes['goal']['icon'] = '&#128274'; $nodes['goal']['row'] = mt_rand(1, $maxRows); $nodes['goal']['column'] = mt_rand(1, $maxColumns); while ($nodes['goal']['column'] === $nodes['start']['column']) { $nodes['goal']['column'] = mt_rand(1, $maxColumns); } //build and display the grid $tileCounter = 0; for ($i = 1; $i <= $maxRows; $i++) { for ($j = 1; $j <= $maxColumns; $j++) { $tileCounter++; $grid[$i][$j]['tile'] = $tileCounter; $grid[$i][$j]['exits'] = null; $image = '<svg width="'.$svgSize.'px" height="'.$svgSize.'px" fill="#333" xmlns="http://www.w3.org/2000/svg">'.PHP_EOL; $image .= '<title>tile: '.$grid[$i][$j]['tile'].'&#xA;row: '.$i.'&#xA;column: '.$j.'</title><rect width="80%" height="80%" x="10%" y="10%" rx="5%" ry="5%" />'.PHP_EOL; // Center square if ($i === $nodes['start']['row'] && $j === $nodes['start']['column']) { $image .= '<text x="50%" y="50% "textLength="100%" font-size="'.$fontSize.'%" dominant-baseline="middle" text-anchor="middle">'.$nodes['start']['icon'].'</text>'.PHP_EOL; } if ($i === $nodes['goal']['row'] && $j === $nodes['goal']['column']) { $image .= '<text x="50%" y="50% "textLength="100%" font-size="'.$fontSize.'%" dominant-baseline="middle" text-anchor="middle">'.$nodes['goal']['icon'].'</text>'.PHP_EOL; } if ($i > 1 && $i <= $maxRows) { /* north,top */ $grid[$i][$j]['exits'] .= 'north'; $image .= '<rect width="20%" height="10%" x="40%" y="0%" />'.PHP_EOL; } if ($j > 1 && $j <= $maxColumns) { /* west,left */ $grid[$i][$j]['exits'] .= (!empty($grid[$i][$j]['exits']) ? ', ' : '') . 'west'; $image .= '<rect width="10%" height="20%" x="0%" y="40%" />'.PHP_EOL; } if ($i < $maxRows) { /* south,bottom */ $grid[$i][$j]['exits'] .= (!empty($grid[$i][$j]['exits']) ? ', ' : '') . 'south'; $image .= '<rect width="20%" height="100%" x="40%" y="90%" />'.PHP_EOL; } if ($j < $maxColumns) { /* east,right */ $grid[$i][$j]['exits'] .= (!empty($grid[$i][$j]['exits']) ? ', ' : '') . 'east'; $image .= '<rect width="10%" height="20%" x="90%" y="40%" />'.PHP_EOL; } $image .= '</svg>'; echo $image; } echo '<br>'.PHP_EOL; } if ($displayGridArray) { echo '<p>'; $k = 1; foreach ($grid as $row => $association) { $l = 1; foreach ($association as $column => $data) { echo 'row ' . $k . ', column ' . $l; foreach ($data as $label => $info) { echo ', ' . $label . ': ' . $info; } echo '<br>'; $l++; } $k++; } echo '</p>'; } echo 'total tiles: ' . $tileCounter . '<br>'; echo 'start node: ' . $nodes['start']['row'] . ':' . $nodes['start']['column'] . ' tile ' . $grid[$nodes['start']['row']][$nodes['start']['column']]['tile'] . '<br>'; echo 'goal node: ' . $nodes['goal']['row'] . ':' . $nodes['goal']['column'] . ' tile ' . $grid[$nodes['goal']['row']][$nodes['goal']['column']]['tile'] . '<br>'; echo 'traps: ' . $trapSize . '<br>'; echo 'available tiles = ' . $availableTiles . ' (minus traps, start and goal nodes)<br>'; ?> now you just have to place the monsters and treasures into columns not belonging to start and goal nodes, calculate a path or possible paths, place traps not interfering with atleast one valid path from start to goal and remove the exits that create the traps.. i also created a variable for displaying the grid array for development purposes. let us know if you have problems finishing the code.
  16. I'm trying to build this program myself in spare time but i out of time for now. I have added the "doors" and documented them in the array. <?php // Grid settings $gridWidth = 3; $gridHeight = 4; $svgSize = 100; // Images (Icons) $iconExit = '&#128274;'; // Shows a lock $iconMonster = '&#129430;'; // Shows a dinosaur $iconStart = '&#128578;'; // Shows a smiley $iconTreasure = '&#127873;'; // Shows a gift // Calculate Monsters $monsters = ceil($gridHeight * $gridWidth * 0.15); // Calculate Treasures $treasures = floor($gridHeight * $gridWidth * 0.25); // Make iconBox and shuffleBox $iconBox = array_merge( array_fill(1, $treasures, $iconTreasure), array(1 => $iconExit), array_fill(1, $monsters, $iconMonster), array(1 => $iconStart) ); $shuffleBox = $iconBox; shuffle($shuffleBox); /* Build the full grid with all information ///////////////////////////////////////////////*/ $grid = array(); for ($i = 1; $i <= $gridHeight; $i++) { for ($j = 1; $j <= $gridWidth; $j++) { $grid[$i][$j]['top'] = $grid[$i][$j]['left'] = $grid[$i][$j]['bottom'] = $grid[$i][$j]['right'] = 0; $image = '<svg width="'.$svgSize.'px" height="'.$svgSize.'px" fill="#333" xmlns="http://www.w3.org/2000/svg">'.PHP_EOL; $image .= '<rect width="80%" height="80%" x="10%" y="10%" rx="5%" ry="5%" />'.PHP_EOL; // Center square if ($i > 1 && $i <= $gridHeight) { /* top */ $grid[$i][$j]['top'] = 1; $image .= ' ' . '<rect width="20%" height="10%" x="40%" y="0%" />'.PHP_EOL; } if ($j > 1 && $j <= $gridWidth) { /* left */ $grid[$i][$j]['left'] = 1; $image .= ' ' . '<rect width="10%" height="20%" x="0%" y="40%" />'.PHP_EOL; } if ($i < $gridHeight) { /* bottom */ $grid[$i][$j]['bottom'] = 1; $image .= ' ' . '<rect width="20%" height="100%" x="40%" y="90%" />'.PHP_EOL; } if ($j < $gridWidth) { /* right */ $grid[$i][$j]['right'] = 1; $image .= ' ' . '<rect width="10%" height="20%" x="90%" y="40%" />'.PHP_EOL; } $image .= '</svg>'; echo $image; } echo '<br>'; } //echo '<br>'; print_r($grid); //echo '<br><br>'; $k = 1; foreach ($grid as $row => $association) { $l = 1; foreach ($association as $column => $connection) { foreach ($connection as $door => $status) { echo 'row ' . $k . ', column ' . $l . ', ' . $door . ' door: ' . $status . '<br>'; } $l++; } $k++; echo '<br>'; } ?> Now you just need to think of a path algorithm which needs documented coordinates. Once you have a path, that doesn't involve randomly disabling doors which require checking for broken paths, you can then loop over the necessary connections to disable them as well as display the surprise items. I've removed a few unnecessary variables and comments from the code. I'll try to wok on a path algorithm along side of your path algorithm ideas and we'll see if we can solve your problems. Unless, someone else beats us to it...
  17. I wonder why you do not want to build a grid and cut a path at the same time as well as build an array to track the grid. You could easily create the grid and a grid array in one fell swoop. <?php // Grid settings $gridWidth = 5; $gridHeight = 5; $svgSize = 100; $svgColor = '#333'; $svg['center'] = '<rect width="80%" height="80%" x="10%" y="10%" rx="5%" ry="5%" />'; // Images (Icons) $iconExit = '&#128274;'; // Shows a lock $iconMonster = '&#129430;'; // Shows a dinosaur $iconStart = '&#128578;'; // Shows a smiley $iconTreasure = '&#127873;'; // Shows a gift // Calculate Monsters $monsters = ceil($gridHeight * $gridWidth * 0.15); // Calculate Treasures $treasures = floor($gridHeight * $gridWidth * 0.25); // Make iconBox and shuffleBox $iconBox = array_merge( array_fill(1, $treasures, $iconTreasure), array(1 => $iconExit), array_fill(1, $monsters, $iconMonster), array(1 => $iconStart) ); $shuffleBox = $iconBox; shuffle($shuffleBox); // Build the full grid with all information $grid = array(); for ($i = 1; $i <= $gridHeight; $i++) { for ($j = 1; $j <= $gridWidth; $j++) { $grid[$i][$j] = 'content'; $image = '<svg width="'.$svgSize.'px" height="'.$svgSize.'px" fill="'.$svgColor.'" xmlns="http://www.w3.org/2000/svg">'.PHP_EOL; $image .= ' '.$svg['center'].PHP_EOL; // Center square $image .= '</svg>'; // Close SVG echo $image; // Show image } echo '<br>'; } //echo '<br>'; print_r($grid); //echo '<br><br>'; $k = 1; foreach ($grid as $row => $association) { $l = 1; foreach ($association as $column => $data) { echo 'row ' . $k . ', column ' . $l . ': ' . $data . '<br>'; $l++; } $k++; echo '<br>'; } ?> your code seems to contradict the doors because the doors are not being used in anyway other than creating paths around a random maze. I think that this is somewhat like the old Atari game Haunted House (one of my favs.) Anyway, you could write a make path algorithm and build the doors from there, which would now only be bottom or right. I think that you are overthinking. Even better is to use mathematics to design the grid and path but it is not necessary.
  18. I thought that you wanted every square to be connected, which is what i changed. I looked at your code again and i see what you are doing: the smiley is the start and the lock is the exit. The walking in a circle is doors that should be broken but all columns should not have four doors. Still, i wouldn't program it this way but it's your code. we get a better view of what is happening when we print the contents of your field array. Take a look at the array, if you have time. take a closer look at yourcheck each field = connected code. echo '<br><br>'; foreach ($field as $row => $colArr) { foreach ($colArr as $col => $door) { echo '<table cellspacing="2" cellpadding="2" border="1" width="400"><tr><td bgcolor="#f0f0f0" width="100">row</td><td bgcolor="#f0f0f0" width="100">col</td><td bgcolor="#f0f0f0" width="100">door</td><td bgcolor="#f0f0f0" width="100">content</td></tr>'; foreach ($door as $direction => $content) { //echo 'row: ' . $row . ', col: ' . $col . ', door: ' . $position . ', item: ' . $item . '<br>'; echo '<tr><td>' . $row . '</td><td>' . $col . '</td><td>' . $direction . '</td><td>' . $content . '</td></tr>'; } echo '</table>'; } } echo '<br><br>'; where is the text 'content' coming from in this array? i have yet to locate the source. meantime, row -1 is curious since that would be row 0 and there is not a row 0 (for row = 1).
  19. I have tested the original script with my border control hack and the grid is complete without other changes to your script. Hopefully, this tweak solves your problems. complete script with border hack and comment around the hack.: <?php // Start Sessie //session_start(); // Map settings $mapWidth = 5; $mapHeight = 5; $squareSize = 70; $squareColor = '#333'; // Content settings $monster = '&#129430;'; $treasure = '&#127873;'; $start = '&#128578;'; $exit = '&#128274;'; // Make SVG files $fontSize = $squareSize * 2; $svg['center'] = '<rect width="80%" height="80%" x="10%" y="10%" rx="5%" ry="5%" />'; $svg['right'] = '<rect width="10%" height="20%" x="90%" y="40%" />'; $svg['bottom'] = '<rect width="20%" height="10%" x="40%" y="90%" />'; $svg['left'] = '<rect width="10%" height="20%" x="0" y="40%" />'; $svg['top'] = '<rect width="20%" height="10%" x="40%" y="0%" />'; // Function to count the values in a field function count_values($arr) { $counting = 0; foreach ($arr as $key => $val) { if (is_numeric($val)) { $counting = $counting + $val; } } return $counting; } // Calculate Monsters $monsters = ceil($mapHeight * $mapWidth * 0.16); // Calculate Chests $chests = floor($mapHeight * $mapWidth * 0.24); // Check map size if ($monsters == 0 || $chests == 0 || ($monsters + $chests + 2) > ($mapHeight * $mapWidth)) { print 'Please change your mapsize'; exit; } // Create content $squareChests = array_fill(1, $chests, 'treasure'); $squareMonsters = array_fill(1, $monsters, 'monster'); $squareStart = array(1 => 'start'); $squareEnd = array(1 => 'exit'); // Merge and mix all content $fillbox = array_merge($squareChests, $squareMonsters, $squareStart, $squareEnd); shuffle($fillbox); /******************************\ Start Grid Map \******************************/ // Build column for ($row=1; $row<=$mapHeight; $row++) { // Build row for ($col=1; $col<=$mapWidth; $col++) { $randomSquare = array(); while (count_values($randomSquare) < 1) { // Default settings $squareMaxTop = 1; $squareMaxLeft = 1; $squareMaxBottom = 1; $squareMaxRight = 1; // Top row has never a door at top if ($row == 1){ $squareMaxTop = 0; } // First column has never a door at left if ($col == 1){ $squareMaxLeft = 0; } // Last row has never a door at the bottom if ($row == $mapHeight){ $squareMaxBottom = 0; } // Last column has never a door at the right if ($col == $mapWidth){ $squareMaxRight = 0; } $randomSquare = array( 'top' => rand(0, $squareMaxTop), 'right' => rand(0, $squareMaxRight), 'bottom' => rand(0, $squareMaxBottom), 'left' => rand(0, $squareMaxLeft), ); } $field[$row][$col] = $randomSquare; } } /******************************\ Check each field = connected \******************************/ foreach ($field as $row => $colArr) { foreach ($colArr as $col => $door) { // Check top door is connected with previous top field $previousTop = $row - 1; $field[$previousTop][$col] = isset($field[$previousTop][$col]) ? $field[$previousTop][$col] : NULL; if ($field[$previousTop][$col] != NULL) { $field[$row][$col]['top'] = $field[$previousTop][$col]['bottom']; if (count_values($field[$row][$col]) < 1) { $field[$row][$col]['top'] = 1; $field[$previousTop][$col]['bottom'] = 1; } } else { unset($field[$previousTop]); } // Check right door is connected with next right field $nextRight = $col + 1; $field[$row][$nextRight] = isset($field[$row][$nextRight]) ? $field[$row][$nextRight] : NULL; if ($field[$row][$nextRight] != NULL) { $field[$row][$col]['right'] = $field[$row][$nextRight]['left']; if (count_values($field[$row][$col]) < 1) { $field[$row][$col]['right'] = 1; $field[$row][$nextRight]['left'] = 1; } } else { unset($field[$row][$nextRight]); } // Check bottom door is connected with next bottom field $nextBottom = $row + 1; $field[$nextBottom][$col] = isset($field[$nextBottom][$col]) ? $field[$nextBottom][$col] : NULL; if ($field[$nextBottom][$col] != NULL) { $field[$row][$col]['bottom'] = $field[$nextBottom][$col]['top']; if (count_values($field[$row][$col]) < 1) { $field[$row][$col]['bottom'] = 1; $field[$nextBottom][$col]['top'] = 1; } } else { unset($field[$nextBottom]); } // Check left door is connected with previous left field $previousLeft = $col - 1; $field[$row][$previousLeft] = isset($field[$row][$previousLeft]) ? $field[$row][$previousLeft] : NULL; if ($field[$row][$previousLeft] != NULL) { $field[$row][$col]['left'] = $field[$row][$previousLeft]['right']; if (count_values($field[$row][$col]) < 1) { $field[$row][$col]['left'] = 1; $field[$row][$previousLeft]['right'] = 1; } } else { unset($field[$row][$previousLeft]); } // Give dead end always a monster / treasure / Start or Exit if (count_values($field[$row][$col]) == 1 && count($fillbox) > 0) { $field[$row][$col]['content'] = $fillbox[0]; array_shift($fillbox); } else { $field[$row][$col]['content'] = ''; } } } /**************************************************\ Check broken paths If broken path, add entry to random field in broken path \**************************************************/ // How to do ????? /**************************************************\ Check walking circles If circle, remove one entry from random field in cicle path \**************************************************/ // How to do ????? // Set leftover content to random fields while (count($fillbox) > 0) { $x = rand(1, $mapHeight); $y = rand(1, $mapWidth); if ($field[$x][$y]['content'] == '') { $field[$x][$y]['content'] = $fillbox[0]; array_shift($fillbox); } } /******************************\ Show grid \******************************/ foreach ($field as $rowKey => $rowArr) { foreach ($rowArr as $colKey => $colArr) { // Create and show image SVG $image = '<svg width="'.$squareSize.'px" height="'.$squareSize.'px" fill="'.$squareColor.'" xmlns="http://www.w3.org/2000/svg">'.PHP_EOL; $image .= ' '.$svg['center'].PHP_EOL; // Center square // The doors edit: border control happens here. so essentially, the broken paths are created here with your original code. if ($rowKey == 1) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['top'].PHP_EOL; } if ($colKey == 1) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['left'].PHP_EOL; } if ($rowKey == 5) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['bottom'].PHP_EOL; } if ($colKey == 5) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['right'].PHP_EOL; } // the above code closes the doors around the grid (borders) but does not break the other doors. // The text (content) $text = ''; if ($colArr['content'] == 'monster'){ $text = $monster; } if ($colArr['content'] == 'treasure'){ $text = $treasure; } if ($colArr['content'] == 'start'){ $text = $start; } if ($colArr['content'] == 'exit'){ $text = $exit; } $image .= ' <text x="50%" y="50% "textLength="100%" font-size="'.$fontSize.'%" dominant-baseline="middle" text-anchor="middle">'.$text.'</text>'.PHP_EOL; $image .= '</svg>'; // Close SVG print $image; // Show image } print '<br>'; // Next row } ?>
  20. i had some time to find the errors in your logic which control the borders, so i tweaked your code to complete the 'grid'. <?php // Start Sessie //session_start(); // Map settings $mapWidth = 5; $mapHeight = 5; $squareSize = 70; $squareColor = '#333'; // Content settings $monster = '&#129430;'; $treasure = '&#127873;'; $start = '&#128578;'; $exit = '&#128274;'; // Make SVG files $fontSize = $squareSize * 2; $svg['center'] = '<rect width="80%" height="80%" x="10%" y="10%" rx="5%" ry="5%" />'; $svg['right'] = '<rect width="10%" height="20%" x="90%" y="40%" />'; $svg['bottom'] = '<rect width="20%" height="10%" x="40%" y="90%" />'; $svg['left'] = '<rect width="10%" height="20%" x="0" y="40%" />'; $svg['top'] = '<rect width="20%" height="10%" x="40%" y="0%" />'; // Function to count the values in a field function count_values($arr) { $counting = 0; foreach ($arr as $key => $val) { if (is_numeric($val)) { $counting = $counting + $val; } } return $counting; } // Calculate Monsters $monsters = ceil($mapHeight * $mapWidth * 0.16); // Calculate Chests $chests = floor($mapHeight * $mapWidth * 0.24); // Check map size if ($monsters == 0 || $chests == 0 || ($monsters + $chests + 2) > ($mapHeight * $mapWidth)) { print 'Please change your mapsize'; exit; } // Create content $squareChests = array_fill(1, $chests, 'treasure'); $squareMonsters = array_fill(1, $monsters, 'monster'); $squareStart = array(1 => 'start'); $squareEnd = array(1 => 'exit'); // Merge and mix all content $fillbox = array_merge($squareChests, $squareMonsters, $squareStart, $squareEnd); shuffle($fillbox); /******************************\ Start Grid Map \******************************/ $squareMaxTop = 1; $squareMaxLeft = 1; $squareMaxBottom = 1; $squareMaxRight = 1; // Build column for ($row=1; $row<=$mapHeight; $row++) { // Build row for ($col=1; $col<=$mapWidth; $col++) { $randomSquare = array(); while (count_values($randomSquare) < 4) { $randomSquare = array( 'top' => rand(0, $squareMaxTop), 'right' => rand(0, $squareMaxRight), 'bottom' => rand(0, $squareMaxBottom), 'left' => rand(0, $squareMaxLeft), ); } $field[$row][$col] = $randomSquare; } } /******************************\ Show grid \******************************/ foreach ($field as $rowKey => $rowArr) { foreach ($rowArr as $colKey => $colArr) { // Create and show image SVG $image = '<svg width="'.$squareSize.'px" height="'.$squareSize.'px" fill="'.$squareColor.'" xmlns="http://www.w3.org/2000/svg">'.PHP_EOL; $image .= ' '.$svg['center'].PHP_EOL; // Center square // The doors if ($rowKey == 1) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['top'].PHP_EOL; } if ($colKey == 1) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['left'].PHP_EOL; } if ($rowKey == 5) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['bottom'].PHP_EOL; } if ($colKey == 5) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['right'].PHP_EOL; } // The text (content) $text = ''; $image .= ' <text x="50%" y="50% "textLength="100%" font-size="'.$fontSize.'%" dominant-baseline="middle" text-anchor="middle">'.$text.'</text>'.PHP_EOL; $image .= '</svg>'; // Close SVG print $image; // Show image } print '<br>'; // Next row } ?> if you run the script, you will see a complete grid with all of the fields connected without border paths. I would not code a grid like this but it is your script. I hacked the code to make it work as you suggest (unless i have misinterpreted your request.)
  21. the code is doing what you have instructed it to do: create at least one door. Shouldn't you create at least 4 doors? the logic is a problem. Let's hack the script and see what happens. /******************************\ Start Grid Map \******************************/ $squareMaxTop = 1; $squareMaxLeft = 1; $squareMaxBottom = 1; $squareMaxRight = 1; // Build column for ($row=1; $row<=$mapHeight; $row++) { // Build row for ($col=1; $col<=$mapWidth; $col++) { // Default settings makes no difference here // Create random square with at least 1 door $randomSquare = array(); while (count_values($randomSquare) < 4) { $randomSquare = array( 'top' => rand(0, $squareMaxTop), 'right' => rand(0, $squareMaxRight), 'bottom' => rand(0, $squareMaxBottom), 'left' => rand(0, $squareMaxLeft), ); } $field[$row][$col] = $randomSquare; } } You need to re-examine the border control (doors at edges) and tweak the code to include 4 doors/paths.
  22. is this your code and design or are you using someone elses code and design? valid user ids as query strings is insecure and, frankly, stupid. if you wrote the code, then i suggest a rewrite is in order. do you pass a user id query string to every page as a method of validating a logged in user? ranklist should simply use the user id in the database to query results for the valid logged-in user. you would need to rewrite your code to utilize a proper log in script and check the database each page request (shared hosting). if you have a dedicated host then use a session variable to flag a logged in user but still check the database at each page request. nota bene: if the current user is not permitted to view another user's page, then this is simply access control and you should slap yo'self for posting this question. if user_id query not equal to user_id then not permitted to view. In other words, if user_id !== user_id query McFly? Hello, McFly? try not to search the internet for solutions because you may stumble across a "pretty uri" Apache rewrite proposal, which is not pretty and it is an awful patch for even more awful design methods. Any use of Apache rewrite is alot like saying "pretend [that] you didn't see that", so silly and resource consuming. i have no idea what "ranklist" is displaying and i don't really care but it could effect resolutions. if there is a particular reason why you cannot just use a db query to control access, then you are left with patching the code. if the current user is able to view this current user id associated data, then you could use a session variable instead. However, if all of the users id associated data is accessible to a user, then this would be too many session variables used to replace ids. use a session variable with a random get_id string id as key and user_id as value check if isset session variable $_SERVER['QUERY_STRING'] (not $_GET['id']), which is now random get_id string, then display the user_id associated results. the real id is associated with the random get_id string (= key/value) you could also use a database instead of a session variable. at login, generate a random string and insert it into the user table column, named (for example) hide_user_id then, you could use that temporarily valid id instead of a session variable. query the db when loading ranklist and retrieve the correct user id to display the asociated data using this hide_user_id in the query. just be certain that the hide_user_id column has a unique constraint applied. just use your noggin and create a patch until you can rewrite the code correctly. Best Wishes, Biff.
  23. @Barand You, Sir, are a veteran professional programmer and it always shows in your posts. Me, on the other hand, i am more of a hacker that is slowly learning from pros. Your code is a beautiful example of a well designed form and form processing script. Bravo! Hopefully, the OP can see the beauty of your work and follow this lead. Meantime, your "Judicious application of array key names" is a perfect example of how i can use this concept in future designs. I have copied this code to a text file for future reference. Pros can easily illustrate its usefulness. Thank you for educating me on this subject . Point well noted 🙂 edit: Dear Barand, please change the following sentence "Job Done." to "Job Well Done."
  24. I did not consider that someone may see my post and not understand that the code posted is just an example of how to detect empty of this array. I hope that viewers understand to escape the output after validation (code not included). I should have used the following code in my post to avoid security problems: foreach ($_POST['subquestion'] as $value) { echo htmlentities($value, ENT_QUOTES, 'UTF-8') . '<br>'; } my code sample is not a valid solution to be applied online, rather in a testing environment.
  25. I have no idea why you are using inline style to hide inputs. Are you trying to implement a rogue type="hidden" format? Makes no sense, none at all. Meantime, the subquestion array in this form will never be empty because the keys will be sent in the post (with empty values). You could hack a bit to force detection but this just illustrates that your code is sloppy and unorthodox. I suggest that you read more about html forms and structures of forms. You could make a new post in the html subforum here at phpfreaks. So to show you how subquestions could be handled, i have spent a few minutes creating a script with your messy code that i had to format in addition to hacking. Here is a working attempt to detect empty or not empty and display the results. If all values are empty then the subquestion has not been populated with values, otherwise the values will be shown. For the record, i am not a fan of form input arrays. <?php declare (strict_types = 1); switch ($_SERVER['REQUEST_METHOD']) { case 'GET': ?> <form autocomplete="off" method="post"> <label for="question">Sub Question <span class="req">*</span></label> <textarea cols="46" rows="3" name="subquestion[]" placeholder="Enter Sub question here.."></textarea> <div class="divider "></div> <div class="divider"></div> <textarea class="opt_text opt_text0 " cols="46" rows="2" name="choice0[]" placeholder="Enter Choice A here.." style="display: none;"></textarea> <label for="image" class="opt_img opt_img0" style="display: none;">Add Choice A Image(if any..)</label> <input type="file" class="opt_img opt_img0" name="o-image0[]" style="display: none;"><br><br> <textarea class="opt_text opt_text0 " cols="46" rows="2" name="choice0[]" placeholder="Enter Choice B here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img0" style="display: none;">Add Choice B Image(if any..)</label> <input type="file" class="opt_img opt_img0" name="o-image0[]" style="display: none;"><br><br> <textarea class="opt_text opt_text0 " cols="46" rows="2" name="choice0[]" placeholder="Enter Choice C here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img0 " style="display: none;">Add Choice C Image(if any..)</label> <input type="file" class="opt_img opt_img0" name="o-image0[]" style="display: none;"> <br><br> <textarea class="opt_text opt_text0 " cols="46" rows="2" name="choice0[]" placeholder="Enter Choice D here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img0" style="display: none;">Add Choice D Image(if any..)</label> <input type="file" class="opt_img opt_img0" name="o-image0[]" style="display: none;"> <li><label for="question">Sub Question <span class="req">*</span></label> <textarea cols="46" rows="3" name="subquestion[]" placeholder="Enter Sub question here.."> </textarea> <div class="divider "></div> <div class="divider"></div> <textarea class="opt_text opt_text1 " cols="46" rows="2" name="choice1[]" placeholder="Enter Choice A here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img1" style="display: none;">Add Choice A Image(if any..)</label> <input type="file" class="opt_img opt_img1" name="o-image1[]" style="display: none;"><br><br> <textarea class="opt_text opt_text1 " cols="46" rows="2" name="choice1[]" placeholder="Enter Choice B here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img1" style="display: none;">Add Choice B Image(if any..)</label> <input type="file" class="opt_img opt_img1" name="o-image1[]" style="display: none;"><br><br> <textarea class="opt_text opt_text1 " cols="46" rows="2" name="choice1[]" placeholder="Enter Choice C here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img1 " style="display: none;">Add Choice C Image(if any..)</label> <input type="file" class="opt_img opt_img1" name="o-image1[]" style="display: none;"> <br><br> <textarea class="opt_text opt_text1 " cols="46" rows="2" name="choice1[]" placeholder="Enter Choice D here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img1" style="display: none;">Add Choice D Image(if any..)</label> <input type="file" class="opt_img opt_img1" name="o-image1[]" style="display: none;"> <li><label for="question">Sub Question <span class="req">*</span></label> <textarea cols="46" rows="3" name="subquestion[]" placeholder="Enter Sub question here.."> </textarea> <div class="divider "></div> <div class="divider"></div> <textarea class="opt_text opt_text2 " cols="46" rows="2" name="choice2[]" placeholder="Enter Choice A here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img2" style="display: none;">Add Choice A Image(if any..)</label> <input type="file" class="opt_img opt_img2" name="o-image2[]" style="display: none;"><br><br> <textarea class="opt_text opt_text2 " cols="46" rows="2" name="choice2[]" placeholder="Enter Choice B here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img2" style="display: none;">Add Choice B Image(if any..)</label> <input type="file" class="opt_img opt_img2" name="o-image2[]" style="display: none;"><br><br> <textarea class="opt_text opt_text2 " cols="46" rows="2" name="choice2[]" placeholder="Enter Choice C here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img2 " style="display: none;">Add Choice C Image(if any..)</label> <input type="file" class="opt_img opt_img2" name="o-image2[]" style="display: none;"> <br><br> <textarea class="opt_text opt_text2 " cols="46" rows="2" name="choice2[]" placeholder="Enter Choice D here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img2" style="display: none;">Add Choice D Image(if any..)</label> <input type="file" class="opt_img opt_img2" name="o-image2[]" style="display: none;"></li> <input type="submit"> </form> <?php break; case 'POST': $countQuestions = count($_POST['subquestion']); $checkEmpty = 0; foreach ($_POST['subquestion'] as $value) { if (empty($value)) { $checkEmpty++; } } if ($checkEmpty === $countQuestions) { echo 'subquestion is empty'; break; } foreach ($_POST['subquestion'] as $value) { echo $value . '<br>'; } break; default: echo 'Request Method denied'; break; } ?> Hopefully you can create a cleaner, nicer form and process the form correctly. phpfreaks has lots of professionals that can help you when you have problems along the way. I suggest that if you continue using arrays, then atleast provide keys that can be checked for empty.
×
×
  • 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.