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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.