做更多结果

I'm learning php and mysql and to time I have finally my dynamic menu ready. Now I want use a news system. For this I have write a simple script in php with a while loop

if ($result->num_rows > 0) { 
    while($row = $resut->fetch_assoc()) {
        echo "<tr><th>". $row["ntitle"]."</th></tr><tr><th>". $row["ninhalt"]."</th></tr><tr><th>". $row["ndatum"]."</th></tr>";
    }
}

I use

<?php

require_once ('config.php');

$db_link = mysqli_connect (MYSQL_HOST, 
                       MYSQL_BENUTZER, 
                       MYSQL_KENNWORT, 
                       MYSQL_DATENBANK);

if ( $db_link )
{
    $sql = "SELECT id, mtitle, mlink FROM cm_menue";
    $result = $db_link->query($sql);

}
else
{
// hier sollte dann später dem Programmierer eine
// E-Mail mit dem Problem zukommen gelassen werden
die('keine Verbindung möglich: ' . mysqli_error());
}
?>

For my Database Connect and for do mysql data select, so I can't can use $sql again. How do I make it so that I can select other data that I need for the news system?

Since it's a news system I guess you need data from another table which has references to another table with an id or something like that. In that case you should use a join.

http://www.w3schools.com/sql/sql_join_left.asp

If not, you can just declare another variable like $sql2 and use it.

since you are using the variable only once (and directly after setting it) you can reuse it at another place without any consequences.

you can also not use the $sql variable at all:

$result = $db_link->query("SELECT id, mtitle, mlink FROM cm_menue");

You can reuse variables as long as you are aware what the content of the variable is at any point you are using it, so doing this is absolutely fine:

$var1 = "hallo";
echo $var1; // hallo
$var1 = "du";
echo $var1; // du

Und an deiner stelle würde ich keine emails verschicken wenn ein sql error auftritt, wenn die datenbank von deinem anbieter kurz down ist und du viel traffic auf deiner seite hast würde das dein email-postfach mit fehlermails zumüllen...