creare link ca rezultat

Secţiune dedicată începatorilor.

Moderatori: Moderatori, Start Moderator

surrogates
PHPRomania Supporter
Mesaje: 8
Membru din: Joi Oct 06, 2011 12:54 pm

creare link ca rezultat

Mesajde surrogates » Joi Oct 06, 2011 1:21 pm

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



surrogates
PHPRomania Supporter
Mesaje: 8
Membru din: Joi Oct 06, 2011 12:54 pm

Mesajde surrogates » Joi Oct 06, 2011 1:42 pm

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 ...

w3apps
Average Member
Mesaje: 156
Membru din: Joi Sep 02, 2010 11:41 pm

Mesajde w3apps » Vin Oct 07, 2011 10:47 pm

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>";

surrogates
PHPRomania Supporter
Mesaje: 8
Membru din: Joi Oct 06, 2011 12:54 pm

Mesajde surrogates » Sâm Oct 08, 2011 8:51 am

da ... asa este ...
multumesc mult


Înapoi la “PHP Incepători”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 20 vizitatori