-
Posts
24,605 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
What do you see if you echo $sql; Is there a value at the end where the staff id should be?
-
Curly braces and endif don't play nice together. Use one syntax or the other. <?php if($chk == 0) { ?> <div id='showMe'> <div class="container"> <div class="row" style="color:red; padding-top:6rem; text-align:center;"> <h1>Database Update Failed</h1> </div> </div> </div> <?php } else { ?> <div id='showMe'> <div class="container"> <div class="row" style="padding-top:6rem; text-align:center;" > <h1><center>Database Update Successful</center></h1> </div> </div> </div> <?php } ?> </body> </html>
-
using php read from weather api and insert into mysql database
Barand replied to AJM2's topic in PHP Coding Help
Can you post the data returned by the api without all the var_dump junk in it? Can you post your code in a reasonably formatted manner? -
Where is the value for $userLoggedin coming from?
-
Example $arr = [ [ 'A', 'Jan. 22, 22'], [ 'B', 'Dec. 25, 21'], [ 'C', 'Feb. 22, 22'], [ 'D', 'Jan. 2, 22'] ]; usort($arr, function($a, $b) { $da = DateTime::createFromFormat('M. j, y', $a[1]); $db = DateTime::createFromFormat('M. j, y', $b[1]); return $db <=> $da; }); echo '<pre>' . print_r($arr, 1) . '</pre>'; outputs Array ( [0] => Array ( [0] => C [1] => Feb. 22 22 ) [1] => Array ( [0] => A [1] => Jan. 22 22 ) [2] => Array ( [0] => D [1] => Jan. 2 22 ) [3] => Array ( [0] => B [1] => Dec. 25 21 ) )
-
COALESCE() comes in useful here SELECT ... FROM tablename WHERE COALESCE(colname, '') = '';
-
Use PHP Variable as Value for Inline Style Property
Barand replied to braddalton's topic in PHP Coding Help
If you do, tell us what your real problem is. At present you are telling us a solution that isn't working - because it's the wrong solution, perhaps? -
Use PHP Variable as Value for Inline Style Property
Barand replied to braddalton's topic in PHP Coding Help
Use outer double quotes to insert a variable into a string. $cat_list = "<a href='blah'>cat 1</a>, <a href='yadayada'>cat 2</a>"; $cat_color = '#8F1FCF'; $cat_list = str_replace('<a', "<a style='color:$cat_color'", $cat_list); -
SImply by using the fact that there are 60 minutes in an hour and some very basic arithmetic. Therefore 0.67 hrs is 60 * 0.67 minutes (= 40 min) $t = 12.67; printf('%d hrs %d min', intval($t), ($t - intval($t))*60); //--> 12 hrs 40 min
-
It does center the text, but your inline heading is only as wide as its content (as adding a border shows)
-
try <?php $j = '{"JsonAssociationV1":{"transaction_type":"Create","main_train_uid":"G31259","assoc_train_uid":"G32783","assoc_start_date":"2021-12-13T00:00:00Z","assoc_end_date":"2022-05-13T00:00:00Z","assoc_days":"1111100","category":"NP","date_indicator":"S","location":"SHEFFLD","base_location_suffix":null,"assoc_location_suffix":null,"diagram_type":"T","CIF_stp_indicator":"P"}}'; $a = json_decode($j, 1); $type = $a['JsonAssociationV1']['transaction_type']; echo $type; // --> Create ?>
-
Too many <..>s and echos. Try echo "<option value='$value'>$key</option>"; (Note use of outer double quotes) Please use the <> button when posting code
-
Of course, the correct code could equally be echo ($class - $variacion); or echo ($class_variacion); but who can say as we have no idea what the line is supposed to do. "'cause de Hyphen" doesn't really cut it as an explanation.
-
echo "$game[6] $game[7]/$game[4] $game[5] $game[9] $game[10] $game[11] - $game[12] $game[13] $game[14]"; is redundant
-
returning the result of multidimentional array
Barand replied to Adamhumbug's topic in PHP Coding Help
The code you posted above outputs this for me (changed only by adjusting newlines and tabs) <div class="col-4"> <h5>Laker</h5> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="1" value="Adam Simms"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="7" value="David Powell"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="9" value="George Wilson"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="11" value="Jane Morrison"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="21" value="Peter Adamson"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="23" value="Wayne Jones"> </div> <div class="col-4"> <h5>Grace</h5> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="2" value="Allan Blair"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="5" value="Anthony Bell"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="6" value="Caroline Freeman"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="14" value="John Watson"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="15" value="Jack Williams"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="19" value="Mary Whitehouse"> </div> <div class="col-4"> <h5>Jardine</h5> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="4" value="Anne Bailey"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="12" value="John Patterson"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="13" value="John Tully"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="18" value="Mary Sheldon"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="20" value="Michael Grove"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="22" value="Peter Appleby"> </div> <div class="col-4"> <h5>Cowdrey</h5> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="3" value="Anna Hamilton"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="8" value="Emma Watson"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="10" value="Henry Irving"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="16" value="Margaret Norton"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="17" value="Mary Blake"> <input class="form-control w-100 mb-3" type="text" disabled="disabled" name="" data-value="24" value="William Smith"> </div> No col-6s and nothing rogue. -
returning the result of multidimentional array
Barand replied to Adamhumbug's topic in PHP Coding Help
(This example uses the "house" and "pupil" tables from my SQL tutorials instead of your teams and players) $res = $db->query("SELECT h.house_name , p.fname , p.lname FROM house h JOIN pupil p USING (houseid) "); $data = []; foreach ($res as $row) { if (!isset($data[$row['house_name']])) { $data[$row['house_name']] = []; } $data[$row['house_name']][] = [$row['fname'], $row['lname']]; } foreach ($data as $house => $pupils) { echo "$house<ul>"; foreach ($pupils as $p) { echo "<li>{$p[0]} {$p[1]}</li>"; } echo "</ul>"; } giving -
Have you tried using mysqil's error reporting to find the reason?
-
number has not been assigned a value in that code $x and $y are php variables and will not be available when the javascript runs.