PHP-Code:
<?php
function FollowsSomeone($user_name)
{
//Test for existing entry in DB
$con=mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql1 ="SELECT `user_name` from `following` where `user_name`='".$user_name."'";
$result = mysqli_query($con,$sql1);
if(mysqli_num_rows($result) == 0)
{
return false;
} else {
return true;
}
mysqli_free_result($result);
mysqli_close($con);
}
function getFollowingPosts($user_name)
{
If (FollowsSomeone($_SESSION['user_name']))
{
$connect = mysqli_connect (DB_HOST,DB_USER,DB_PASS,DB_NAME);
$sql = "SELECT `follow_name` FROM `following` where`user_name`='".$user_name."'";
$db_erg = mysqli_query($connect, $sql );
if ( ! $db_erg )
{
die('Ungültige Abfrage: ' . mysqli_error());
}
$follow_names = array();
while ($zeile = mysqli_fetch_array( $db_erg, MYSQL_ASSOC))
{
array_push($follow_names,$zeile['follow_name']);
}
$index = 0;
while(count($follow_names) >= $index)
{
$sql = "SELECT `user_name`,`videotitle`,`videourl`,`thumbnail` FROM `startpage` where `user_name`='".$follow_names[$index]."'order by post_time desc";
print($sql);
$db_erg = mysqli_query($connect, $sql );
if ( ! $db_erg )
{
die('Ungültige Abfrage: ' . mysqli_error());
}
echo '<div style="width:496px; height:700px; align:center; overflow:auto">';
while ($zeile = mysqli_fetch_array( $db_erg, MYSQL_ASSOC))
{
?>
<table style="text-align:center">
<td>
<tr>
<td><a href="/userpage.php?<?php echo($zeile['user_name'])?>"> <?php echo($zeile['user_name'])?></a><?php echo(" has posted: ") ?><b><?php echo ($zeile['videotitle']) ?></b></td>
</tr>
<tr>
<td><a href="<?php echo($zeile['videourl'])?>"><img src="<?php echo($zeile['thumbnail']) ?>" alt="Picture not found" style="width:496px;height:279px"></a></td>
</tr>
</td>
</table>
</table>
<?php
mysqli_free_result( $db_erg );
mysqli_close($connect);
$index++;
}
echo "</div>";
}
}
else
{
$connect = mysqli_connect (DB_HOST,DB_USER,DB_PASS,DB_NAME);
$sql = "SELECT `user_name`,`videotitle`,`videourl`,`thumbnail` FROM `startpage` order by post_time desc";
$db_erg = mysqli_query($connect, $sql );
if ( ! $db_erg )
{
die('Ungültige Abfrage: ' . mysqli_error());
}
echo '<div style="width:496px; height:700px; align:center; overflow:auto">';
while ($zeile = mysqli_fetch_array( $db_erg, MYSQL_ASSOC))
{
?>
<table style="text-align:center">
<td>
<tr>
<td><a href="/userpage.php?<?php echo($zeile['user_name'])?>"> <?php echo($zeile['user_name'])?></a><?php echo(" has posted: ") ?><b><?php echo ($zeile['videotitle']) ?></b></td>
</tr>
<tr>
<td><a href="<?php echo($zeile['videourl'])?>"><img src="<?php echo($zeile['thumbnail']) ?>" alt="Picture not found" style="width:496px;height:279px"></a></td>
</tr>
</td>
</table>
</table>
<?php
}
echo "</div>";
mysqli_free_result( $db_erg );
mysqli_close($connect);
}
}
könnt ihr mir sagen warum bei der zweiten Abfrage der Datenbank mir ein "Ung�ltige Abfrage" ausgegeben wird? Habe mir beide SQL-Befehle auch noch einmal ausgeben lassen und funktionieren beide manuell in phpmyadmin..

Ich gebe quasi eine Liste aus und habe aber auch ein Follow-System auf meiner Website. Jetzt möchte ich, dass nur Posts von Leuten denen man folgt angezeigt werden. Dafür teste ich erstmal ob man überhaupt jemandem folgt. Wenn nicht wird einfach alles angezeigt. Ich bin eingeloggt in meinem "Accountsystem" und die Verbindung zur Datenbank klappt problemlos
Kommentar