Drewser33 Posted February 19, 2008 Share Posted February 19, 2008 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!! Quote Link to comment Share on other sites More sharing options...
chronister Posted February 19, 2008 Share Posted February 19, 2008 <?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 Quote Link to comment Share on other sites More sharing options...
Drewser33 Posted February 19, 2008 Author Share Posted February 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
Drewser33 Posted February 19, 2008 Author Share Posted February 19, 2008 OK by removing the while in your coding I only get one "ARRAY" by each result, which would be perfect if I can manipulate that "ARRAY" to be equal to variables or include variables this will work great. Quote Link to comment Share on other sites More sharing options...
Drewser33 Posted February 19, 2008 Author Share Posted February 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.