-
Posts
24,612 -
Joined
-
Last visited
-
Days Won
834
Everything posted by Barand
-
What have you tried so far?
-
Not if the writer consistently omits line-breaks and indentation. I would say the key is readability.
-
Just for fun, this was my attempt $square = [ [ 4, 9, 2], [ 3, 5, 7], [ 8, 1, 6] ]; $rowtots = []; $coltots = []; $k=count($square); // ROW and COL TOTALS for ($r=0; $r<$k; $r++) { for ($c=0; $c<$k; $c++) { if (isset($rowtots[$r])) $rowtots[$r] += $square[$r][$c]; else $rowtots[$r] = $square[$r][$c]; if (isset($coltots[$c])) $coltots[$c] += $square[$r][$c]; else $coltots[$c] = $square[$r][$c]; } } // put the totals into a sing;e array for later checking $totals = array_merge($rowtots, $coltots); // DIAGONALS TOTALS $diag1 = 0; for ($r=0, $c=0; $r<$k; $r++, $c++) { $diag1 += $square[$r][$c]; } $totals[] = $diag1; // append to array $diag2 = 0; for ($r=0, $c=$k-1; $r<$k; $r++, $c--) { $diag2 += $square[$r][$c]; } $totals[] = $diag2; // append to array // output square and result foreach ($square as $row) { echo '|'.join('|', $row).'|<br>'; } echo count(array_count_values($totals))==1 ? 'Magic square' : 'Not a magic square';
-
Agreed, the solution is poorly written and does not address the final part of the question (order listed on the cover) My solution would be SELECT b.Title , b.PublisherCode , b.Type , GROUP_CONCAT(a.AuthorFirst,' ',a.AuthorLast ORDER BY w.Sequence SEPARATOR ', ') as WrittenBy FROM book b INNER JOIN wrote w ON b.BookCode = w.BookCode INNER JOIN author a ON w.AuthorNum = a.AuthorNum GROUP BY b.BookCode HAVING COUNT(a.AuthorNum) > 1; +----------------------+---------------+------+---------------------------------------+ | Title | PublisherCode | Type | WrittenBy | +----------------------+---------------+------+---------------------------------------+ | Treasure Chests | TA | ART | Lon Schleining, Randy O'Rourke | | Van Gogh and Gauguin | WP | ART | Bradley Collins, Jr., Bradley Collins | | Black House | RH | HOR | Stephen King, Peter Straub | +----------------------+---------------+------+---------------------------------------+
-
The second query would be SELECT EmpID , EmpName , FormName , Scoring FROM SubmittedForm WHERE EmpID = '0001' AND submissionStatus <> 'Draft' AND fiscalYear='2015'
-
Please use tags in future posts. I added them this time. (Or you can use the <> button in the toolbar)
-
These are the only groups I found $a = json_decode($j,1); $groups = []; foreach ($a['response']['venues'] as $v) { $groups[] = $v['hereNow']['groups']; } echo '<pre>',print_r($groups, true),'</pre>';
-
Are you sure that json is correct - gives my a syntax error when attempting to decode?
-
Post the json data (results) so we can see what you are working with.
-
HTML select and option work with PHP database
Barand replied to sigmahokies's topic in PHP Coding Help
Your option values do not look like numbers to me. And your WHERE condition is nothing like mine. So which bit of it did you do? -
HTML select and option work with PHP database
Barand replied to sigmahokies's topic in PHP Coding Help
Your options need the month as as the value and month name as the text <select name='month'> <option value='1'>January</option> <option value='2'>February</option> ... etc Process the month, which will be in $_GET['month'], and query the database with a query like SELECT whatever FROM mytable WHERE MONTH(dateofbirth) = ? -
PHP $_GET? At least I think that is the function I need to get working
Barand replied to DogMan's topic in PHP Coding Help
This code is unnecessary as you are using DateTime objects. $now = time(); // this is really NOW, for comparison to your quit date $your_date = strtotime($quitdate); $datediff = $now - $your_date; You can get the vapedays from the interval object $vapedays = $interval->format('%a days'); -
No need to pop any elements, the starting position is already Array ( [2] => 1 [3] => 3 ) since the numeric index will automatically increment after any provided numeric index. So all that is required is to add the final two elements $array['b'] = 4; $array[] = 2; // adds index 4 So, in full $array = array('2' => 1, 3); $array['b'] = 4; $array[] = 2; echo '<pre>',print_r($array, true),'</pre>'; //result Array ( [2] => 1 [3] => 3 [b] => 4 [4] => 2 )
-
3rd option: $fname = 'otoole.desmond.caferoyal.pdf'; $ext = strrchr($fname, '.'); echo $ext; //==> .pdf Which is what I pointed out to you in reply #2
-
Skinning a cat (Or how many ways to output "Hello World!")
Barand replied to benanamen's topic in Miscellaneous
function x($a, $b) { $res = 0; while ($b) { if ($b%2) $res += $a; $a <<= 1; $b >>= 1; } return $res; } function y($j,$k) { echo chr($j+58|($k?0x20:0)); } $a = str_split(x(0xC0421DB,0x07),2) ; $b = str_split(x(0x5CDD207, 0x1E),2); array_walk($a , 'y'); echo ', '; array_walk($b , 'y'); -
Get the mime type of the updated file and apply the extension according to that value. You are already on an outdated version of PHP, you don't want to move to a worse situation.
-
How to Create a "action.php" page for HTML Form?
Barand replied to rashidpathiyil's topic in PHP Coding Help
I didn't receive that memo -
Need help posting to mysql and sending email from form
Barand replied to gabbymiles's topic in PHP Coding Help
@QoC, See end of para 7 on http://php.net/manual/en/language.expressions.php -
To have $row['id'] in your results you need to select "id" in your query.
-
you need a value for each column. You seem to have a couple of extra values at the end '".mysql_real_escape_string($data['length'])."', '', '', NOW(), 0, '') | | | | | | filesize mime ?? | | ?? added | is_done
-
What happened to PM attachments? I can't add them any more.
-
$real = $_FILES["file"]["name"]; // $GetName = ServerName($_FILES["file"]["name"]); $x = explode('.',$real); $GetName = time() . "." . $x[1]; If $real is "myfile.desmond.docx" then you will get desmond in $x[1]
-
You can't nest forms. Your data tables will be 1 to many though, an employee table and a phone table, each row of which contains employee id and a phone number. Just have one form containing employee fields and multiple fields for phone number entry. Name the phone fields something like "phone[]" so they are posted in an array, which you can loop through to process. When processing, insert the employee data and grab the last_insert_id to get the value of the new auto_incremented id field. Use this to insert the emp id value in each of the phone number records.
-
A somewhat simpler one-liner $input = "dog,white cat,white cat,black cat,white dog,black bird,white"; echo '<pre>',print_r(array_count_values(explode("\n", $input)), true),'</pre>';
-
I wonder if there's a Facebook API for that.