Autor Zpráva
peta
Profil *
mam jednoduchou tabulku

CREATE TABLE pp_laws (
id int(11) NOT NULL auto_increment,
priority tinyint(4) UNSIGNED default NULL,
laws set('a','b','c','d') default 1,
PRIMARY KEY(id),
KEY (laws)
) TYPE=MyISAM COLLATE cp1250_general_ci;

A ted potrebuji v PHP vypsat zahlavi + obsah
Problem je, ze chci hlavicku ve formatu
=== id, priority, 'a', 'b' , 'c', 'd' ===

Co jsem zkousel:
1)
ALE pouzitim
$dotaz="DESCRIBE $tab";
dostanu klasicky tvar
=== id, priority, laws ===
2)
Pouzit klasicky select
$dotaz = "SELECT * FROM $tab";
, ze bych si rozparsoval sloupec laws nemuzu, protoze plna prava nemusi mit uzivatel nastavena.
3)
Jedina pozitelna cesta je pro mne zatim pres
$dotaz="SHOW CREATE TABLE $tab";
Jenze to se musi slozite rozparsovat nebo aspon substringovat a kdyz nahodou pridam nejaky sloupec, tak to musim cele zmenit.

Co by jste poradili?
tiso
Profil
Neviem či som to správne pochopil ale buď si napíš 4 stĺpce miesto jedného - laws, alebo si vyber a vypíš riadky kde laws <= práva užívateľa...
peta
Profil *
tiso
Mno, pro pochopeni jsem pridal prave prikaz pro vytvoreni tabulky.
V celku jse o to, ze jsem se kdesi, bud pcsvet nebo linuxsoft nebo neco tak, docetl, ze pouziva sloupec SET pro popis prav...
Datovy typ SET ... http://www.linuxsoft.cz/article.php?id_article=784
Takze potrebuji zobrazit moznosti, jake ma sloupec set.

$dotaz="SHOW CREATE TABLE $tab";
$vysl3 = mysql_query($dotaz) OR die(mysql_error());
$row3 = mysql_fetch_array($vysl3);
print_r($row3);

zobrazi toto:
Array ( [0] => pp_laws [Table] => pp_laws [1] => CREATE TABLE `pp_laws` ( `id` int(11) NOT NULL auto_increment, `priority` tinyint(4) unsigned default NULL, `laws` set('a','b','c','d') default NULL, PRIMARY KEY (`id`), KEY `laws` (`laws`) ) ENGINE=MyISAM DEFAULT CHARSET=cp1250 [Create Table] => CREATE TABLE `pp_laws` ( `id` int(11) NOT NULL auto_increment, `priority` tinyint(4) unsigned default NULL, `laws` set('a','b','c','d') default NULL, PRIMARY KEY (`id`), KEY `laws` (`laws`) ) ENGINE=MyISAM DEFAULT CHARSET=cp1250 )

a presne toto:
set('a','b','c','d')
je to, co potrebuji vypsat
a nevim jak
Zajimave je, ze PHPMyAdmin to nejak zobrazuje
Sloupec Typ Porovnávání Vlastnosti Nulový Výchozí Extra Akce
id int(11) Ne auto_increment Změnit Odstranit Primární Index Unikátní Fulltext
priority tinyint(4) UNSIGNED Ano NULL Změnit Odstranit Primární Index Unikátní Fulltext
laws set('a', 'b', 'c', 'd') cp1250_general_ci Ano NULL Změnit Odstranit Primární Index Unikátní Fulltext

takze se pustim asi do studovani zdrojaku phpmyadminu.
peta
Profil *
tiso
Tak uz nic, dik. Uz jsem na to prisel, mel jsem spatne postaveny dotaz.

$dotaz="SHOW COLUMNS FROM $tab";
//$dotaz="SHOW DATABASES";
$vysl3 = mysql_query($dotaz) OR die(mysql_error());
while ($row3 = mysql_fetch_array($vysl3))
{
print_r($row3);
}

Problem je v tom, ze ty udaje jsou az v dalsim radku a ja zobrazoval pro kazdy pokusny dotaz jen ten prvni.
tiso
Profil
Databázy moc v láske nemám, teraz som si pozrel ten SET... Skús čo Ti vypíše tento skript na výpis tabuliek z databázy:

//-prihlasovacie udaje k databaze:---------------------------------------------
define("SQL_HOST","localhost");
define("SQL_DBNAME","databaza");
define("SQL_USERNAME","root");
define("SQL_PASSWORD","");
//-pripojenie k databaze:-------------------------------------------------------
$conection=mysql_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD);
mysql_select_db(SQL_DBNAME, $conection);
//-vypis obsahu tabuliek z databazy:--------------------------------------------
$tables=mysql_list_tables(SQL_DBNAME);
while($line=mysql_fetch_row($tables)){
$out.= '
<table class="db"><caption>Table "'.$line[0].'":</caption>';
$fields=mysql_list_fields(SQL_DBNAME, $line[0], $conection);
$columns=mysql_num_fields($fields);
$out.= '
<tr>';
for ($i=0;$i<$columns;$i++){
$column=mysql_field_name($fields,$i);
$out.= '<th>'.$column.'</th>';
}
$out.= '</tr>';
$result=mysql_query("SELECT * FROM `".$line[0]."`");
while($row=mysql_fetch_row($result)){
$out.= '
<tr>';
for ($i=0;$i<$columns;$i++){$out.= '<td>'.$row[$i].'</td>';}
$out.= '</tr>';
}
$out.= '
</table>';
}
echo $out;


...tak som to písal asi zbytočne...
peta
Profil *
tiso Dik, ale ja uz to mam poresene.

Ten script vypada asi takto:

$dotaz = "SELECT *".$dotaz1." ORDER BY `priority` ASC LIMIT ".$from." , ".$msgs2;
//echo "<hr>dotaz2 = ".$dotaz;
$vysl = mysql_query($dotaz) or die("Dotaz error: laws all ! ".mysql_error());
$pocet = mysql_NumRows($vysl);

if ($pocet>0)
{

$file1="pp_laws.php";
PPnav1($file1,$from,$msgs,$finded,'');

$set = array();
$dotaz_h = "SHOW COLUMNS FROM $tab";
$vysl_h = mysql_query($dotaz_h) OR die(mysql_error());
$pocet_h = mysql_NumRows($vysl_h);
if ($pocet_h>0)
{
$tableHead ="\n<tr>";
$tableHead.="\n\t<td>&nbsp;</td>";
while ($row_h = mysql_fetch_array($vysl_h))
{
$y = $row_h['Field'];
$x = $row_h['Type'];
if (!is_int($y) && EReg("set",$x))
{
$x = substr($x,4,-1);
$x = Ereg_Replace("\'","",$x);
$x = explode(",",$x);
foreach ($x as $key => $value)
{$tableHead.="\n\t<td>$value</td>"; $set[$y][$key]=$value;}
}
else {
$tableHead.="\n\t<td>$y</td>";
}
}
$tableHead.="\n</tr>";
}

echo "\n<table class=\"tab\" cellspacing=\"0\" align=\"center\">\n<thead>$tableHead</thead>\n<tbody>";
$i=0;
while ($row2 = mysql_fetch_array($vysl))
{
$tableRow ="\n<tr>";
$tableRow.= "\n\t<td><input name=\"ch$i\" type=\"checkbox\" value=\"{$row2['id']}\"/></td>";
foreach ($row2 as $key => $value) {if (!is_int($key))
{
if (array_key_exists($key,$set))
{
$x = explode(",",$value);
foreach ($set[$key] as $key1 => $value1)
{
$y = (in_array($value1,$x))?1:0;
$tableRow.= "\n\t<td><input name=\"ch".$row2['id'].$key.$key1."\" type=\"checkbox\" value=\"$y\"".($y>0?" checked=\"checked\"":"")."/></td>";
}
}
else
{
$tableRow.="\n\t<td>$value</td>";}}
}
$tableRow.="\n</tr>";
echo $tableRow;
$i++;
}
echo "\n</tbody>\n<tfoot>$tableHead\n</tfoot>\n</table>";
PPnav1($file1,$from,$msgs,$finded,'');

}
else {pp_err("find0");}



A vytvori mi to takovyto pekny kod.
<p align="center" class="arrownav">

<a href="./pp-pp_laws.php?msgs=10&amp;from=1&amp;PHPSESSID=e7217da5ecc56c 8dfb4ecf6b951b0a2e" title="1 - 10">|&lt;&lt;</a>
<a href="./pp-pp_laws.php?msgs=10&amp;from=1&amp;PHPSESSID=e7217da5ecc56c 8dfb4ecf6b951b0a2e" title="1 - 10">&lt;</a>

1/1
<a href="./pp-pp_laws.php?msgs=10&amp;from=1&amp;PHPSESSID=e7217da5ecc56c 8dfb4ecf6b951b0a2e" title="1 - 10">&gt;</a>
<a href="./pp-pp_laws.php?msgs=10&amp;from=1&amp;PHPSESSID=e7217da5ecc56c 8dfb4ecf6b951b0a2e" title="1 - 10">&gt;&gt;|</a>
</p>
<table class="tab" cellspacing="0" align="center">
<thead>
<tr>
<td>&nbsp;</td>
<td>id</td>
<td>priority</td>

<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
</tr></thead>
<tbody>
<tr>
<td><input name="ch0" type="checkbox" value="1"/></td>

<td>1</td>
<td>255</td>
<td><input name="ch1laws0" type="checkbox" value="1" checked="checked"/></td>
<td><input name="ch1laws1" type="checkbox" value="1" checked="checked"/></td>
<td><input name="ch1laws2" type="checkbox" value="1" checked="checked"/></td>
<td><input name="ch1laws3" type="checkbox" value="1" checked="checked"/></td>
</tr>
</tbody>
<tfoot>

<tr>
<td>&nbsp;</td>
<td>id</td>
<td>priority</td>
<td>a</td>
<td>b</td>
<td>c</td>

<td>d</td>
</tr>
</tfoot>
</table>
<p align="center" class="arrownav">

<a href="./pp-pp_laws.php?msgs=10&amp;from=1&amp;PHPSESSID=e7217da5ecc56c 8dfb4ecf6b951b0a2e" title="1 - 10">|&lt;&lt;</a>
<a href="./pp-pp_laws.php?msgs=10&amp;from=1&amp;PHPSESSID=e7217da5ecc56c 8dfb4ecf6b951b0a2e" title="1 - 10">&lt;</a>
1/1
<a href="./pp-pp_laws.php?msgs=10&amp;from=1&amp;PHPSESSID=e7217da5ecc56c 8dfb4ecf6b951b0a2e" title="1 - 10">&gt;</a>
<a href="./pp-pp_laws.php?msgs=10&amp;from=1&amp;PHPSESSID=e7217da5ecc56c 8dfb4ecf6b951b0a2e" title="1 - 10">&gt;&gt;|</a>
</p>
Toto téma je uzamčeno. Odpověď nelze zaslat.