![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
The attached code works great. In an HTML table, it prints the "votes_up" value from a MySQL database for each "$row2" generated by a "while" loop. However, in an HTML table cell, I would like to print "votes_up" minus another value called "votes_down" I imagine that the first step would be to create a variable equal to "votes_up" minus "votes_down." But I don't know how to print this new variable for each "$row2" in the MySQL database. How do I do this? Thanks in advance, John print "<td>" .$row2['votes_up']. "</td>"; |
#3
| |||
| |||
|
|
.oO(ArizonaJohn) The attached code works great. In an HTML table, it prints the "votes_up" value from a MySQL database for each "$row2" generated by a "while" loop. However, in an HTML table cell, I would like to print "votes_up" minus another value called "votes_down" I imagine that the first step would be to create a variable equal to "votes_up" minus "votes_down." But I don't know how to this new variable for each "$row2" in the MySQL database. How do I do this? Thanks in advance, John print "<td>" .$row2['votes_up']. "</td>"; $votes_diff = $row2['votes_up'] - $row2['votes_down']; print "<td>$votes_diff</td>"; or print "<td>".($row2['votes_up'] - $row2['votes_down'])."</td>"; HTH Micha |
#4
| |||
| |||
|
|
The problem with that is that DW's design view won't understand it. I'd rather see you do it this way - ? $votes_diff = $row2['votes_up'] - $row2['votes_down']; ? td><?php echo $votes_diff?$votes_diff:' '; ?></td which will retain the validity of the HTML on your page. |
#5
| |||
| |||
|
|
Hello, The attached code works great. In an HTML table, it prints the "votes_up" value from a MySQL database for each "$row2" generated by a "while" loop. However, in an HTML table cell, I would like to print "votes_up" minus another value called "votes_down" I imagine that the first step would be to create a variable equal to "votes_up" minus "votes_down." But I don't know how to this new variable for each "$row2" in the MySQL database. How do I do this? Thanks in advance, John print "<td>" .$row2['votes_up']. "</td>"; |
#6
| |||
| |||
|
|
Alternatively: Here's your query: select (`votes_up` - `votes_down`) as votes_total from table; Then your HTML/PHP echo "<td>" .$row2['votes_total']. "</td>"; |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
Cosmo Kramer, thanks for your response. Your response looked like an easy solution, but I tried it and the HTML just printed out the code. Was it supposed to be within PHP or something? |
#9
| |||
| |||
|
|
.oO(Cosmo Kramer) Alternatively: Here's your query: select (`votes_up` - `votes_down`) as votes_total from table; Then your HTML/PHP echo "<td>" .$row2['votes_total']. "</td>"; CHEATER!!!1 ;-) OK, of course that would be another (and in fact the preferred) way. But you should remove the backticks - they're just damn ugly and not necessary in this case. Micha |
#10
| |||
| |||
|
|
The reason for the ternary operator was to insert a non-breaking space in the event that the value were null. This will prevent border/background color anomalies in some browsers when there is nothing in the table cell. |
![]() |
| Thread Tools | |
| Display Modes | |
| |