Jump to content

Add Some Features Of A Display Table


yangkai9999
 Share

Recommended Posts

Hi all,Now, I can use the following code to display the all records in table p2. But I still have a number of things need to be done.1. for each column, I need to add title. the titles' name are difference with fields' name from table p2 (Ex. P_id from p2 can say "patient ID", that one is meaningful for end user). 2. and can be sorted by click the title's name.3. the column color should be difference one another (for example: col1:#99cccc; col2:99ffcc;col3:#99cccc; col4:99ffcc....)4. for each record, I need add a check box at left side as selection flag (can be using to delete or export or ... for future).I don't anticipate getting whole solutions at once. But I appreciate if anyone can help me to solve any little piece of my question.Thank you,<html><head><title>Browse all records from P2</title></head><body><?php$db="mytest";$link = mysql_connect("localhost","root","Openit4me");if (! $link) die("Couldn't connect to MySQL");mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());$result = mysql_query( "SELECT * FROM mytest.p2" ) or die("SELECT Error: ".mysql_error());$num_rows = mysql_num_rows($result);echo "There are $num_rows records.<P>";echo "<table width=800 border=1>\n";$get_field = mysql_fetch_field($result);while ($get_info = mysql_fetch_row($result)){ echo "<tr>\n";foreach ($get_info as $field) echo "\t<td bgcolor='#99cccc'> <font face=arial size=2/>$field</font></td>\n";echo "</tr>\n";}echo "</table>\n";mysql_close($link);?></body></html>

Link to comment
Share on other sites

Hi all,Now, I can use the following code to display the all records in table p2. But I still have a number of things need to be done.1. for each column, I need to add title. the titles' name are difference with fields' name from table p2 (Ex. P_id from p2 can say "patient ID", that one is meaningful for end user). 2. and can be sorted by click the title's name.3. the column color should be difference one another (for example: col1:#99cccc; col2:99ffcc;col3:#99cccc; col4:99ffcc....)4. for each record, I need add a check box at left side as selection flag (can be using to delete or export or ... for future).I don't anticipate getting whole solutions at once. But I appreciate if anyone can help me to solve any little piece of my question.Thank you,<html><head><title>Browse all records from P2</title></head><body><?php$db="mytest";$link = mysql_connect("localhost","root","Openit4me");if (! $link) die("Couldn't connect to MySQL");mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());$result = mysql_query( "SELECT * FROM mytest.p2" ) or die("SELECT Error: ".mysql_error());$num_rows = mysql_num_rows($result);echo "There are $num_rows records.<P>";echo "<table width=800 border=1>\n";$get_field = mysql_fetch_field($result);while ($get_info = mysql_fetch_row($result)){ echo "<tr>\n";foreach ($get_info as $field) echo "\t<td bgcolor='#99cccc'> <font face=arial size=2/>$field</font></td>\n";echo "</tr>\n";}echo "</table>\n";mysql_close($link);?></body></html>
Hi all,Now, I got Q1 and Q3 solutions using the following code. I still need more help for another 3 questions.Thank you,code:<html><head><title>Browse all records from P2</title></head><body><?php$db="mytest";$link = mysql_connect("localhost","root","Openit4me");if (! $link) die("Couldn't connect to MySQL");mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());$result = mysql_query( "SELECT * FROM mytest.p2" ) or die("SELECT Error: ".mysql_error());$num_rows = mysql_num_rows($result);mysql_close($link);echo "There are $num_rows records.<P>";echo "<center><h3><font face=arial> My test project II </font></center></h3>" ;echo "<center><h4><font face=arial> Browse all records from table p2 </font></center></h4>";echo " <table align=center height=69 > <tr bgcolor='#AA9E7A'> <font face=arial size=2/><td width=100><font face=arial size=2/><div align=center><strong>Patient ID</strong></div></font></td> <td width=100><font face=arial size=2/><div align=center><strong>Name</strong></div></font></td> <td width=100><font face=arial size=2/><div align=center><strong>Education</strong></div></font></td> <td width=248><font face=arial size=2/><div align=center><strong>Address</strong></div></font></td> <td width=100><font face=arial size=2/><div align=center><strong>Family number</strong></div></font></td> <td width=100><font face=arial size=2/><div align=center><strong>Test order</strong></div></font></td> </tr>"; while ($row= mysql_fetch_array($result)){ //loop until all records from the table are selected echo "<tr>"; echo "<td bgcolor='#A3D5E4'><font face=arial size=2/>". $row[ 'P_ID' ] ."</font></td>"; echo "<td bgcolor='#ADD2D3'><font face=arial size=2/>". $row[ 'v1' ] ."</font></td>"; echo "<td bgcolor='#A3D5E4'><font face=arial size=2/>". $row[ 'V2' ] ."</font></td>"; echo "<td bgcolor='#ADD2D3'><font face=arial size=2/>". $row[ 'V3' ] ."</font></td>"; echo "<td bgcolor='#A3D5E4'><font face=arial size=2/>". $row[ 'V4' ] ."</font></td>"; echo "<td bgcolor='#ADD2D3'><font face=arial size=2/>". $row[ 'V5' ] ."</font></td>"; echo "</tr>";} echo "</table>"; ?></body></html>
Link to comment
Share on other sites

I've used this before to sort a table using java script:http://yoast.com/articles/sortable-table/For the checkboxes, just add a new TD with the checkbox in it. Make sure to give the checkbox either a name or value that contains the ID of the row.
I followed the instruction to change my code like this (see bellow), but it doesn't work. Where is problem of the change?Thanks,<html><head> <script type="text/javascript" src="sortable.js" id="mybrowse"></script> <title>Browse all records from P2</title></head><body><?php$db="mytest";$link = mysql_connect("localhost","root","Openit4me");if (! $link) die("Couldn't connect to MySQL");mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());$result = mysql_query( "SELECT * FROM mytest.p2" ) or die("SELECT Error: ".mysql_error());$num_rows = mysql_num_rows($result);mysql_close($link);//this is my debug;echo "There are $num_rows records.<P>";//add titles;echo "<center><h3><font face=arial> My test project II </font></center></h3>" ;echo "<center><h4><font face=arial> Browse all records from table p2 </font></center></h4>";//<tr bgcolor='#AA9E7A'> is used to add color for whole row;echo " <table class='sortable' id='mybrowse' align=center height=69 > <tr bgcolor='#AA9E7A'><th width=100><font face=arial size=2/><div align=center><strong>Patient ID</strong></div></font></th> <th width=100><font face=arial size=2/><div align=center><strong>Name</strong></div></font></th> <th width=100><font face=arial size=2/><div align=center><strong>Education</strong></div></font></th> <th width=248><font face=arial size=2/><div align=center><strong>Address</strong></div></font></th> <th width=100><font face=arial size=2/><div align=center><strong>Family number</strong></div></font></th> <th width=100><font face=arial size=2/><div align=center><strong>Test order</strong></div></font></th> </tr>"; //<td bgcolor='#A3D5E4'> is used to add color for each column;while ($row= mysql_fetch_array($result)){ //loop until all records from the table are selected echo "<tr>"; echo "<td bgcolor='#A3D5E4'><font face=arial size=2/>". $row[ 'P_ID' ] ."</font></td>"; echo "<td bgcolor='#ADD2D3'><font face=arial size=2/>". $row[ 'v1' ] ."</font></td>"; echo "<td bgcolor='#A3D5E4'><font face=arial size=2/>". $row[ 'V2' ] ."</font></td>"; echo "<td bgcolor='#ADD2D3'><font face=arial size=2/>". $row[ 'V3' ] ."</font></td>"; echo "<td bgcolor='#A3D5E4'><font face=arial size=2/>". $row[ 'V4' ] ."</font></td>"; echo "<td bgcolor='#ADD2D3'><font face=arial size=2/>". $row[ 'V5' ] ."</font></td>"; echo "</tr>";} echo "</table>"; ?></body></html>
Link to comment
Share on other sites

You have an ID on your script tag, but other than that the code looks fine. Relatively speaking, at least. You're using a lot of really old ways to do things. E.g., instead of this:<tr bgcolor='#AA9E7A'><th width=100><font face=arial size=2/><div align=center><strong>Patient ID</strong></div></font></th>I would do this:<tr style="background-color: #AA9E7A"><th style="width: 100px; font: bold 12px arial,sans-serif; text-align: center;">Patient ID</th>

Link to comment
Share on other sites

You have an ID on your script tag, but other than that the code looks fine. Relatively speaking, at least. You're using a lot of really old ways to do things. E.g., instead of this:<tr bgcolor='#AA9E7A'><th width=100><font face=arial size=2/><div align=center><strong>Patient ID</strong></div></font></th>I would do this:<tr style="background-color: #AA9E7A"><th style="width: 100px; font: bold 12px arial,sans-serif; text-align: center;">Patient ID</th>
I drop the ID part from my script tag and the script still doesn't work.I look at their example html file and found out the sample file are not php file. Do you think this is a problem cause that JS script doesn't work? Should I move out the part of tr part from PHP tag?Thank you,
Link to comment
Share on other sites

It doesn't matter that it's PHP. Check Firebug to make sure there aren't any Javascript errors, and check the Net tab to make sure the sortable.js script file is being downloaded.
I found the code works fine on Firefox, but doesn't work on IE. How to change the code to make the one working on both web browse?Thanks,
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...