Jump to content

SELECT Query troubles


Drewser33

Recommended Posts

Hi, I am still very new to php.  I have made some simple things work, and I feel like this should be easy, but it is making my head hurt.

 

This is the scenario.  There is a database that holds all the employee information. 

Unfortunately with the policy here I had to create a separate database for my project, but still using the same employee information so I reference that database to get the employee info.

 

So my goal is write a select query to count the number of open tasks a specific employee that is inside a department.  I have accomplished in writing the query to accomplish this.  My problem is that every time I display the value in which it provides, it is a string of numbers and I cannot display it correctly.

 

$conn1 = mysql_connect('localhost', 'localhost', '7passwordV') or die(mysql_error());

mysql_select_db('homefree');

            $query6 = "SELECT * FROM employees WHERE dept = 2";

            $result6 = mysql_query($query6) or die (mysql_error());

            $where = array();

          while($row6 = mysql_fetch_array($result6))

          {

            $where [] = $row6['id'];

 

          }

mysql_close($conn1);

 

include 'includes/configtask.php';

include 'includes/opendbtask.php';

 

foreach($where as $val) {

    $query100 = "SELECT ID FROM taskinfo WHERE Response = '$val' ORDER BY ID";

    $result100 = mysql_query($query100);

    $row100 = mysql_num_rows($result100);

        ?>

      <table cellpadding=2  width="750"  align ="center" table border = "0">

      <tr>

      <td>   

<?php     

echo $row100;

  ?>

</td>

</tr>

  <?php

}

 

What I would like to do is display each value it returns but in the form of a variable, individually. 

 

Hope this makes sense as I am pretty stuck on this one.

 

THANKS!!

Link to comment
https://forums.phpfreaks.com/topic/91971-select-query-troubles/
Share on other sites

<?php
$conn1 = mysql_connect('localhost', 'localhost', '7passwordV') or die(mysql_error());
               mysql_select_db('homefree');
            $query6 = "SELECT * FROM employees WHERE dept = 2";
            $result6 = mysql_query($query6) or die (mysql_error());
            $where = array(); // I would get rid of this... but that is just me.. this is the proper way to do it.
           while($row6 = mysql_fetch_array($result6))
           {
               $where[] = $row6['id']; // you had a space between the $where and [] that is not an array
         
          }
          mysql_close($conn1);

include 'includes/configtask.php';
include 'includes/opendbtask.php';

foreach($where as $val) {
    $query100 = "SELECT ID FROM taskinfo WHERE Response = '$val' ORDER BY ID";
    $result100 = mysql_query($query100);
    $row100 = mysql_num_rows($result100);
        ?>
       <table cellpadding=2  width="750"  align ="center" table border = "0">
          <tr>
             <td>             
<?php       
              echo $row100; // here your echoing the number of rows that were returned. 
                                   //  with no break in them either that is why they are all one long string

               while($rows = mysql_fetch_array($result100))
               {
                     echo $rows.'<br>'; // here is what your query is returning.
               }
  ?>
           </td>
       </tr>
  <?php
}

?>

 

See what that gives ya.

 

Nate

Link to comment
https://forums.phpfreaks.com/topic/91971-select-query-troubles/#findComment-471118
Share on other sites

I tried your code chronister and this is what displayed on my page(using firefox)

 

1Array

0

1Array

6Array

Array

Array

Array

Array

Array

0

0

0

0

1Array

0

0

 

What I noticed about the word array here is that when the result of the numrows was 1, you see array once, if the result of the numrows is 6 you get 6 words that say array.  Unless I missed something, (which is more than possible) this is not what I was looking for.

 

Thanks for your help,

Drew

Link to comment
https://forums.phpfreaks.com/topic/91971-select-query-troubles/#findComment-471132
Share on other sites

GOT IT!!!!!!!

 

Here is the code I used:

 

 

$conn1 = mysql_connect('local', 'local', '7asdfadas') or die(mysql_error());

              mysql_select_db('homefree');

            $query6 = "SELECT * FROM employees WHERE dept = 2";

            $result6 = mysql_query($query6) or die (mysql_error());

           

            //$where = array(); // I would get rid of this... but that is just me.. this is the proper way to do it.

          while($row6 = mysql_fetch_array($result6))

          {

              $where[] = $row6['id']; // you had a space between the $where and [] that is not an array

       

          }

          mysql_close($conn1);

 

 

 

foreach($where as $val) {

include 'includes/configtask.php';

include 'includes/opendbtask.php';

    $query100 = "SELECT * FROM taskinfo WHERE Response = '$val' ORDER BY ID";

    $result100 = mysql_query($query100);

    $row100 = mysql_num_rows($result100);

        ?>

      <table cellpadding=2  width="750" table border = "0">

      <?php

      if(!$row100 ==0)

      {

      ?>

          <tr>

            <td>           

Open Tasks <?php echo $row100; ?>

</td>

<td>

          <?php

          $rows = mysql_fetch_assoc($result100);

          $test = $rows['Response']; 

          $conn2 = mysql_connect('local', 'local', '7sadfasZLXdfaadsV') or die(mysql_error());

              mysql_select_db('homefree');

 

 

$query6000 = "SELECT id,f_name, l_name FROM employees WHERE id = '$test'";

$result6000 = mysql_query($query6000) or die (mysql_error());

$row6000 = mysql_fetch_array($result6000);

$employeename = $row6000['f_name'] . ' ' . $row6000['l_name'];

mysql_close($conn2);

          ?>

              Person: <?php echo $employeename; ?>

              </td>

      </tr>

      </table>

  <?php

}}

 

 

 

Displaying

 

Open Tasks 1  Person: Employee name1

Open Tasks 1 Person: Employee name2

Open Tasks 6 Person: Employee name3

Open Tasks 1 Person: Employee name4

Link to comment
https://forums.phpfreaks.com/topic/91971-select-query-troubles/#findComment-471194
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.