21. září bude sraz! Od 18.00 v restauraci Tradice v Praze u Anděla
Autor Zpráva
PEKLO
Profil
Ahoj.vytvořil sem si databazi, ve ktere mam tabulku a tuto tabulku bych chtel vypisovat na html strance(i s rameckem) mohl by mi nekdo poradit jak na to? nejlip dyby mi nekdo mohl napsat php zdrojak jako priklad..Dekuju
peta
Profil
$dotaz = "SELECT * FROM `moje_tabulka`";
$vysl = sq($dotaz,' array show');
$pocet = mysql_num_rows($vysl);
if ($pocet>0)
{
while ($row = mysql_fetch_row($vysl))
{print_r($row);echo '<hr>';}
}

mm.gene.cz
google.com php mysql example



slozitejsi:
function eval_show2($filter = array())
{
global $CFG_SQLtable;

/*
$dotaz = "SELECT DISTINCT `HODNOTA_ODPOVEDI` FROM `$CFG_SQLtable`";
$vysl = sq($dotaz,' records show');
$pocet = mysql_num_rows($vysl);
$h = array();
if ($pocet>0)
{
while ($row = mysql_fetch_row($vysl))
{$h[] = $row[0];}
}
*/
global $arr_fakulta,$arr_katedra,$arr_predmet,$arr_odpovedi,$arr_tvrzeni;

$podm = array();
if (isset($filter['fakulta']))
{
$f = $filter['fakulta'];
if (array_key_exists($f,$arr_fakulta)) {$podm[] = "`FAKULTA`='$f'";}
}
if (isset($filter['katedra']))
{
$f = $filter['katedra'];
if (array_key_exists($f,$arr_katedra)) {$podm[] = "`KATEDRA`=' $f'";} // prvni je mezera!!!
}
if (isset($filter['predmet']))
{
$f = $filter['predmet']*1;
foreach($arr_predmet as $key=>$value)
{if (isset($value[$f])) {//echo '<hr>'.$value[$f].'<hr>';
$podm[] = "`CZ_NAZEV`=' ".$value[$f]."'"; break;}}
}

$v = array();
//$dotaz0 = "SELECT DISTINCT COUNT(`POCET`) as `suma` FROM `$CFG_SQLtable` "; //Excel Kontingencni tabulka
$dotaz0 = "SELECT DISTINCT SUM(`POCET`) as `suma` FROM `$CFG_SQLtable` ";
foreach($arr_odpovedi as $key1=>$value1)
{
$v['sumax'.$key1] = 0;
}
foreach($arr_tvrzeni as $key2=>$value2)
{
$v['sumay'.$key2] = 0;
}
foreach($arr_odpovedi as $key1=>$value1)
{
$podm1 = $podm;
$podm1[] = "`BODOVANI`=".$key1;
$v[$key1] = array();
foreach($arr_tvrzeni as $key2=>$value2)
{
$podm2 = $podm1;
$podm2[] = "`PORADI_TVRZENI`=".$key2;
$podm2 = implode(" AND ",$podm2);
$podm2 = ($podm2!="") ? "WHERE ".$podm2 : '';
$dotaz = $dotaz0.$podm2;
//echo '<sub>'.$dotaz.'</sub><hr>';
$vysl = sq($dotaz,' suma records show');
$res = mysql_result($vysl,0,'suma') * 1;
$v[$key1][$key2] = $res;
$v['sumax'.$key1]+= $res;
$v['sumay'.$key2]+= $res;
}
}

$h = '';
foreach($arr_tvrzeni as $key2=>$value2)
{$h.= '<th>'.$key2.'</th>';}
$h = "\n".'<tr><th>&nbsp;</th><th>Celkem</th>'.$h.'</tr>';

$b = '';
foreach($arr_odpovedi as $key1=>$value1)
{
$b.= "\n".'<tr><th>'.$value1.'</th><td><b>'.$v['sumax'.$key1].'</b></td>';
foreach($arr_tvrzeni as $key2=>$value2)
{
$b.= '<td>'.$v[$key1][$key2].'</td>';
}
$b.= '</tr>';
}
$b.= "\n".'<tr><th>&nbsp;</th><th>Celkem</th>';
foreach($arr_tvrzeni as $key2=>$value2)
{
$b.= '<td><b>'.$v['sumay'.$key2].'</b></td>';
}
$b.= '</tr>';
//$t = "\n".'<table border="1">'."\n".'<tbody>'.$b."\n".'</tbody>'."\n".'</table>';
$t = "\n".'<table class="tab_anketa" border="1" cellpadding="0" cellspacing="0" id="tab_anketa">'."\n".'<thead>'.$h."\n".'</thead>'."\n".'<tbody>'.$b. "\n".'</tbody>'."\n".'</table>';
return $t;
}

function get_array($key)
{
global $CFG_SQLtable;
$dotaz = "SELECT DISTINCT `$key` FROM `$CFG_SQLtable` ORDER BY `$key` ASC";
$vysl = sq($dotaz,' array show');
$pocet = mysql_num_rows($vysl);
$r = array();
if ($pocet>0)
{
while ($row = mysql_fetch_row($vysl))
{$r[] = $row[0];}
}
return $r;
}

Vaše odpověď


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0