Jump to content

How do you add the dollar sign to the results of a query?


strago

Recommended Posts

How do you add the dollar sign to the results of a query?

$query = "SELECT Table1,Table2,Table3 FROM database ORDER BY $order DESC LIMIT $start_from, 50";

shows the amount

$query = "SELECT Table1,Table2,'$'Table3 FROM database ORDER BY $order DESC LIMIT $start_from, 50";

removes the amount and only shows the dollar sign.

 

Complete script...

 

 

/* construct and run our query */
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 50;
$query = "SELECT Table1,Table2,'$'Table3 FROM database ORDER BY $order DESC LIMIT $start_from, 50";
$result = mysql_query ($query);

/* make sure data was retrieved */
$numrows = mysql_num_rows($result);
if ($numrows == 0) {
    echo "No data to display!";
    exit;
}

/* now grab the first row and start the table */
$row = mysql_fetch_assoc ($result);
echo "<TABLE border=1>\n";
echo "<TR>\n";
foreach ($row as $heading=>$column)
{
    /* check if the heading is in our allowed_order
     * array. If it is, hyperlink it so that we can
     * order by this column */
    echo "<TD><b>";
    if (in_array ($heading, $allowed_order)) {
        echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading\">$heading</a>";
    } else {
        echo $heading;
    }                
    echo "</b></TD>\n";
}
echo "</TR>\n";

/* reset the $result set back to the first row and
 * display the data */
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
    echo "<TR>\n";
    foreach ($row as $column) {
        echo "<TD>$column</TD>\n";
    }
    echo "</TR>\n";
}
echo "</TABLE>\n";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.