473,385 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Mysql data display in a HTML Table layout, with alt row bg color Using php

Hi, iam trying to display student names along with their course selected and status of their selection, from mysql db, the result has to be in tabular format, with alternate row bg color, here is my code, please help me out...
Please share a complete code, i will be very thankful
Expand|Select|Wrap|Line Numbers
  1. <? 
  2. include('config.php');
  3.  
  4. echo "<a href='Student Details Form.php'>New Record</a>"; 
  5.  
  6. echo "<table border=2 >"; 
  7. echo "<tr>"; 
  8. echo "<td><b>Sl No.</b></td>"; 
  9. echo "<td><b>Student Name</b></td>"; 
  10. echo "<td><b>Course Applied</b></td>"; 
  11. echo "<td><b>Status</b></td>"; 
  12. echo "</tr>"; 
  13.  
  14. $result = mysql_query("SELECT `stud_name` AS 'Student Name', `course_studying` AS 'Course Applied', `status` AS 'Status' FROM `cjet`.`student_details` WHERE `status` = 'Selected'") or trigger_error(mysql_error()); 
  15. while($row = mysql_fetch_array($result)){
  16.  
  17. foreach($row AS $key => $value) { $row[$key] = stripslashes($value);
  18.  } 
  19. echo "<tr bgcolor= '$bgcolor'>";  
  20. echo "<td valign='top'>" . nl2br( $row['stud_id']) . "</td>";  
  21. echo "<td valign='top'>" . nl2br( $row['stud_name']) . "</td>";  
  22. echo "<td valign='top'>" . nl2br( $row['course_studying']) . "</td>";  
  23. echo "<td valign='top'>" . nl2br( $row['status']) . "</td>";  
  24. echo "<td valign='top'><a href=edit.php?id={$row['stud_id']}>Edit</a></td><td><a href=delete.php?id={$row['stud_id']}>Delete</a></td>"; 
  25. echo "</tr>"; 
  26. echo "</table>"; 
  27. echo "<a href='Student Details Form.php'>New Record</a>"; 
  28. ?>
  29.  
Oct 1 '10 #1
4 4041
Expand|Select|Wrap|Line Numbers
  1. <? 
  2. include('config.php');
  3.  
  4. echo "<a href='Student Details Form.php'>New Record</a>"; 
  5.  
  6. echo "<table border=2 >"; 
  7. echo "<tr>"; 
  8. echo "<td><b>Sl No.</b></td>"; 
  9. echo "<td><b>Student Name</b></td>"; 
  10. echo "<td><b>Course Applied</b></td>"; 
  11. echo "<td><b>Status</b></td>"; 
  12. echo "</tr>"; 
  13.  
  14. $result = mysql_query("SELECT `stud_name` AS 'Student Name', `course_studying` AS 'Course Applied', `status` AS 'Status' FROM `cjet`.`student_details` WHERE `status` = 'Selected'") or trigger_error(mysql_error()); 
  15. $i=0;
  16. while($row = mysql_fetch_array($result)){
  17. ($i%2 == 0) ? $bgcolor = "#ff0000" : $bgcolor = "#0000ff";
  18. foreach($row AS $key => $value) { $row[$key] = stripslashes($value);
  19.  } 
  20. echo "<tr bgcolor= '$bgcolor'>";  
  21. echo "<td valign='top'>" . nl2br( $row['stud_id']) . "</td>";  
  22. echo "<td valign='top'>" . nl2br( $row['stud_name']) . "</td>";  
  23. echo "<td valign='top'>" . nl2br( $row['course_studying']) . "</td>";  
  24. echo "<td valign='top'>" . nl2br( $row['status']) . "</td>";  
  25. echo "<td valign='top'><a href=edit.php?id={$row['stud_id']}>Edit</a></td><td><a href=delete.php?id={$row['stud_id']}>Delete</a></td>"; 
  26. echo "</tr>"; 
  27. $i++;
  28. echo "</table>"; 
  29. echo "<a href='Student Details Form.php'>New Record</a>"; 
  30. ?>
  31.  
Change the colors as you like.
Oct 1 '10 #2
Thank you boss,

well i have one more question, how do i display Sl No., right now as you can see i am using the following code to display Serial Number - 'stud_id'
Expand|Select|Wrap|Line Numbers
  1. echo "<td><b>Sl No.</b></td>"; 
  2.  
corresponding to
Expand|Select|Wrap|Line Numbers
  1. echo "<td valign='top'>" . nl2br( $row['stud_id']) . "</td>"; 
  2.  
the stud_id value changes if i delete a student from the table, or when the list has only 'Selected' students name, how to implement a Sequential numbering.

I hope iam clear with the above question
Oct 1 '10 #3
Hi,

you can simply show the looping variable as serial number.

Expand|Select|Wrap|Line Numbers
  1.  echo "<td><b>". $i ."</b></td>";
Oct 1 '10 #4
Hi, i tried both the above solutions - 1) to change the alternate row bg color & 2) serial number,

doesn't work,
can anybody please look into this here is my updated code
Expand|Select|Wrap|Line Numbers
  1. <style type="text/css">
  2. table.tbg {
  3.     text-align:center;
  4. }
  5. </style>
  6. <? 
  7. include('config.php');
  8.  
  9. echo "<a href='Student Details Form.php'>New Record</a>"; 
  10.  
  11. echo "<table border=2 class='tbg'>"; 
  12. echo "<tr>"; 
  13. echo "<td><b>Sl No.</b></td>"; 
  14. echo "<td><b>Student Name</b></td>"; 
  15. echo "<td><b>Course Applied</b></td>"; 
  16. echo "<td><b>Status</b></td>"; 
  17. echo "</tr>"; 
  18.  
  19. $result = mysql_query("SELECT stud_id, stud_name, course_studying, status FROM cjet.student_details  WHERE status = 'Selected' ") or trigger_error(mysql_error()); 
  20.  
  21. $i=0;
  22.  
  23. while($row = mysql_fetch_array($result)){
  24.  
  25. ($i%2 == 0) ? $bgcolor = "#ff0000" : $bgcolor = "#0000ff";
  26.  
  27. foreach($row AS $key => $value) { $row[$key] = stripslashes($value); 
  28.  } 
  29. echo "<tr bgcolor= '$bgcolor'>";  
  30. echo "<td valign='top'><b>". $i ."</b></td>";  
  31. echo "<td valign='top'>" . nl2br( $row['stud_name']) . "</td>";  
  32. echo "<td valign='top'>" . nl2br( $row['course_studying']) . "</td>";  
  33. echo "<td valign='top'>" . nl2br( $row['status']) . "</td>";  
  34. echo "<td valign='top'><a href=edit.php?id={$row['stud_id']}>Edit</a></td><td><a href=delete.php?id={$row['stud_id']}>Delete</a></td>"; 
  35. echo "</tr>"; 
  36. echo "</table>"; 
  37. echo "<a href='Student Details Form.php'>New Record</a>"; 
  38. ?>
  39.  
  40.  
Oct 4 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Antoni | last post by:
Hello, I wondered if anyone could offer some guidance, I trying to write a php script to connect to a database, and display the records in a table. I found the code here in a php4 text, and...
28
by: Anthony Williams | last post by:
Good morning, I'm currently designing a site, using CSS, and wish to create a variable width two-column layout, with header and footer, and one fixed-width column on the left. Previously, I...
0
by: Joey Martin | last post by:
This is urgent, so any quick help is much appreciated!!!! I have an ASP page that pulls data from a SQL table and puts it into a basic html table. This is basic stuff. I moved my pages from a...
0
by: Kamal Ahmed | last post by:
Hi All, I am using Asp.Net 1.1 inline coding with MS SQL Server as a backend for developing a solution. My requirement is to generate HTML Table as a cross tab to display columns an Rows and to...
3
by: rahul agarwal | last post by:
Hi All, I want to get data in an HTML table on an ASP.net page using C#. Please tell me how this can be done Thanx
4
nirmalsingh
by: nirmalsingh | last post by:
hi everybody, i want to enter some data in text box and load it in html table for viewing purpose. atlast i want read all the data from html table and save in database.help me to do this? 1.how to...
4
by: sandeep123456 | last post by:
hi, can we send data from html to excel sheet using java script sandeep
2
by: pavani1 | last post by:
Hi, I have to move my data from one table to another table in database when some condition is true. plz tell that how to start logic.
5
by: Ashish101 | last post by:
Hi, I have a html table with data. Now when I select a particular row, I need the data of all the cells of that row how would I do Kindly help Thanx in advance
3
by: abhishek1234321 | last post by:
I have a form at http://www.vtuhub.com/w.html which shows results if a proper roll number is entered... the results are fetched from http://results.vtu.ac.in site and only the table is shown... now i...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.