-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
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.
-
Trying to use php rand() function (newbie)
Barand replied to DavidAbineri's topic in PHP Coding Help
If the php code didn't work when it was a .html file but did work when changed to a .php file, then that should be a clue. The default configuration on most servers is that php code must be in a .php file to be processed. A .php file may contain html (in fact it doesn't need to contain any php!). -
Trying to use php rand() function (newbie)
Barand replied to DavidAbineri's topic in PHP Coding Help
Is the file that the code is in a .PHP file or a .HTML file? If it's not .php, rename it and try again. -
-
Also your css style specification is for images with class=logo. You don't have one, you have a div with class=logo.
-
Store id if login successful if (password_verify($_POST['password'], $row['password'])) { $_SESSION['user_id'] = $_POST['user_id']; } else { // error - invalid login } Get and display points if (isset($_SESSION['user_id'])) { $res = $conn->prepare("SELECT points FROM user_points WHERE user_id = ? "); $res->execute([${SESSION['user_id']}]); echo "You have " . $res->fetchColumn(). " points<br>"; } else { header("Location: login.php"); // send to login page }
-
When they log in, store their userID as a session variable. When you want to display their points, query your database using that userID.
-
That is what you don't want to do. Don't increase or reduce values in tables. Instead store individual referals and individual offers. The number still required will be the difference between total referals and total offers which can be calculated when required by a query. So if you you had a db structure similar to this +-----------------+ +----------------+ | organisation | | volunteer | +-----------------+ +----------------+ | org_id |----+ | volunteer_id |----+ | org_name | | | name | | | contact | | | address | | | etc. | | | phone | | +-----------------+ | | etc | | | +------------------+ +----------------+ | +----------------+ | | referal | | | help_offer | | +------------------+ | +----------------+ | | ref_id | | | help_id | +-----<| org_id | +------<| volunteer_id | | referal_date | | offer_date | | sex | | sex | | age | | age | | name | | quantity | | address | +----------------+ | etc | +------------------+ ... then counting the referals by sex/age gives the requirement and summing the quantities of help offered by sex/age gives the aid total. The deferrences are how many you still require.
-
PayPal Integration in PHP (Step by Step Tutorial)
Barand replied to FabrizioCo's topic in PHP Coding Help
// Create a connection to the database. mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); // ADD THIS LINE $db = new mysqli($dbConfig['host'], $dbConfig['username'], $dbConfig['password'], $dbConfig['name']); Adding that line will make mysql report any errors it encounters -
PayPal Integration in PHP (Step by Step Tutorial)
Barand replied to FabrizioCo's topic in PHP Coding Help
nm -
PHP 8.0 How to correct if ( count($this::$sources) > 0 )
Barand replied to David-London's topic in PHP Coding Help
Before you guess the correction code, see what it contains when you get the error var_dump($this::$sources); and find where it is being initialized (probably in it's class' constructor -
PHP 8.0 How to correct if ( count($this::$sources) > 0 )
Barand replied to David-London's topic in PHP Coding Help
If $sources is supposed to be an array then ensure it is correctly initialised as such. If it is currently NULL, you will get an error. -
Create an array of those field names which are to be read only, for example $readonly = ['id', 'username', 'email']; then $ro = (in_array($key, $readonly)) ? 'readonly' : '';
-
If you have a GROUP BY to calculate an aggregate (SUM, COUNT etc) you can't use WHERE on the aggregate value as it's value isn't known until the end of the query. So while a WHERE clause filters inputs, a HAVING clause filters outputs. The COUNT(*) .. GROUP BY is givings me a count the records for each combination of job_number/line_item. As we are looking for duplicates we are only interested in those with a count of more than one. As for JOIN vs UNION... SELECT ... FROM A JOIN B gives you rows with columns from both A and B. So a join extends the columns. SELECT ... FROM A UNION SELECT ... FROM B gives you the rows from the first select followed by those from the second. So a union extends the rows.
-
How to sort Hidden -> A-Z in Top and Show -> Z-A in Bottom
Barand replied to Ramcult's topic in PHP Coding Help
If you haven't written a custom sort function before, I suggest you start with something simple until you understand how they work. EG $array = [2, 1, 4, 3, 6, 5, 8, 7]; Then write functions to sort the above array ascending order descending order even numbers first followed by the odd numbers NOTE: A custom sort function has two arguments, $a and $b. usort() will place each pair of array items into $a and $b and call your function Your function should determine if $a should sort above or below $b by returning -1 (or a value < 0) if $a should be above $b +1 (or a value > 0) if $a should be below $b 0 if they are considered equal -
How to sort Hidden -> A-Z in Top and Show -> Z-A in Bottom
Barand replied to Ramcult's topic in PHP Coding Help
That would give this, (not what your example above shows) | 1 | Amet \ | 1 | Consectetur | | 1 | Ipsum | HIDDEN, A-Z | 1 | Lorem | | 1 | Sed / | | Sit \ | | Elit | SHOW, Z-A | | Dolor | | | Adipiscing / Is that what you want? If it is then this is the function... usort($raw, function ($a, $b) { $x = $b['hidden'] <=> $a['hidden']; // sort hidden to top, show to bottom (ie hidden DESC) if ($x == 0) { // do elements have same hidden value? return $a['hidden'] ? $a['label'] <=> $b['label'] : $b['label'] <=> $a['label']; // sort label ASC if hidden, label DESC if show } else return $x; }); If it isn't, adapt the function to your requirements. -
How to sort Hidden -> A-Z in Top and Show -> Z-A in Bottom
Barand replied to Ramcult's topic in PHP Coding Help
If you want to sort by "hidden" you do not need usort(). A simple sort() or rsort() will suffice. By default, arrays are sorted on the value of the first element. $raw[] = array("hidden" => true, "label" => "Lorem"); $raw[] = array("hidden" => true, "label" => "Ipsum"); $raw[] = array("hidden" => false, "label" => "Dolor"); $raw[] = array("hidden" => false, "label" => "Sit"); $raw[] = array("hidden" => true, "label" => "Amet"); $raw[] = array("hidden" => true, "label" => "Consectetur"); $raw[] = array("hidden" => false, "label" => "Adipiscing"); $raw[] = array("hidden" => false, "label" => "Elit"); $raw[] = array("hidden" => true, "label" => "Sed"); sort($raw); showResults($raw); rsort($raw); showResults($raw); function showResults($array) { echo '<pre>'; printf("| %6s | %-15s |<br><br>", 'Hidden', 'Label'); foreach ($array as $arr) { printf("| %6s | %-15s |<br>", $arr['hidden'], $arr['label']); } echo "<pre><br>"; } Results sort() rsort() | Hidden | Label | | Hidden | Label | | | Adipiscing | | 1 | Sed | | | Dolor | | 1 | Lorem | | | Elit | | 1 | Ipsum | | | Sit | | 1 | Consectetur | | 1 | Amet | | 1 | Amet | | 1 | Consectetur | | | Sit | | 1 | Ipsum | | | Elit | | 1 | Lorem | | | Dolor | | 1 | Sed | | | Adipiscing |