Home Forums Chart Support Issues retrievng data from MySql Reply To: Issues retrievng data from MySql

#7475

Ok, at this file: http://parles.upf.edu/llocs/adljc/grafics/graf_tipus_recursos.php I have put this query:
SELECTTipus_1AS 'Tipus', COUNT(*) AS 'Recursos' FROMvaluesGROUP BYTipus_1DESC

You can see the resulting table under the graphic.

The complete code for rendering the table is this one:

<?php
include ("../admin/dbconnect.php");
$query= "SELECT <code>Tipus_1</code> AS 'Tipus', COUNT(*) AS 'Recursos' FROM <code>values</code> GROUP BY <code>Tipus_1</code> DESC";
$result = mysql_query($query);
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<table class='sortable'><tr>";

// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td align=center>".strtr(" {$field->name} ", $transname)."</td>";
}
echo "</tr>\n";
// printing table rows

while($row = mysql_fetch_row($result))
{
    echo "<tr onMouseOver=this.bgColor='#e0e0e7'; onMouseOut=this.bgColor='white';>";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td align=center>$cell</td>";
    echo "</tr>\n";
}
mysql_free_result($result);
?>

2. Type of data: Tipus_1 set(‘lingüístic’,’jurídic’) NOT NULL,