Pagina 1 din 1

creare link ca rezultat

Scris: Joi Oct 06, 2011 1:21 pm
de surrogates
buna ziua
intampin urmatoarea problema ... am sa zicem un numar de X tabele din care trebuie sa afisez doar tabelele care au in campurile lor o anumita valoare (sa zicem -1)
ideea e ca atunci cand afisez tabelele, rezultatul sa fie sub forma unui link catre un fisier de forma nume_tabela.php
pana acum am reusit sa afisez doar numele tabelelor ...
fisierul arata cam asa ...
<?php
// Make a MySQL Connection
mysql_connect("localhost", "root", "1234")
or die('Could not connect: ' . mysql_error());
mysql_select_db("ping") or die('Could not select database');

// Get all the data from the "all" table
$result = mysql_query("SELECT DISTINCT 'a1' AS Nume_tabela FROM a1 WHERE time = -1
UNION
SELECT DISTINCT 'a2' AS Nume_tabela FROM a2 WHERE time = -1
UNION
SELECT DISTINCT 'a3' AS Nume_tabela FROM a3 WHERE time = -1")
or die(mysql_error());

echo "<table width='300' border='1' align='center'>";
echo "<tr>
<th>Nume tabela</th>
</tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {

// Print out the contents of each row into a table
echo "<br>";
echo "<tr align='center'><td>";
echo $row['Nume_tabela'];
echo "</td></tr>";
}

echo "</table>";
?>

cum as putea sa obtin acele link-uri?
multumesc mult

Scris: Joi Oct 06, 2011 1:42 pm
de surrogates
am gasit o solutie ...
am inlocuit linia:
echo $row['Nume_tabela'];
cu urmatoarea
echo "<a href=\"{$row['Nume_tabela']}.php\">{$row['Nume_tabela']}
</a>";

daca cineva mai are si alte solutii ...

Scris: Vin Oct 07, 2011 10:47 pm
de w3apps
Este corecta solutia. Pot spune doar ca linia ta:

echo "<a href=\"{$row['Nume_tabela']}.php\">{$row['Nume_tabela']}</a>";

poate fi si:

echo "<a href='$row[Nume_tabela].php'>$row[Nume_tabela]</a>";

Scris: Sâm Oct 08, 2011 8:51 am
de surrogates
da ... asa este ...
multumesc mult