intampin urmatoarea problema ...
am o baza de date in care sunt n tabele ce au aceeasi structura, dar numarul acestor tabele mai creste din cand in cand
chiar daca numarul acestora creste, vreau sa afisez doar acele tabele care au o anumita valoare intr-un camp ... sa zicem cele care au in campul camp1 valoarea a
pana acum am reusit sa afisez toate tabelele din acea baza de date, folosind scriptul:
<?php
$dbname = 'test';
if (!mysql_connect('localhost', 'root', '1234')) {
echo 'Could not connect to mysql';
exit;
}
//
$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
//afisare
echo "<table width='200' border='1' align='center'>";
echo "<tr>
<th>Nume tabela</th>
</tr>";
while ($row = mysql_fetch_row($result)) {
echo "<br>";
echo "<tr align='left'><td>";
echo "{$row[0]}";
echo "</td></tr>";
}
echo "</table>";
mysql_free_result($result);
?>
cum pot sa afisez doar acele tabele care ma intereseaza?
multumesc mult
listare tabele ce indeplinesc o anumita conditie
Moderatori: Moderatori, Start Moderator
-
surrogates
- PHPRomania Supporter
- Mesaje: 8
- Membru din: Joi Oct 06, 2011 12:54 pm
-
surrogates
- PHPRomania Supporter
- Mesaje: 8
- Membru din: Joi Oct 06, 2011 12:54 pm
multumesc pt. solutie, insa ... nu am rezolvat problema ...
imi apare eroarea:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\jpgraph\aa.php on line 25
linia 25 este urmatoarea:
if($count = mysql_num_rows(mysql_query("SELECT * FROM $row[0] WHERE time = '-1'"))) {
si afisaza de asemenea mesajul:
nu am gasit inregistrari corespunzatoare in tabelul aaa
cu toate ca am asemenea inregistrai in tabelul aaa
imi apare eroarea:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\jpgraph\aa.php on line 25
linia 25 este urmatoarea:
if($count = mysql_num_rows(mysql_query("SELECT * FROM $row[0] WHERE time = '-1'"))) {
si afisaza de asemenea mesajul:
nu am gasit inregistrari corespunzatoare in tabelul aaa
cu toate ca am asemenea inregistrai in tabelul aaa
- misu
- PHPRomania Supporter
- Mesaje: 23
- Membru din: Joi Sep 01, 2011 2:54 pm
- Localitate: Brasov
- Contact:
asta se intampla probabil pentru ca ai in baza de date unul sau mai multe tabele ce nu contin campul time.
prefixeaza acele tabele care au structura identica, ex: tm_tabel, le redenumesti,
apoi selectezi doar tabelele cu "tm_" in fata (unde esti sigur ca exista campul time)
$sql = "SHOW TABLES FROM $dbname LIKE 'tm_%'";
sau poti selecta doar tabelele care contin campul time astfel:
$sql = "SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IN ('time') AND TABLE_SCHEMA='$dbname'";
prefixeaza acele tabele care au structura identica, ex: tm_tabel, le redenumesti,
apoi selectezi doar tabelele cu "tm_" in fata (unde esti sigur ca exista campul time)
$sql = "SHOW TABLES FROM $dbname LIKE 'tm_%'";
sau poti selecta doar tabelele care contin campul time astfel:
$sql = "SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IN ('time') AND TABLE_SCHEMA='$dbname'";
-
surrogates
- PHPRomania Supporter
- Mesaje: 8
- Membru din: Joi Oct 06, 2011 12:54 pm
-
quadmachine
- Senior Member
- Mesaje: 807
- Membru din: Sâm Iul 10, 2010 4:58 pm
- Localitate: Ploiesti
- Contact:
-
quadmachine
- Senior Member
- Mesaje: 807
- Membru din: Sâm Iul 10, 2010 4:58 pm
- Localitate: Ploiesti
- Contact:
-
surrogates
- PHPRomania Supporter
- Mesaje: 8
- Membru din: Joi Oct 06, 2011 12:54 pm
mii de multumiri tuturor ...
m-am mai jucat putin cu acel cod si l-am modificat (inclusiv partea de conectare) ...
acum arata asa:
<?php
$id = @mysql_connect("localhost","root","1234");
mysql_select_db("test",$id);
//
$sql = "SHOW TABLES FROM test";
$result = mysql_query($sql);
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
//afisare
echo "<table width='200' border='1' align='center'>";
echo "<tr>
<th>Nume tabela</th>
</tr>";
while ($row = mysql_fetch_row($result)) {
if($count = mysql_num_rows(mysql_query("SELECT count('time') FROM $row[0] WHERE time = '-1'", $id))) {
// if($count = mysql_query("SELECT COUNT('time') FROM $row[0] WHERE time='-1'", $id)) {
echo "<br>";
echo "<tr align='left'><td>";
echo 'am gasit '.$count.' inregistrari corespunzatoare in tabelul '.$row[0];
echo "</td></tr>";
} else {
echo "<br>";
echo "<tr align='left'><td>";
echo 'nu am gasit inregistrari corespunzatoare in tabelul '.$row[0];
echo "</td></tr>";
}
}
?>
cu acest cod, obtin urmatorul rezultat:
am gasit 1 inregistrari corespunzatoare in tabelul 1
am gasit 1 inregistrari corespunzatoare in tabelul 2
...
daca folosesc insa linia:
if($count = mysql_query("SELECT COUNT('time') FROM $row[0] WHERE time='-1'", $id)) {
obtin un rezultat de forma:
am gasit Resource id #5 inregistrari corespunzatoare in tabelul 1
am gasit Resource id #6 inregistrari corespunzatoare in tabelul 2
...
e ceva care inca imi scapa ...
m-am mai jucat putin cu acel cod si l-am modificat (inclusiv partea de conectare) ...
acum arata asa:
<?php
$id = @mysql_connect("localhost","root","1234");
mysql_select_db("test",$id);
//
$sql = "SHOW TABLES FROM test";
$result = mysql_query($sql);
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
//afisare
echo "<table width='200' border='1' align='center'>";
echo "<tr>
<th>Nume tabela</th>
</tr>";
while ($row = mysql_fetch_row($result)) {
if($count = mysql_num_rows(mysql_query("SELECT count('time') FROM $row[0] WHERE time = '-1'", $id))) {
// if($count = mysql_query("SELECT COUNT('time') FROM $row[0] WHERE time='-1'", $id)) {
echo "<br>";
echo "<tr align='left'><td>";
echo 'am gasit '.$count.' inregistrari corespunzatoare in tabelul '.$row[0];
echo "</td></tr>";
} else {
echo "<br>";
echo "<tr align='left'><td>";
echo 'nu am gasit inregistrari corespunzatoare in tabelul '.$row[0];
echo "</td></tr>";
}
}
?>
cu acest cod, obtin urmatorul rezultat:
am gasit 1 inregistrari corespunzatoare in tabelul 1
am gasit 1 inregistrari corespunzatoare in tabelul 2
...
daca folosesc insa linia:
if($count = mysql_query("SELECT COUNT('time') FROM $row[0] WHERE time='-1'", $id)) {
obtin un rezultat de forma:
am gasit Resource id #5 inregistrari corespunzatoare in tabelul 1
am gasit Resource id #6 inregistrari corespunzatoare in tabelul 2
...
e ceva care inca imi scapa ...
Cine este conectat
Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 27 vizitatori
