Jump to content

tbajaj

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

tbajaj's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Need help in achieving a data entry grid. I have two tables am_user (idam_user, name) and am_activity (idam_act, act) with the data Data for am_user is 1, John 2, Mary 3, Kate Data for am_activity is 1, Cooking 2, Cleaning 3, Painting I have a third table that stores the role played by each user for the activities. am_role (idam_role, role) 1, Manage 2, Observe 3, Documents I want my User table to be my header, Activity table to my 1st column and Role table to populate the data grid [/td] [td]JohnMaryKate CookingManageDocumentObserve CleaningDocumentnullManage PaintingObserveDocumentManage By putting two while loops I am able to generate the header and 1st column but I need help in populating the grid in between. Also I want my data entry area (rows and column besides header and 1st column) to have lookup where they can select values from the am_role table. So, John can "Manage" "Painting" tomorrow if he wants to The two while loops are $query = "select idam_user, Name "; $query .= " from am_user "; $result = mysql_query($query) or die(mysql_error()); // display data in table echo "<center>"; echo "<table>"; echo "<tr>"; echo "<th></th>"; // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $result )) { // echo out the contents of each row into a table echo '<th>' . $row['name'] . ' '; echo "</th>"; } echo "</tr>"; $query = "select idam_act, act "; $query .= " from am_activity "; $result = mysql_query($query) or die(mysql_error()); // display data in table // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $result )) { // echo out the contents of each row into a table echo '<tr>'; echo '<td>' . $row['act'] . '</td>'; echo '</tr>'; } // close table> echo "</table>"; echo "</center>"; Please advise if this thought is realistic and how can I achieve it. Thanks in anticipation.
  2. Dear Laffin. I am very appreciative. I bow to your php skills. You are a life savior.
  3. Hello Laffin, thanks again. I have attached the complete file of code. These things are requesting your attention * Although the new piece of code you added is generating header but as a regular header and not transposed. * After I execute that piece of code, my index is reaching end of array, so I ended up fetching again, may be you know how to fix that too Finally, I made minor modification like concatenation to html variable, instead of echoing. That is just FYI. Please advise. Thanks 17347_.php
  4. Dear Laffin, I feel like giving you a hug. Very simple and elegant code. I had to make minor modifications and I am glad that I also used my brain besides picking yours. My code need one more blessing. How do I put Column Titles as my first Column? So, if you see my example, my first row was actually column name from the table. I really appreciate it. Thanks
  5. Here is the code I am struggling with. I thought it was not taking me anywhere because the output is only 2 columns <?php $link = mysql_connect("myserver", "mylogin", "mypass123"); if (!$link) { die('Not connected : ' . mysql_error()); } $hostname = mysql_get_host_info($link); // make ddms the current db $db_selected = mysql_select_db("primarydb", $link); if (!$db_selected) { die ('Can\'t use ddms : ' . mysql_error()); } //this is just a marker to see where I am on the output //printf("%s\n", "XXX"); // Get all the data from the table $result = mysql_query("SELECT EmpID, FirstName, DoJ, Supervisor FROM primarydb.projects where projectID like '34%'; ") or die(mysql_error()); $html = "<table border=1>"; //printf("%s\n", "YYY"); $numOfCols = mysql_num_fields($result); $numOfRows = mysql_num_rows($result); $info = mysql_fetch_assoc($result); if($numOfRows > 0){ do { foreach($info as $column => $value) { $html.= "<tr><td>$column</td><td>$value</td></tr>"; } } while ($info = mysql_fetch_array($result)); } $html.= "</table>"; mysql_free_result($result); echo $html; ?>
  6. I am fetching a data from database which comes out like this EmpID First Name DoJ Supervisor '34698' 'Ian Bobby' '2011-08-09' 'Daniel Lin' '34684' 'Sally Dodd' '2011-08-09' 'James Kirk' '34871' 'Alan Dandy' '2011-08-09' 'Pamela Roy' I want to Transpose it like this EmpID '34698' '34684' '34871' First Name 'Ian Bobby' 'Sally Dodd' 'Alan Dandy' DoJ '2011-08-09' '2011-08-09' '2011-08-09' Supervisor 'Daniel Lin' 'James Kirk' 'Pamela Roy' Please help
×
×
  • 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.