Mysql
 SQL >> Datenbank >  >> RDS >> Mysql

Links aus in einer MySQL-Tabelle gespeicherten URLs aufbauen

Angenommen eines lokalen MySQL-Servers mit Benutzername und Passwort, beide auf "root" gesetzt, einer Tabelle namens url_table und einer Datenbank namens url_database, könnten Sie so etwas machen:

$connection = mysql_connect("127.0.0.1","root","root"); // Connect to the mysql server mysql_select_db("url_database"); // Open the desired database $query = "SELECT url,text FROM url_table"; // Query to select the fields in each row $result = mysql_query($query); // Run the query and store the result in $result while($row = mysql_fetch_assoc($result)) // While there are still rows, create an array of each { echo "<a href='".$row['url']."'>".$row['text']."</a>"; // Write an anchor with the url as href, and text as value/content } mysql_close($connection); // close the previously opened connection to the database 

Beachten Sie, dass die mysql-Erweiterung veraltet ist; für neuen Code bevorzugen Sie mysqli oder PDO mit Prepared Statements.