OK..I thought somewhere I saw a way to place something into the output (echo, print...etc) but not have it actually print out.
The reson I need this function, is that I have a javascript as my governing sorter for a table. This is because I do not want the page to have to reload when you want it sorted by a different field. However, it sorts only alphabetically, and one of the fileds needs to be sorted differently. As a fix I have placed a 0 in front of the one that comes first, a 1 infront of the second..etc...
Now, the numbers are included in the output of the table, but I don't want the to display. Is there a function that leaves the number there for sorting purposes, but will not actually print it?
The javascript sorter:
<script type="text/javascript">
function compare(a,b)
{
au = new String(a)
bu = new String(b)
var an = parseInt(au)
var bn = parseInt(bu)
if (isNaN(an) || isNaN(bn))
{as = au.toLowerCase()
bs = bu.toLowerCase()
if (as > bs)
{return 1;}
else
{return -1;}
}
else {
return an - bn;
}
}
// DOM table sorter borrowed (but modified) from Paul Sowden
// Finally somone that does it the right way
// function borrowed from those lovely people at the w3c
function getConcatenedTextContent(node) {
var _result = "";
if (node == null) {
return _result;
}
var childrens = node.childNodes;
var i = 0;
while (i < childrens.length) {
var child = childrens.item(i);
switch (child.nodeType) {
case 1: // ELEMENT_NODE
case 5: // ENTITY_REFERENCE_NODE
_result += getConcatenedTextContent(child);
break;
case 3: // TEXT_NODE
case 2: // ATTRIBUTE_NODE
case 4: // CDATA_SECTION_NODE
_result += child.nodeValue;
break;
case 6: // ENTITY_NODE
case 7: // PROCESSING_INSTRUCTION_NODE
case 8: // COMMENT_NODE
case 9: // DOCUMENT_NODE
case 10: // DOCUMENT_TYPE_NODE
case 11: // DOCUMENT_FRAGMENT_NODE
case 12: // NOTATION_NODE
// skip
break;
}
i ++;
}
return _result;
}
function sort(e) {
var el = window.event ? window.event.srcElement : e.currentTarget;
// a pretty ugly sort function, but it works nonetheless
var a = new Array();
var name = el.firstChild.nodeValue;
var dad = el.parentNode;
var node;
for (var i = 0; (node = dad.getElementsByTagName("td").item(i)); i++) {
if (node.firstChild.nodeValue == name) break;
}
var tbody = dad.parentNode.parentNode.getElementsByTagName("tbody").item(0);
for (var j = 0; (node = tbody.getElementsByTagName("tr").item(j)); j++) {
// crude way to sort by surname and name after first choice
a[j] = new Array();
a[j][0] = getConcatenedTextContent(node.getElementsByTagName("td").item(i));
a[j][1] = getConcatenedTextContent(node.getElementsByTagName("td").item(1));
a[j][2] = getConcatenedTextContent(node.getElementsByTagName("td").item(0));
a[j][3] = node;
}
a.sort(compare);
// not a perfect way to check, but hell, it suits me fine
if (a[0][0] == getConcatenedTextContent(tbody.getElementsByTagName("tr").item(0).getElementsByTagName("td").item(i))
&& a[1][0] == getConcatenedTextContent(tbody.getElementsByTagName("tr").item(1).getElementsByTagName("td").item(i))) a.reverse();
for (var j = 0; j < a.length; j++) {
tbody.appendChild(a[j][3]);
}
}
function init(e) {
var thead = document.getElementById('memberslist').getElementsByTagName("thead").item(0);
var node;
for (var i = 0; (node = thead.getElementsByTagName("td").item(i)); i++) {
if (node.addEventListener) node.addEventListener("click",sort,false);
else if (node.attachEvent) node.attachEvent("onclick",sort);
}
// go on with the stuff
}
if (window.addEventListener) window.addEventListener("load",init,false);
else if (window.attachEvent) window.attachEvent("onload",init);
</script>
The table contents (not headers) generated by php:
{echo "
<tr>
<td>".$members[$i]['nick name' ]."</td>
<td>".$members[$i]['rank' ]." ".$members[$i]['rank name' ]."</td> // This is the field that needs to be sorted differently
<td>".$members[$i]['level' ]."</td>
<td>".$members[$i]['profession']."</td>
<td>".$members[$i]['gender' ]."</td>
<td>".$members[$i]['breed' ]."</td>
</tr>";
$i++;
}
$members[$i]['rank' ] is the number associated with the ranking level.
$members[$i]['rank name' ] is the actual name of the rank..President, Genreal, Unit Commander...etc.
I need $members[$i]['rank' ] to be used, but invisible to the page.