mysql array into table issue
Posted: Tue Jan 23, 2007 12:46 am
ok well i'm just trying to get my mysql array into a table for presentation on a webpage. However, I'm having the hardest time creating a table "foreach" array.
Don't mind the db_set_active () and the db_query(), its a simple modification of php statement for accessing another DB other than the default db for drupal coding(http://drupal.org/node/18429).
My goal is to have this array example created into an html table like so:
Don't mind the db_set_active () and the db_query(), its a simple modification of php statement for accessing another DB other than the default db for drupal coding(http://drupal.org/node/18429).
My goal is to have this array example created into an html table like so:
FYI I plan on using most of the entries into html my table, so don't worry about truncating the SQL statement.Array ( [0] => NX [ticker] => NX [1] => Quanex Cp [companyname] => Quanex Cp [2] => 0.14 [dividend] => 0.14 [3] => 450.61 [curass] => 450.61 [4] => 9.10 [multiplier] => 9.10 [5] => 1.82 [bookval] => 1.82 [6] => 130.68 [long_term_debt] => 130.68 [7] => 208.41 [total_cur_liabilities] => 208.41 [8] => 29.8 [past_5_earnings] => 29.8 [9] => 12.5 [future_5_earnings] => 12.5 [10] => 527.72 [annsales] => 527.72 [11] => 2007-01-21 03:01:55 [last_update_time] => 2007-01-21 03:01:55 [12] => 0 [rank] => 1 [13] => 3011 [stock_id] => 3011 [14] => [price] => [15] => 0 [score] => 0 [16] => 1 )
-----------------------------------------------------
|Company Name: | [companyname] Value|
|Ticker: | [ticker] Value |
|P/E Ratio: | [multiplier] Value |
-----------------------------------------------------
Code: Select all
function coldowl_mysql_retrieve(){
db_set_active('intelligent');
$mysql_query = "SELECT * , COUNT( stock_id ) AS rank FROM curldata WHERE annsales >= '100' AND dividend >0 AND multiplier <=17 AND multiplier >0 AND bookval >0 AND multiplier * bookval <= 22.5 AND past_5_earnings >= 16.5 AND curass / total_cur_liabilities >=2 GROUP BY 'stock_id' ORDER BY 'multiplier' DESC;";
$returnval = db_query($mysql_query);
$a_record = mysql_fetch_array($returnval);
print_r($a_record);
foreach ($a_record as $key => $value) {
print "<table><tr><td>Company Name</td><td>".$value['[companyname]']."<td></tr><tr><td>Ticker</td><td>".$value['[ticker]']."</td></tr><tr><td>Multiplier</td><td>".$value['[multiplier]']."</td></tr></table>";
}
db_set_active('default');
}
}