news script (kommentar zaehler)

Eassyyyy
PHP:
<?php
$s = "SELECT  * FROM news WHERE id = '$id'" ;
$q = mysql_query($s) ;
while ($array = mysql_fetch_array($q)) {
$s1 = "SELECT  * FROM news_comments  WHERE id = '$id'" ;
$q1 = mysql_query($s1) ;
$comments_anzahl = mysql_num_rows($q1) ;
//HTML
}
?>
so muss das ungefähr sein... :-)
 
Also bei mir sieht das so aus:

PHP:
<?php
// Zur config datei Includen //
include "config.php";

// Verbindung mit der Datenbank erstellen //
$db = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");


// Tabelle //
$query = "SELECT * FROM news1 ORDER BY id DESC LIMIT 6";
$result = mysql_query($query);
while($r=mysql_fetch_array($result))

{
$name=$r["name"];
$titel=$r["titel"];
$news=$r["news"];
$email=$r["email"];
$link=$r["link"];
$datum=$r["datum"];
$id=$r["id"];


echo "<table width='310' border='1' cellspacing='0' cellpadding='0' bordercolor='#000000'>
  <tr>
    <td width='68%'>$titel</td>
    <td width='32%'>
      <div align='center'><a href='mailto:$email'>$name</a></div>
    </td>
  </tr>
</table>
<table width='310' border='0' height='24'>
  <tr>
    <td valign='top'>$news</td>
  </tr>
</table>
<table width='310' border='1' cellspacing='0' cellpadding='0' bordercolor='#000000'>
  <tr>
    <td width='68%'>Link: <a href='http://www.$link'>$link</a></td>
    <td width='32%'>
      <div align='center'><a href='comments.php?id=$id'>comments</a>($id)</div>
    </td>
  </tr>
</table>
<table width='310' border='0' cellspacing='0' cellpadding='0' bordercolor='#000000'>
  <tr>
    <td width='68%'>&nbsp;</td>
  </tr>
  <tr>
    <td width='68%'>&nbsp;</td>
  </tr>
  <tr>
    <td width='68%'>&nbsp;</td>
  </tr>
</table>";
}
?>

Wie soll ich das jetzt einbauen?
 
PHP:
<?php
// Zur config datei Includen //
include "config.php";

// Verbindung mit der Datenbank erstellen //
$db = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");


// Tabelle //
$query = "SELECT * FROM news1 ORDER BY id DESC LIMIT 6";
$result = mysql_query($query);
while($r=mysql_fetch_array($result))

{
$name=$r["name"];
$titel=$r["titel"];
$news=$r["news"];
$email=$r["email"];
$link=$r["link"];
$datum=$r["datum"];
$id=$r["id"];

$s1 = "SELECT  * FROM news_comments  WHERE id = '$id'" ;
$q1 = mysql_query($s1) ;
$comments_anzahl = mysql_num_rows($q1) ;

echo "<table width='310' border='1' cellspacing='0' cellpadding='0' bordercolor='#000000'>
  <tr>
    <td width='68%'>$titel</td>
    <td width='32%'>
      <div align='center'><a href='mailto:$email'>$name</a></div>
    </td>
  </tr>
</table>
<table width='310' border='0' height='24'>
  <tr>
    <td valign='top'>$news</td>
  </tr>
</table>
<table width='310' border='1' cellspacing='0' cellpadding='0' bordercolor='#000000'>
  <tr>
    <td width='68%'>Link: <a href='http://www.$link'>$link</a></td>
    <td width='32%'>
      <div align='center'><a href='comments.php?id=$id'>comments</a>  ($comments_anzahl )</div>
    </td>
  </tr>
</table>
<table width='310' border='0' cellspacing='0' cellpadding='0' bordercolor='#000000'>
  <tr>
    <td width='68%'>&nbsp;</td>
  </tr>
  <tr>
    <td width='68%'>&nbsp;</td>
  </tr>
  <tr>
    <td width='68%'>&nbsp;</td>
  </tr>
</table>";
}
?>
 
guck mal nach ob die tabelle stimmt, und ob die id stimmt... die id wird doch auch schonper GEt weitergegeben... du hast sie glaub ich nun doppelt defieniert...
 
Also tabelle stimmt id mmhh hab newsid = $id!
Also ich weis ned genau an was es liegt in der comments tabell ist:

id,newsid,name,email,titel,comment und ned mehr!
 
Zuletzt bearbeitet:
So einmal an alle in der Runde der freundliche Hinweis doch in Zukunft ein wenig mehr auf Rechtschreibung, deutsche Grammatik und Groß/Kleinschreibung zu achten, wie in Punkt 12 der Netiquette vermerkt ist.

Mir kam nämlich grade beim Überfliegen des Threads geringfügig der Graus :p
 
Zuletzt bearbeitet von einem Moderator:
PHP:
$sql = "select count(*) from $table where news_id = $id";
$res = mysql_query($sql);
$row = mysql_fetch_row($res);
echo $row[0];

Somit bist du auf der sicheren Seite!
 
Zurück