Jump to content

viper3two

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

viper3two's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [!--quoteo(post=352154:date=Mar 6 2006, 01:51 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 6 2006, 01:51 PM) [snapback]352154[/snapback][/div][div class=\'quotemain\'][!--quotec--] Well you need to add some code before and after your loop to get it to alternate colors. Here is the code first we set the row color before the loop [code]$bgcolor = '#FFFF00'; //yellow cause you want to start with blue [/code] Then at the start of the loop we have a check to change the color if it is one or the other [code]if ($bgcolor == "#FFFF00"){   $bgcolor = "#0000FF"; } else {   $bgcolor = "#FFFF00"; }[/code] Now we can put everything together [code]$bgcolor = '#FFFF00'; //yellow cause you want to start with blue $display_block .= " <table cellpadding=3 cellspacing=2 border=0 width=98%> <tr> <th>First Name</th> <th>Last Name</th> <th>Title</th> <th>Picture</th> </tr>"; while ($newArray = mysql_fetch_array($result)) { // altername the colors if ($bgcolor == "#FFFF00"){   $bgcolor = "#0000FF"; } else {   $bgcolor = "#FFFF00"; } $empnumber = $newArray['EmpNo']; $firstname = $newArray['FstName']; $lastname = $newArray['LstName']; $title = $newArray['Title']; $department = $newArray['HmDept']; $picfile = $newArray['PictureFile']; $display_block .= "<tr bgcolor=$bgcolor> <td align=center>$lastname <br> </td> <td align=center>$firstname <br> </td> <td align=center>$title <br> </td> <td align=center><img src=/EmployeeDirectory/database/$picfile> <br> </td> </tr>"; }[/code] Also the code to take out borders is border=0 Ray [/quote] Thank you Ray. I put in your code and read through it to understand how it works now. I appreciate your help! Tony
  2. Just a quick question, I have a table that will display an employee's demographics. What is the code to make the borders not visible, and also to change the cell row colors EG: Blue first Row Yellow second row and alternate back and forth? Here is what I have, it works, but it is just a plain vanilla table: $display_block .= " <table cellpadding=3 cellspacing=2 border=1 width=98%> <tr> <th>First Name</th> <th>Last Name</th> <th>Title</th> <th>Picture</th> </tr>"; while ($newArray = mysql_fetch_array($result)) { $empnumber = $newArray['EmpNo']; $firstname = $newArray['FstName']; $lastname = $newArray['LstName']; $title = $newArray['Title']; $department = $newArray['HmDept']; $picfile = $newArray['PictureFile']; $display_block .= "<tr> <td align=center>$lastname <br> </td> <td align=center>$firstname <br> </td> <td align=center>$title <br> </td> <td align=center><img src=/EmployeeDirectory/database/$picfile> <br> </td> </tr>"; } and then in the HTML: <html> <head> <title>Administration</title> </head> <body> <p align="center"><a name="top" id="top"></a></p> <p align="center"><a name="top" id="top"></a></p> <p align="center"><font face="Arial" size="3">Administration</font></p> <?php echo $display_block; ?> </body> </html> Thanks for the reply in advance! You guys are awesome! Tony
  3. [!--quoteo(post=352086:date=Mar 6 2006, 09:46 AM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 6 2006, 09:46 AM) [snapback]352086[/snapback][/div][div class=\'quotemain\'][!--quotec--] Let mysql do that. SELECT * FROM eelist WHERE HmDept='001' ORDER BY LstName [/quote] Thank you! I will give that a try and see what happens. Appreciate it! Tony
  4. Hello, I am designing a webpage that reads a database in mysql and I am trying to sort and display the results. This example, I open my database, and pull it into an array. I want to search that array for HmDept="001", then sort the results by alpha (LstName). Can any body help me? Here is the code that I have so far: <?php $conn = mysql_connect("localhost", "root", "cpsint"); mysql_select_db("employees",$conn); $sql = "SELECT * FROM eelist"; $result = mysql_query($sql, $conn) or die(mysql_error()); $display_block = ""; if (mysql_num_rows($result) < 1) { //no record found $display_block .= "<p>No Record Found</p>"; } else { $display_block .= " <table cellpadding=3 cellspacing=2 border=1 width=98%> <tr> <th>First Name</th> <th>Last Name</th> <th>Title</th> <th>Picture</th> </tr>"; while ($newArray = mysql_fetch_array($result)) { $empnumber = $newArray['EmpNo']; $firstname = $newArray['FstName']; $lastname = $newArray['LstName']; $title = $newArray['Title']; $department = $newArray['HmDept']; $picfile = $newArray['PictureFile']; ///////THIS IS WHERE I NEED THE HELP :)/////// //////I WANT TO DISPLAY ONLY DEPARTMENT "001" /////// //////THEN SORT IT ALPHABETICALLY BY LastName////// if ($department == "001") { $display_block .= "<tr> <td align=center>$lastname <br> </td> <td align=center>$firstname <br> </td> <td align=center>$title <br> </td> <td align=center><img src=/EmployeeDirectory/database/$picfile> <br> </td> </tr>"; } } } ?> <html> <head> <title>Administration</title> </head> <body> <p align="center"><a name="top" id="top"></a></p> <p align="center"><a name="top" id="top"></a></p> <p align="center"><font face="Arial" size="3">Administration</font></p> <?php echo $display_block; ?> </body> </html> THANK YOU IN ADVANCE FOR THE HELP!!!! Tony
×
×
  • 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.