Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

add css code inside while loop <tr>

CSS loop

  • Please log in to reply
5 replies to this topic

#1 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 15 March 2012 - 11:00 PM

hi...

I have query to display data and I use while loop.

here is my code:
echo "<table id='kanban_list'>";
echo "<tr>
        <th><label>Display Details:</label><input  onclick='showDetails(this);' id='chkDetail'   type='checkbox' checked='checked' value='wip'/></th>
        <th> PCODE </th>
        <th> LOT CODE </th>
        <th> CHEMICAL WEIGHING </th>
        <th> COMPOUNDING </th>
        <th> EXTRUSION </th>
        <th> FORMING </th>
        <th> DEFLASHING </th>
        <th> KANBAN </th>
        <th> VIRTUAL </th>
        <th> TOTAL </th>
        <!--<th> MIN LOT </th>-->
     </tr>";  
$sql = "SELECT DISTINCT kd.PCODE, kc.count_wip_chemical_weighing, kc.count_wip_compounding, kc.count_wip_extrusion, 
kc.count_wip_forming, kc.count_wip_deflashing, kc.kanban, kc.virtual, kc.total FROM kanban_checker kc JOIN kanban_data kd ON kc.PCODE = kd.PCODE
ORDER BY kc.PCODE";
$result = mysql_query($sql, $con); 
while($row = mysql_fetch_assoc($result)){            
    echo "<tr>
        <td>Total Lot ID (Lot)</td>
        <td> $row[PCODE]</td>  
        <td> </td>
        <td> $row[count_wip_chemical_weighing]</td>                                          
        <td> $row[count_wip_compounding]</td>
        <td> $row[count_wip_extrusion]</td>
        <td> $row[count_wip_forming]</td>
        <td> $row[count_wip_deflashing]</td>
        <td> $row[kanban]</td>
        <td> $row[virtual]</td>
        <td> $row[total]</td>
       <!-- <td> $row[min_lot]</td>  -->
        </tr>";
}

$sql = "SELECT DISTINCT kd.PCODE, kdc.count_doz_chemical_weighing, kdc.count_doz_compounding, kdc.count_doz_extrusion, 
kdc.count_doz_forming, kdc.count_doz_deflashing, kdc.kanban_doz, kdc.virtual_doz, kdc.total_doz FROM kanban_checker_doz kdc JOIN kanban_data kd ON kdc.PCODE = kd.PCODE
WHERE kd.PCODE = '$row[PCODE]'
ORDER BY kdc.PCODE";
$result_qty = mysql_query($sql, $con);

while ($row_doz = mysql_fetch_assoc($result_qty)){
     echo "<tr>
        <td>Total Qty (Doz)</td>
        <!--<td> </td>  -->
        <td> $row_doz[PCODE]</td> 
        <td> </td>
        <td> $row_doz[count_doz_chemical_weighing]</td>                                          
        <td> $row_doz[count_doz_compounding]</td>
        <td> $row_doz[count_doz_extrusion]</td>
        <td> $row_doz[count_doz_forming]</td>
        <td> $row_doz[count_doz_deflashing]</td>
        <td> $row_doz[kanban_doz]</td>
        <td> $row_doz[virtual_doz]</td>
        <td> $row_doz[total_doz]</td>
       <!-- <td> $row[min_lot]</td>  -->
        </tr>";   
}
echo "</table>";

sample data:

Display Details---Compound---Chemical Weighing-----etc...
---------------------P28------------1.00----------------------------
---------------------P28------------250.00------------------------
---------------------P30------------2.00--------------------------
---------------------P30------------520.00---------------------
---------------------P32------------1.00----------------------------

I need to add alternate background color per compound.
for example:

P28 green
P30 yellow
P32 green
P33 yellow
and so on.

Any help is highly appreciated.

Thank you

---------------------P32------------520.00-----------------------
---------------------P33------------4.00----------------------------
---------------------P33------------1000.00---------------------
  • 0

#2 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1310 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 21 March 2012 - 07:42 PM

First of all, you are allowed to do this inside PHP:
if ($username == "user1"){ ?> Hey, how dare you?! 

Trying to sign in using 'user1' as a username is against the rules! <?php 
} else { ?> Sign-in successful! <?php }
, so you don't have to have all those 'echo' commands.

As for the CSS insertion part, you can have something like this:
?> <div style="color: <?php 
if ($value == "P28") print "green"; 
elseif ($value == .... 
... and so on ... 
?>;"> <?php 
echo ... 
?> </div> 
<?php

So that you check what field it is and then you print (or echo, if you like that better) the appropriate color.


P.S. This is probably the wrong forum; because it's more of a PHP question than a JavaScript/CSS question, this should probably go in the PHP forum.
  • 0
Regards,
RR

#3 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 22 March 2012 - 02:02 AM

even better to assign the div an class and put the css in the stylesheet file.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#4 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1310 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 22 March 2012 - 06:20 AM

Or ID.


For class:
.P28 { 
  color: ...; 
} 
.P29 { 
...
, and
... 
<div class="P28" ... 
<div class="P29" ... 
...


With ID:
#P28 { 
  color: ...; 
} 
#P29 { 
...
, and
...
<div id="P28" ... 
<div id="P29" ... 
...

  • 0
Regards,
RR

#5 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 23 March 2012 - 03:03 AM

If you'd use ID then you'll end up with multiple <div> elements having the same ID which is invalid for the HTML spec.
  • 0

#6 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1310 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 23 March 2012 - 09:04 AM

I thought he had only one of each P28, P29, etc., rows; well in this case then yes, you would want to use class.
  • 0
Regards,
RR





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download