-
Posts
24,606 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
Why have you got 2 identically structured tables? [edit...] Why are creating a third table consisting of data derived from other tables? When you use an aggregation function the only values you can rely on on are the aggregated values and any GROUP BY values. All other values that are selected will be arbitrarily chosen from any record in the group.
-
Echo them and see which looks right. echo _ROOT_ . '<br>'; echo __ROOT__ . '<br>';
-
If it returns -1 then $this->getCredits() must be returning 0 (or false).
-
You can... $numLocations = 4; $stmt = $pdo->prepare ("SELECT city_name FROM city ORDER BY city_name LIMIT ? "); $stmt->execute([$numLocations]); $data = $stmt->fetchAll();
-
get Table Alias row values - MySQL Query in PHP
Barand replied to ajaxStardust's topic in PHP Coding Help
Here's some ways to skin that cat ... A foreach ($res as $row) { echo "<div><ol>"; echo "<li>{$row['Nmbr_fid']}</li>"; echo "<li>{$row['Nmbr_value']}</li>"; echo "<li>{$row['Name_fid']}</li>"; echo "<li>{$row['Name_Value']}</li>"; . . . echo "</ol></div>"; } B foreach ($res as $row) { echo "<div><ol>"; foreach ($row as $col) { echo "<li>$col</li>"; } echo "</ol></div>"; } C foreach ($res as $row) { echo "<div><ol><li>" . join('</li><li>', $row) . '</li></ol></div>'; } -
get Table Alias row values - MySQL Query in PHP
Barand replied to ajaxStardust's topic in PHP Coding Help
How are you getting "$data" array? -
get Table Alias row values - MySQL Query in PHP
Barand replied to ajaxStardust's topic in PHP Coding Help
What have to tried so far? How are you connecting to the database? Have look at phpdelusions site If you aren't already using PDO the I recommend you do. -
Information not updating to database after deselecting a checkbox
Barand replied to wongle's topic in PHP Coding Help
Are most of those the checkbox values? -
https://www.php.net/manual/en/mysqli.construct.php See example #3 - manual error handling
-
Information not updating to database after deselecting a checkbox
Barand replied to wongle's topic in PHP Coding Help
You should be getting an error from the above - 4 ? placeholders but 7 values in the paremeter array -
Information not updating to database after deselecting a checkbox
Barand replied to wongle's topic in PHP Coding Help
Try forcing an error (such as trying to connect with invalid password, for example) and see if that gets logged. -
Information not updating to database after deselecting a checkbox
Barand replied to wongle's topic in PHP Coding Help
If errors aren't being reported they may be being logged. Have you checked error logs? -
Information not updating to database after deselecting a checkbox
Barand replied to wongle's topic in PHP Coding Help
When you connect to the db, do you set the PDO::ATTR_ERRMODE attribute to PDO::ERRMODE_EXCEPTION so that pdo errors are reported? -
select option passing data to input fields: mySQL
Barand replied to javanoob's topic in PHP Coding Help
Here is a fuller fix for those NULL gm values showing changes Output Data mysql> select * from item where cat_id=4; +----+---------------+------+------+--------+ | id | itemname | em | gm | cat_id | +----+---------------+------+------+--------+ | 10 | Glock 9mm | 125 | 1050 | 4 | | 11 | Colt .38 | 200 | 1175 | 4 | | 12 | Derringer .22 | 115 | NULL | 4 | NULL gm value +----+---------------+------+------+--------+ -
Not only not necessary but quite a bizarre combination. Do you want a horizontal menu bar or a card layout? Pick one.
-
Not unless you post the relevant code that's giving the problem
-
Perhaps it's the code that's wrong.
-
Your tables have too many keys. See my diagram above. A city only needs FK link to its parent state. A state has a FK link to its parent country so from city you know its state then from state you know its country. Example SELECT country_name , state_name , city_name FROM city ct JOIN state s ON ct.state_id = s.id JOIN country c ON s.country_id = c.id ORDER BY country_name, state_name, city_name;
-
Do you have a data structure to support that process? For example +-------------------+ | country | +-------------------+ | id |-----+ | country_name | | +-------------------+ +-------------------+ | | state | | +-------------------+ | | id |-----+ +----<| country_id | | | state_name | | +-------------------+ +-------------------+ | | city | | +-------------------+ | | id |-----+ +-----<| state_id | | | city_name | | +-------------------+ +-------------------+ | | area | | +-------------------+ | | id | +-----<| city _id | | area_name | +-------------------+
-
Hijacking someone else's topic aside for now, define "Not working".
-
First you are going to have to bear some criticism of your code DO NOT connect to the server every time you call a function. Connect once at the top of index.php an pass the connection in the function calls. Connections are slow and you will overburden your server with connections You don't need 3 function calls to get the status totals - one will suffice You don't execute() after query(), execute() is for prepared statements. Don't put a closing ?> at end of included php files Lecture over, here's how I would do it (skeleton) index.php <?php require 'SqlConn.php'; $SC = 0; $FC = 0; // get status counts and store counts in an array $statusCounts = JC($conn); // pass $conn to function // output status counts echo "<h2>Completed : {$statusCounts['Completed']}</h2>"; echo "<h2>In-Progress : {$statusCounts['In-Progress']}</h2>"; echo "<h2>On-Hold : {$statusCounts['ON_HOLD']}</h2>"; // check critical systems CriticalSystem( $SC, $FC ); // output system success counts countupdown($SC, $FC); ?> functions.php <?php function JC($conn) // pass $conn to function { $sql = "Select Status , Count(Status) as total from EXCELMACRO...Jobs$ group by Status "; $stmt = $conn->query($sql); $resultCompleted = $stmt->fetchAll(); return array_column($resultCompleted, 'total', 'Status'); // return array of totals bt status } function CriticalSystem( &$SC, &$FC ) // pass count variables by reference { //array for critical devices $systems = array( array('ip' => '192.168.9.254', 'name' => 'Tech Swtich'), array('ip' => '192.168.9.205', 'name' => 'Printer'), array('ip' => '192.168.9.200', 'name' => 'Sales Printer'), array('ip' => '192.168.9.201', 'name' => 'Admin Printer'), array('ip' => '192.168.9.1', 'name' => 'KVM'), array('ip' => '192.168.9.2', 'name' => 'Office Data 24 Port'), array('ip' => '192.168.9.3', 'name' => 'Office Data 48 Port'), array('ip' => '192.168.9.4', 'name' => 'Office Voice 48 Port'), array('ip' => '192.168.9.7', 'name' => 'Warehouse Switch'), array('ip' => '192.168.9.13', 'name' => 'Foundry Canteen Switch'), ); //Result to search for to give success result $good = "Received = 1"; //troubleshooting to see if being re-freshed //echo "<h1>Site Status ".date("h:i:s")."</h1>"; echo "<table border='0' class='table'>"; // foreach loop to ping IP and check if alive or dead & dispaly result foreach ($systems as $ip) { unset($result); $successValue = "DOWN"; exec("ping -n 1 $ip[ip]", $result); foreach($result as $line) { if (strpos($line,$good) == TRUE){ $successValue = "UP"; } } echo "<tbody> <tr> <td>IP Address: {$ip['ip']}</td> <td>Unit Name: {$ip['name']}</td> </tr> <tr> <td>Status is: $successValue</td> <td>" . ($successValue == "UP" ? "<img src='/Images/GTick.jpg'>" ."<span style='color:#000000'>". $SC++ ."</span>" : "<img src='/Images/RTick.jpg'>" . "<span style='color:#000000'>".$FC++ ."</span>"). "</td> </tr> </tbody> "; } echo"</table>"; $FC = count($systems) - $SC; } function countupdown($countup, $countdown) // pass counts to function { echo "<center>"; echo "<br></br>"; echo "<img src='/Images/GTick.jpg'>". " " . "Systems Online = ".$countup; echo "<br></br>"; echo "<img src='/Images/RTick.jpg'>". " ". "Systems Offline = ".$countdown; echo "</center>"; }
-
select option passing data to input fields: mySQL
Barand replied to javanoob's topic in PHP Coding Help
Store gm = NULL in your db for those items. (set default to NULL and don't give them a value) Display the gm value as ( $row['gm'] ?? 'X' ) (BTW, what do em and gm mean?) -
The two most likely scenarios are these A ) the functions are called independantly <?php CriticalSystem(); // call 1st function countupdown(); // call 2nd function function CriticalSystem() { // function definition } function countupdown() { // function definition } ?> B ) the second function is called from within the first function <?php CriticalSystem(); // call 1st function function CriticalSystem() { // function definition countupdown(); // call 2nd function } function countupdown() { // function definition } ?> Which of these applies will determine how the values are passed.
-
Why are you converting $countup and $countdown to arrays. (you can't echo an array) Is you criticalSystems() function being called several times for different sets of systems? Problem is, I am only seeing a couple of snippets of code with no context as to how and where they are called, which doesn't help me. Conventional wisdom says "Forget that the global keyword exists". (It can cause more problems than it solves.) Pass values as function arguments.