logo
down
shadow

output data based on two tables


output data based on two tables

By : JennCarynPeterson
Date : December 18 2020, 12:00 PM
Does that help I need to output a table based on two other tables as shown below: , Your code is almost correct.
Add following lines:
code :
    $sql = mysql_query("SELECT*, count(*) as schedule_date FROM mst_schedule WHERE schedule_date LIKE '%$date' GROUP BY schedule_account") or die(mysql_error());
while ($data = mysql_fetch_array($sql)) {
    $account = schAccount($data['schedule_account']);
    $sql2 = mysql_query("SELECT * FROM trn_reportsch WHERE schedule_id='$data[schedule_id]' GROUP BY schedule_id");
    echo "<tr>";
    echo "<td>" . ucfirst($account['admin_fullname']) . "</td>";

    $bad = $good = $vGood = 0; // <-- ADD THIS LINE

    while ($data2 = mysql_fetch_array($sql2)) {
        if($data2['rating'] <=2){ // BAD
            $bad++;
        } else if($data2['rating'] <= 3){ // GOOD
            $good++;
        } else if($data2['rating'] > 3){ // VERY GOOD
            $vGood++;
        }
    }
    echo "<td>" . $bad . "</td>"; // Display the final value for bad
    echo "<td>" . $good . "</td>"; // Display the final value for good
    echo "<td>" . $vGood . "</td>"; // Display the final value for very good
    echo "<td>" . $data['schedule_date'] . "</td>";
    echo "</tr>";
}


Share : facebook icon twitter icon
PHP output summary based on 2 tables.

PHP output summary based on 2 tables.


By : PG0437
Date : March 29 2020, 07:55 AM
it helps some times I have 2 tables in my database and I wanted a PHP output of the following: , Here's the query:
code :
SELECT
  Categories.Name,
  COUNT(Pets.AnimalCAT)
FROM
  Categories
LEFT OUTER JOIN
  Pets
ON
  Categories.AnimalCAT = Pets.AnimalCAT
GROUP BY
  Categories.AnimalCAT
mysql_connect('localhost', 'username', 'password');
mysql_select_db('dbname');

$sql = "
    SELECT
      Categories.Name AS `category`,
      COUNT(Pets.AnimalCAT) AS `count`
    FROM
      Categories
    LEFT OUTER JOIN
      Pets
    ON
      Categories.AnimalCAT = Pets.AnimalCAT
    GROUP BY
      Categories.AnimalCAT
";
$result = mysql_query($sql) or die("Error in SQL: " . mysql_error());

while ($row = mysql_fetch_array($result)) {
  echo $row['category'] . ' ' . $row['count'] . '<br />';
}
Formatting output data into tables based on results

Formatting output data into tables based on results


By : Christian Volker Bak
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , If I understand correctly, you need to print both
s no matter what. Your if condition restricts printing - it will print only when the given condition is satisfied. So you need to alter it. Instead, you need to do this - read through docs, get fileType. If it is file1, assign value for that to a variable, that was initialized to null. If it is file2 , assign value for that to a variable, that was initialized to null. Then test for that variable and print either "-" or the content on each case.
Assuming variables file1Data and file2Data denotes string data from file1 and file2 respectively for each iteration over docs,
code :
while(docs.next) {
   String file1Data = null;
   String file2Data = null;
   if(docs.getString("fileType").equals("file1")) {
   // assign value for fiel1Data here
   } 
   if(docs.getString("fileType").equals("file2")) {
   // assign value for fiel2Data here
   }
   System.out.println("<tr>");
   System.out.println("<td>" + (file1Data == null || file1Data.equals("")?"-" : file1Data) + "</td>");
   System.out.println("<td>" + (file2Data == null || file2Data.equals("")?"-" : file2Data) + "</td>");
   System.out.println("</tr>");
}
XML data to tables using PHP with multiple elements, output should be based on the number of X elements

XML data to tables using PHP with multiple elements, output should be based on the number of X elements


By : MarceeMarc
Date : November 22 2020, 10:54 AM
Any of those help If you want 1 row per per , then you need to loop through the inside the . To get the id use ->getAttribute('id') -
code :
<?php
$dom = new DOMDocument();
$dom->load('person.xml');
$xpath = new DOMXpath($dom);

echo <<<EOF
<table border="1" cellspacing="2" cellpadding="2">   <tr>
    <th>Person ID</th>
    <th>Person Name</th>
    <th>Person LastName </th>
    <th>Code Numbers</th>
    </tr>
EOF;

$persons = $xpath->evaluate('//person');
foreach ($persons as $person) {
    //loop through each <code_number>
    foreach ($xpath->evaluate('./codes/code_number', $person) as $code_number) {
        echo '<tr>', "\n";
        echo '<td>', htmlspecialchars($person->getAttribute('id')), '</td>', "\n";
        echo '<td>', htmlspecialchars($xpath->evaluate('string(./person_name)', $person)), '</td>', "\n";
        echo '<td>', htmlspecialchars($xpath->evaluate('string(./person_lastname)', $person)), '</td>', "\n";
        echo '<td>'.htmlspecialchars($code_number->nodeValue).'</td>', "\n";
        echo '</tr>', "\n"; 
    }
}
echo '</table>';
?>
Counting - based on output from two tables

Counting - based on output from two tables


By : Harshavadan Vaishnav
Date : March 29 2020, 07:55 AM
hop of those help? I have two tables: master and class. Master is a master list of all students that have ever attended the school with studentID and Social Security Number (SSN). I'm worried that honors students have been assigned multiple student ID's. I would like to count studentID's for each SSN. , Just turn your where clause predicate into a subquery
code :
select m.studentID, m.SSN, c.studentID, c.type,
    (Select count(*) from master
     Where SSN = m.SSN) ssnCount
from master m join class c on c.studentID = m.studentID 
where c.type = 'Honors"
    and (Select count(*) from master
         where SSN = m.SSN) > 1
Querying data from 3 different tables based -checking if tables have matching records if not then display them

Querying data from 3 different tables based -checking if tables have matching records if not then display them


By : SnacksAndStacks
Date : March 29 2020, 07:55 AM
wish helps you I think you're making things overcomplicated. From what I gather - you simply need all records from table1 that have no corresponding (or null) records in table3 or no corresponding records in table 2. If this is the case, then this relatively simple query should do it:
code :
select * from tbl1 where NoClient not in (select tbl2.NoClient from tbl2)
union all
select * from tbl1 where NoClient not in (select tbl2.NoClient from tbl2       
inner join tbl3 on tbl2.NoClient=tbl3.NoClient and tbl2.ClinNo=tbl3.ClinNo 
where tbl3.IssueNo is not null)
Related Posts Related Posts :
  • Simplify a multidimensional array in PHP
  • Dynamic DB login in TYPO3 extension
  • Missing index in a multidimensional array PHP
  • Populate form from database
  • Got blank value in update query
  • PHP show message based on user had attach file or not attach file
  • Outline a transparent image using imagick PHP
  • If statement based on last digit of php variable number
  • make popup when post data on the same page
  • How to check email id's with specific domain from the array of email id's in PHP?
  • Dropdown list displays no value
  • Change openssl version in MAMP
  • How to use ob_start() in PHP project while using of Front Controller pattern
  • How do I implement search filter query using mongodb?
  • Android retrieve data from php org.json.JSONArray cannot be converted to JSONObject
  • Error Get request PHP
  • Update datepicker value based on php condition
  • Codeigniter Model loading error
  • How to sort varchar id on basis integer in it using mysql
  • Trial Balance Update accounts
  • Always return user details as json every time user login in laravel 5
  • join table on postgres with php
  • How to check for empty values with in_array WITH EXCEPTIONS?
  • How to replace return carriage in json string made from mysql and php?
  • Intl extension not getting loaded
  • PHP How to echo a 3-dim array
  • How to extend and modify a vendor model in Laravel 5?
  • How to change the number of posts that Wordpress JSON Api loads per page
  • how to validate dynamic text boxes using jquery
  • PHP undefined index id error
  • How to Parse xml data using php
  • getJSON parser cannot process JSON output from PHP file
  • Using Redis on Azure with Symfony2
  • php proc_open file descriptor in bash command
  • Trying to create a generalized function in PHP 5.2, error message not showing
  • Merging multiple rows with same field in column
  • Move "in stock" up on Woocommerce product page
  • Wrong reference path to Mail.php
  • phalcon volt bitwise operatios?
  • How to switch between tab when form submitting in same php file?
  • wp all import script to custom post image gallery
  • Storing a single password within in a PHP file instead of a database of users
  • get increment decrement day once clicked button
  • sql check for duplicates returning bool false?
  • Webmaster tools api dimensions
  • Seeding table using model factory not saving
  • How do I save associated entities in Doctrine 2?
  • fopen $_SERVER[REQUEST_URI]
  • RedBean One to Many Attribute Not Working
  • Safely passing ids to form action?
  • Php array explode a char
  • PHP MySQL Login Failure
  • can't get file_exists to work
  • Array PHP, Check if exist multiple elements to another array
  • Can array_walk be nested in php?
  • Notice: Use of undefined constant DIR - assumed '_DIR_'
  • Getting a weird 500 error with ajax
  • How can I filter an array of strings to remove elements that are prefixes of other elements?
  • Duplicate entries when assigning custom id to Laravel Model
  • AJAX call not returning php file command
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co