I've got a minor problem in that I need to order results depending on what point in the display code I am.
$query = "SELECT name, price, id FROM table WHERE $conditions";
$results = mysql_query ($query);
while($line = mysql_fetch_assoc($results)){
echo "<TR>";
while(list($col_name, $col_value) = each($line)){
if($somecondition){
$cell = $col_value;
}
echo "<td>$cell</td>";
}
echo "</tr>";
}
This returns the way I want the results displayed
Name | Price | textbox with name as ID
Now the problem comes in here:
I need ID to be checked before name.
Name is made into a url as: /page.php?id=$id
If I change the Select statement to be: id, name, price its displayed that way which doesn't work.
So I need either a) a way to change the order of the results on the fly so I can grab the ID first and display it last or a way to get ID in name even though I haven't looped to it yet... that may be the simplest way... can you grab a specific result from $results? Something like:
$results looks like:
|name|price|id|
while($line = mysql_fetch_assoc($results)){
echo "<TR>";
while(list($col_name, $col_value) = each($line)){
if($col_name = $name){
$tmp = get_cell($results, 3); //invalid... what would be valid?
$col_value .= $tmp;
$cell = $col_value;
}
echo "<td>$cell</td>";
}
echo "</tr>";
}
Confused yet? 🙂
Mark