PHP - Unwanted Duplication In Array
Hi everyone,
I don't know whether this is a PHP or MySql problem, but I think it is the former. The following code queries the database correctly, (and before you ask, there are no duplicate database entries), but the output duplicates every row. e.g., hammer (jpg image) hammer hammer (jpg image) hammer saw (jpg image) saw saw (jpg image) saw screwdriver (jpg image) screwdriver screwdriver (jpg image) screwdriver and so on. I cannot see why the code causes the row to repeat. Code: [Select] <?php session_start(); if (isset($_SESSION['id'])) { // Put stored session variables into local php variable $id = $_SESSION['id']; $userId = $_SESSION['userId']; $userGroup = $_SESSION['userGroup']; $managerId = $_SESSION['managerId']; } include_once("demo_conn.php"); $sql = mysql_query("SELECT * FROM users WHERE id='$id'"); while($row = mysql_fetch_array($sql)) { // Get member data into a session variable $egroup = $row["egroup"]; session_register('egroup'); $_SESSION['egroup'] = $egroup; } $query = mysql_query("SELECT topics.url_big, topics.url_small, topics.title, topics.$egroup, quiz.passState, quiz.userDate FROM topics INNER JOIN quiz ON (topics.managerId = quiz.managerId) WHERE topics.$egroup = 1 ORDER BY title ASC"); while ($row1 = mysql_fetch_array($query)) { echo "<a href='../../wood/wood_tool_images/{$row1['url_big']}' target='_blank'><img src='../../wood/wood_tool_images/{$row1['url_small']}' /><br />\n"; echo "{$row1['title']} <br />\n"; } ?> Similar TutorialsAs part of an image gallery I am trying to INSERT data into a table to make accessible the relevant info of individual images - the problem I have encountered is that each query seems to be being inserted twice, and I can't figure out why. The code = Code: [Select] <?php /*============================================== Connect to MySQL and select the correct database ==============================================*/ mysql_connect("localhost", "uname", "pwd") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("gallery_db") or die(mysql_error()); echo "Connected to Database gallery_db.<br />"; /*============================================= Include the files needed to undertake this task =============================================*/ include("functions.php"); /*========================= Set up arrays and variables =========================*/ $store = array(); $exif = array(); $folder = "./images/"; $insrt = 'INSERT INTO images VALUES (img_id, '; $file_name = ''; $file_location =''; $copyright =''; $caption = ''; $file_date = ''; $file_time = ''; $camera = ''; $speed = ''; $fNo = ''; $ISO = ''; /*================================= Open folder and read relevant files =================================*/ if ($handle = opendir('./images')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $file_name = $file; //>>> File Name <<< $file_location = $folder . $file; //>>> File Location <<< $exif = exif_read_data($file_location, 'EXIF'); //>>> Read exif data <<< /*============================================================== Check if the 'Copyright' info existe in the exif data, and if it doesn't set the $copyright variable to the relevant value. ==============================================================*/ if (array_key_exists('Copyright', $exif)) { $copyright = $exif['Copyright']; } else { $copyright = "copy name"; } $caption = $exif['COMMENT'][0]; //>>> Get the Caption <<< //>>> Re-format DateTime into separate date and time var's $file_date & $file_time <<< $temp = substr($exif['DateTime'], 0, 10); $file_date = substr($temp, 8, 2) . substr($temp, 4, 4) . substr($temp, 0, 4); $file_time = substr($exif['DateTime'], 11, 8); //>>> Set the rest of the variables <<< $camera = $exif['Model']; //>>> Get the camera make and model <<< $speed = $exif['ExposureTime']; //>>> Get the shutter speed <<< $fNo = $exif['COMPUTED']['ApertureFNumber']; //>>> Get the f No. <<< $ISO = $exif['ISOSpeedRatings']; //>>> Get the ISO rating <<< //>>> Fill the $store[] array with the relevant bits for each seperate query <<< $store[] = $insrt . "'" . $file_name . "', " . "'" . $file_location . "', " . "'" . $copyright . "', " . "'" . $caption . "', " . "'" . $file_date . "', " . "'" . $file_time . "', " . "'" . $camera . "', " . "'" . $speed . "', " . "'" . $fNo . "', " . "'" . $ISO . "')"; } } closedir($handle); } /*============================================================================= Get individual queries from $store[] and INSERT INTO images the relevant VALUES =============================================================================*/ $num_queries = count($store); //>>> Check the number of queries in the array $store $loop = 0; //>>> Starting point for query No. bearing in mind that array keys are numbered from zero while ($loop <= $num_queries - 1) { $query = $store[$loop]; if (!mysql_query($query)){ die('Error: ' . mysql_error()); } mysql_query($query); $loop++; } ?> I know it's not pretty, but that can be attended to once working properly. I am quite sure that it will be a very simple solution, probably so simple that I haven't even thought of it. Hi
I am reading in data from a csv file
if (($handle = fopen("data.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { echo "User Name: $data[0]"; echo "Booking IDs: $data[1]"; } echo "<hr>";The problem is some of the usernames are duplicated so get outputted the same user name 20 times but with different IDs, obviously but I am unsure how to group them together. I can't seem to figure out how to write if the next username is the same as current then just add another ID not go through the entire loop. Any ideas? Thanks I've recently had a problem with my admin site where PHP sessions, which are stored in a MySQL database, are duplicating and causing the page to return to the login screen. Usually the site works fine in Firefox, but stops working in IE and Safari. This problem suddenly appeared over night with no change to the files. Due to the amount of code, I'm reluctant to post it all, but does anyone have a suggestion on why this could be happening and how to solve it? Hello there, I'm looking for a PHP method to duplicate a line, for example if I wanted to duplicate this line: mail($to,$subject,$message,$headers); How could I specify a value of how many are displayed instead of doing this to send it 3 times: mail($to,$subject,$message,$headers); mail($to,$subject,$message,$headers); mail($to,$subject,$message,$headers); Many thanks <?php // Daniel URL duplicator. // Input links list. $linksList = "links.txt"; // How many times to duplicate the url? $manyTimes = 1000; // Read in the list. for ($x = 0; $x <= $manyTimes; $x++) { $handle = fopen($linksList, "r"); $line = fgets($handle); echo $line; fclose($handle); } ?>Hey Guys, I'm stuck on this simple bit of code lol what I'm trying to do is load in a list of urls: site1.com site2.com site3.com etc For each site that is read, I'm trying to duplicate it X times, above would print to screen the same url 1000 times, then move onto the next print it 1000 times etc until the list is done (or how ever many times I select) I can't think of the best way to do it! any help would be appreciated guys! Graham Hi I have this simple code $one = rand(1,9); $two = rand(1,9); $three = rand(1,9); but I need to change it so that they are all unique and the same number is not used more than once can anyone help? thanks Please help and amend the code Save without repetition required $read[0] I hope that my example is clear to you I apologize for bothering you. I am not good in English <?php $fileLocation = getenv("DOCUMENT_ROOT") . "/rt.txt"; $file = fopen($fileLocation,"a"); $n1 = $_POST['n1']; $n2 = $_POST['n2']; for($i = 0; $i < count($file); $i++){ $read = explode("|", $file[$i]); if($n1 == $read[0]){ echo 'Repetition'; } else { fwrite($file,$n1.'|'.$n2."\r\n"); }
I am parsing an rss feed from my flickr photostream using this:-
<?php $url = "http://api.flickr.com/services/feeds/photos_public.gne?id=49466419@N05&lang=en-us&format=rss_200"; $rss = simplexml_load_file($url); if($rss) { echo '<h1>'.$rss->channel->title.'</h1>'; echo '<li>'.$rss->channel->pubDate.'</li>'; $items = $rss->channel->item; foreach($items as $item) { $title = $item->title; $link = $item->link; $published_on = $item->pubDate; $description = $item->description; echo '<h3><a href="'.$link.'">'.$title.'</a></h3>'; echo '<span>('.$published_on.')</span>'; echo '<p>'.$description.'</p>'; } } ?>which gives me this as the description for each image:- public 'description' => string ' <p><a href="http://www.flickr.com/people/alfthomas/">Alf Thomas</a> posted a photo:</p> <p><a href="http://www.flickr.com/photos/alfthomas/14064465890/" title="harlaw_12"> <img src="http://farm6.staticflickr.com/5077/14064465890_83c02ecec6_m.jpg" width="240" height="110" alt="harlaw_12" /> </a> </p> <p>A view of Harlaw Reservoir.</p>' (length=338)What I actually want is the photo (linked back) without the "Alf Thomas posted a photo" bit, does anyone have any idea how I would go about cloning that bit out? Edited by foucquet, 31 May 2014 - 08:14 AM. Hi, I have the following script: <?PHP $match = '/.*?\\d+.*?(\\d+)(\\s+)/is' ; $dbh = new PDO('mysql:host=localhost;dbname=xxxx', 'xxxx', 'xxxx') ; $result = $dbh->query("SELECT companyName, invoiceAddress FROM detail_sheets WHERE area = 'Germany'") ; $codes = array() ; $names = array() ; $c0s = array() ; $c1s = array() ; $c2s = array() ; $c3s = array() ; $c4s = array() ; $c5s = array() ; $c6s = array() ; $c7s = array() ; $c8s = array() ; $c9s = array() ; while($row = $result->fetch(PDO::FETCH_ASSOC)) { if(preg_match($match, $row['invoiceAddress'], $matches)) { $codes[] = substr($matches[1], 0, 1) ; $names[] = $row['companyName'] ; //array_push($found, substr($matches[1], 0, 1), $row['companyName']) ; } } $i = 0 ; foreach($codes as $current) { $currentName = $names[$i] ; $result = $dbh->prepare("SELECT (sum(partbaskets.total) - sum(pourbaskets.total)) AS Margin FROM partbaskets, pourbaskets, enquiries, jobs WHERE partbaskets.enquiryRef = enquiries.id AND pourbaskets.enquiryRef = enquiries.id AND jobs.enquiryRef = enquiries.id AND jobs.status != 'Cancelled' AND enquiries.enqState != 'Inert' AND enquiries.companyName = ? ") ; $result->bindParam(1, $currentName, PDO::PARAM_STR) ; $result->execute() ; while($row = $result->fetch(PDO::FETCH_ASSOC)) { if($current == 0 && $row['Margin']) array_push($c0s, $row['Margin']) ; if($current == 1 && $row['Margin']) array_push($c1s, $row['Margin']) ; if($current == 2 && $row['Margin']) array_push($c2s, $row['Margin']) ; if($current == 3 && $row['Margin']) array_push($c3s, $row['Margin']) ; if($current == 4 && $row['Margin']) array_push($c4s, $row['Margin']) ; if($current == 5 && $row['Margin']) array_push($c5s, $row['Margin']) ; if($current == 6 && $row['Margin']) array_push($c6s, $row['Margin']) ; if($current == 7 && $row['Margin']) array_push($c7s, $row['Margin']) ; if($current == 8 && $row['Margin']) array_push($c8s, $row['Margin']) ; if($current == 9 && $row['Margin']) array_push($c9s, $row['Margin']) ; } $result = NULL ; $i++ ; } echo "<table><tr><td>Area</td><td>Margin</td></tr>" ; echo "<tr><td>Area 0</td><td>" . array_sum($c0s) . "</td></tr>" ; echo "<tr><td>Area 1</td><td>" . array_sum($c1s) . "</td></tr>" ; echo "<tr><td>Area 2</td><td>" . array_sum($c2s) . "</td></tr>" ; echo "<tr><td>Area 3</td><td>" . array_sum($c3s) . "</td></tr>" ; echo "<tr><td>Area 4</td><td>" . array_sum($c4s) . "</td></tr>" ; echo "<tr><td>Area 5</td><td>" . array_sum($c5s) . "</td></tr>" ; echo "<tr><td>Area 6</td><td>" . array_sum($c6s) . "</td></tr>" ; echo "<tr><td>Area 7</td><td>" . array_sum($c7s) . "</td></tr>" ; echo "<tr><td>Area 8</td><td>" . array_sum($c8s) . "</td></tr>" ; echo "<tr><td>Area 9</td><td>" . array_sum($c9s) . "</td></tr></table>" ; ?> But what is happening is that the Margin is being multiplied by the number of rows in partbaskets (which is the same amount of rows in pourbaskets). So for instance, if there is one part per job for a companyName, there is no problem and I get the correct margin. But, if there is say 4 parts for one of the jobs, then the margin for that job will be multiplied by 4, which is wrong. I have tried using GROUP but it didn't help. Can someone please give me the missing link in my SQL statement? Hello all, A simple question: I have a HTML application from which a php script is executed. 'GET' method is used and no form is submitted. I was wondering if there is a way to prevent users from run this php script directly in the browser. Thank you all for your suggestions, Mamer Hi guys,
I am using this code to open and close a pop up window, but as soon as i click the close button this
http://localhost/popup.php?random=&button=
automatically adds in the url, Please tell me what is wrong with the script
<script type="text/javascript"> $(document).ready(function(){ $('a.popup-window').click(function(){ var popupBox = $(this).attr('href'); $(popupBox).fadeIn(400); var popMargTop = ($(popupBox).height() + 24)/2; var popMargLeft = ($(popupBox).width() + 24)/2; $(popupBox).css({ 'margin-top' : -popMargTop, 'margin-left' : -popMargLeft }); $('body').append('<div id="mask"></div>'); $('#mask').fadeIn(400); return false; }); $('button.close,#mask').live('click', function(){ $('#mask,.popupInfo').fadeOut(400,function(){ $('#mask').remove(); }); return false; }); }); $(document).keyup(function(e){ if(e.keyCode ==27){ $('#mask,.popupInfo, #popup-box').fadeOut(400); return false; } }); </script> </head> <body> <a href="#popup-box" class="popup-window">Click</a> <div id="popup-box" class="popupInfo"> <form> <label>ANYTHING</label></br> <input type="text" name="random"/></br> <button type="submit" name="button" class ="close">close</button> </form> </div> </body> </html> Edited by chauhanRohit, 27 June 2014 - 09:46 AM. Code: [Select] <?php # This script does get included into the document create_new_tag_from.php if(isset($_POST['tag_name_submit'])){ $tag_name_submit = $_POST['tag_name_submit']; } if(!empty($_POST['tag_name'])){ $tag_name = strip_tags($_POST['tag_name']); } if(!empty($_POST['tag_description'])){ $tag_description = strip_tags($_POST['tag_description']); } if(isset($tag_name_submit)){ # The Validation of User Entered Data # Do validate for solely alphabetic characters with ctype_alpha # ctype_alpha($tag_name) && if(ctype_alpha($tag_description)){ $tag_name = strtolower($tag_name); $tag_description = strtolower($tag_description); # The Insertion Into the Database $db_connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); # Do research if SQL query has to be modified into a PHP comform query $sql_query = sprintf( "set @newid = convert( ( select max(convert( (substring(tag_id, 2)) , unsigned integer))+1 from tags), char(10) ); set @newid = if(length(@newid) = 1, concat('0', @newid), @newid); set @newid = concat('c', @newid); INSERT INTO tags (tag_id, tag_name, tag_description, added_by_user_id, creation_date, last_edited) VALUES (@newid, '%s', '%s', 7, now(), '0')", mysqli_real_escape_string($db_connect, $tag_name), mysqli_real_escape_string($db_connect, $tag_description) ); $sql_query_run = mysqli_multi_query($db_connect, $sql_query); # Print Test to See If It Works echo "works_ "; echo $tag_name . "_ "; echo $tag_description . "_ "; } else { # End of the Validation echo "The entered data must be in alphabetic characters."; } } ?> Here is the form: Code: [Select] <?php include_once('../../header.php'); include_once('../../model/contribution/create_new_tag_script.php'); ?> <form action="" method="post"> <input type="text" name="tag_name" value="" /> <textarea maxlength="60" type="text" name="tag_description" value=""></textarea> <input type="submit" name="tag_name_submit" value="Submit the New Tag" /> </form> <?php include_once('../../footer.php'); ?> By the script as given above the conditional check will skip to the error message. Though I have to say that ctype_alpha does return TRUE when I do try it with "tag_name" which is entered data from the input field, while the other is from the textarea. I simply cannot see the reason for the returned FALSE. I have an exercise for school that I have to work out. My teacher is letting us figure it out ourselves, but I've ran into some troubles: - We have to make 2 files: sescook1.php and sescook2.php. - We have to make a form for the user to fill out their name and favorite color (in sescook1.php). - We have to check the input (whether there is input or no). If there's isn't any input, we have to echo 'Please fill out __' (in sescook1.php) - We have to store the name in a session variable and the color in a cookievariable (in sescook1.php) - If both fields are filled in, we ave to show a link 'go to the next page' (where 'next page' is an URL to sescook2.php). - All info has to be shown in sescook2.php (Entered name: __, Entered color: ___) - You have a link 'Go back to previous page' (where 'previous page' is an URL to sescook1.php) My code: Quote <?php session_start(); function checkContent() { if($_POST["name"] == "") echo "Please enter your name"; elseif($_POST["favcolor"]) echo "Please enter your favorite color"; else echo "Go to <a href='http://localhost/webadv1011/PHPCookiesSessies/sescook2.php'>next page"; } ?> <form name="color" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="<?php checkContent(); ?>"> <p>Name: <input type="text" name="naam" /></p> <p>Favourite color: <input type="text" name="favcolor" /></p> <p><input type="submit" name="submit" value="send" /></p> </form> This is the code I got so far. My problem is that the page refreshes itself after it does the checkContent function. I'm also not sure how I save my name in a session variable and the color in a cookie variable (and pass them to the next page as well!). We haven't learned anything on cookies and sessions except our own trial and error and things I found on the internet. Unfortunately, I can't really find lots of useful info (most people refer to Ajax, but we can only use php), or I'm looking in the wrong place. Thanks for your help in advance! Hi Everyone, I am writing a PHP script to allow some of my site members to add links to their site. The script is setup to use a supplied link to an image, then make that image a clickable link which in turns opens that webpage. Here is my code: Code: [Select] <?php if($_POST['formsubmit'] == "Submit") { $varLink = $_POST['Link']; $varImage = $_POST['Image']; $varDescription = $_POST['Description']; } $filea = "temp.tmp"; $fileb = "original.txt"; $filec = "newfile.txt"; $fa=fopen($filea,'w'); /* Open Temp File and Write $_POST data */ if($fa) { fwrite($fa,"<a href='$varLink'><img src='$varImage'></a><br>$varDescription<br><br>\n"); fclose($fa); } $fa=fopen($filea,'r'); /* Open Temp File and Read Contents */ if($fa) { $bufa=fgets($fa); fclose($fa); } $fc=fopen($filec,'w'); /* Open New File to merge new and old Links */ if($fc) { fwrite($fc, $bufa); /* Write Newest Link First */ } $fb=fopen($fileb,'r'); /* Open Original file and Read it */ if($fb) { while(!feof($fb)) { /* Loop through complete old file and write to new file */ $bufb=fgets($fb); fwrite($fc, $bufb); } } fclose($fb); fclose($fc); unlink('original.txt'); /* Delete Original File */ unlink('temp.tmp'); /* Delete Temp File */ rename('newfile.txt', 'original.txt'); /* Rename New File to the Old Filename */ ?> NOTE The above code has been 'expanded' in my troubleshooting efforts... (i.e. I wrote the first write to file code, executed it and checked the file contents manually, then the 2nd step, etc....) so my final code will be shorter. The problem I am having,.... when i write the 1st file 'temp.tmp', I get the expected data in the file (below). <a href='http://www.somesite.com'><img src='http://www.somesite.com/pic.jpg'></a><br>Description of site<br><br> However, when I read the temp.tmp and original.txt files and write it to the newfile.txt (to merge it all together) the expected data is there but with an extra entry after each 'good' entry (below): <a href='http://www.somesite.com'><img src='http://www.somesite.com/pic.jpg'></a><br>Description of site<br><br> <a href=''><img src=''></a><br><br><br> I don't understand why i am getting the extra entry '<a href=''><img src=''></a><br><br><br>' in the file. Can anyone shed some light on this? My head is sore from banging it on the wall! When I try to run the code below with Code: [Select] if ( $user->uid ) it works just dandy. But if I use Code: [Select] if ( !$user->uid ) it puts the number one a little bit below my truncated paragraph. It only started doing this after I put the Code: [Select] $login = print("Log in to see full article!");. It worked normally (besides the fact that it didn't say log in to see full article) And for description, I have 400 words of Lorem Ipsum, but you guys dont need to see that so I put elipses. Code: [Select] <head> <?php // this signifies how to truncate function myTruncate($string, $limit, $break=".", $pad="...") { // return with no change if string is shorter than $limit if(strlen($string) <= $limit) return $string; // is $break present between $limit and the end of the string? if(false !== ($breakpoint = strpos($string, $break, $limit))) { if($breakpoint < strlen($string) - 1) { $string = substr($string, 0, $breakpoint) . $pad; } } return $string; } ?> <title>truncate test</title> </head> <body> <?php $description = 'Lorem. ipsum dolor sit amet...'; // This makes it so it only applies to non logged in users if ( !$user->uid ) { //Replace 'XXX' with your number (Probably 500) $description = myTruncate($description, xxx); $login = print("Log in to see full article!"); } echo "<p>$description</p>"; echo "<p>$login</p>"; ?> I'm having a problem with some php code that allows you to edit a text file. No matter what file it loads, it always adds four horizontal tabs and two spaces to the end of the text. I've attached the code to this post. If anyone can help me with this, it would be greatly appreciated. Cindy I have 2 files; Newfault.php and thankyou.php 1) Data is entered into a form in Newfault.php 2) The data from this form is retieved in thankyou.php and is then inserted into a table called "Calls" Problem: My entered record is being added to my database OK, but it is also adding a blank record for some reason and I can't work out why. Can anyone help? This is for my uni assignment. Thanks, Ladykudos This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=328141.0 NOTE - Please read the information first as it contains important information to understand the problem. Rules → • There are 9 Columns(C1,C2,C3,C4,C5,C6,C7,C8,C9) [ Max columns will be 9] • The number of Rows can vary from 3,6,9,12,15,18 (Max). In this case Number of Rows shall be 12 Number of Rows = No of Tickets (Max Allowed 6) x Rows Per Ticket (Max Allowed 3). Thus, Max Rows can be 18 • Each Row is required to have 4 Blank Spaces and 5 Filled with Numbers • All numbers available in the Column Array have to be utilized • This configuration of an shall create a matrix of 9 Columns & 12 Rows (3 x 4 Tickets), which is 108 MATRIX BLOCKS where only a maximum of 60 numbers can be filled out of 108 available blocksrandomly with the above conditions being met 100%. • The numbers in column must be arranged / sorted in ASCENDING ORDER (For coding logic purpose, as soon as the number is assigned to the new MATRIX MAP use array_shift() or unset() the number so as to avoid repetition Example - Row 1 and Column 1 shall generate a MATRIX BLOCK - R1C1 Row 3 and Column 7 shall generate a MATRIX BLOCK - R3C7 Matrix Block can also be termed as Matrix Cell for your ease (if needed) MASTER SET OF ARRAY WITH NUMBERS array( "C1"=> array( 1, 2, 3, 5, 6, 7, 9 ), //7 Numbers "C2"=> array( 13, 14, 15, 17, 18, 19 ), //6 Numbers "C3"=> array( 21, 22, 23, 24, 25, 26, 30 ), //7 Numbers "C4"=> array( 31, 33, 34, 36, 37, 38, 39 ), //7 Numbers "C5"=> array( 41, 42, 46, 47, 48, 49, 50 ), //7 Numbers "C6"=> array( 51, 52, 53, 54, 55, 57, 58 ), //7 Numbers "C7"=> array( 61, 62, 64, 65, 69, 70 ), //6 Numbers "C8"=> array( 71, 74, 75, 76, 77, 78 ), //6 Numbers "C9"=> array( 82, 83, 85, 87, 88, 89, 90 ) //7 Numbers ); The above array has 60 Numbers to be filled out of 108 MATRIX BLOCK / CELL which meets the condition that for a FULL BLOCK containing 4 MINI BLOCKS WITH 3 ROWS (max. allowed) EACH I have been able to generate this without any issue meeting all the conditions of the Columns My Allocation Matrix Array will look like array( "R1"=> array( "C1"=> true, // Means that MATRIX BLOCK R1C1 will be NOT EMPTY "C2"=> false, // Means that MATRIX BLOCK R1C2 will be EMPTY "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> false ), "R2"=> array( "C1"=> false, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> true, "C8"=> true, "C9"=> false ), "R3"=> array( "C1"=> true, "C2"=> true, "C3"=> true, "C4"=> true, "C5"=> false, "C6"=> false, "C7"=> false, "C8"=> false, "C9"=> true ), "R4"=> array( "C1"=> true, "C2"=> true, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> false ), "R5"=> array( "C1"=> false, "C2"=> false, "C3"=> false, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> true, "C8"=> true, "C9"=> true ), "R6"=> array( "C1"=> true, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ), "R7"=> array( "C1"=> false, "C2"=> false, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> true ), "R8"=> array( "C1"=> true, "C2"=> false, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> true ), "R9"=> array( "C1"=> true, "C2"=> false, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ), "R10"=> array( "C1"=> false, "C2"=> true, "C3"=> true, "C4"=> true, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> false, "C9"=> false ), "R11"=> array( "C1"=> false, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> true, "C9"=> false ), "R12"=> array( "C1"=> true, "C2"=> false, "C3"=> true, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ) ); In the above array R stands for Row, C for Column, TRUE/FALSE (Boolean) means that if TRUE a Number can be filled in the resulting MATRIX BLOCK / CELL ( Row[Number]Column[Number] ) else if FALSE the MATRIX BLOCK / CELL shall be EMPTY The result for the above shall be
PROBLEM : I am unable to understand what should possibly be the logic & loop used here for creating a MATRIX ALLOCATION MAP as shown above I have tried while, foreach & for but unable determine the perfect combination which would meet the conditions. (Tried all of the above with Nested Loops also) Edited May 1, 2020 by AlphaMikeTags hi i am trying to make a payroll calculator script that takes employee info, calculates pay, displays submitted info in a table, stores info in an array, and updates the array when new info is submitted. i have most of these accomplished, i am having trouble with the "store into an array, and update the array when new info is submitted" parts of the project. i am still not very fluent in php so there may be easier ways to achieve what i have so far. any pointers would be a great help, this part has got me stumped. |