got some problems with my usersearch.
see here the script:
i tried a few things out so there a some lines commentet out..
Code: Select all
<?php
ob_start();
session_start();
include ('header.php');
if(!isset($_SESSION['uid'])){
//include ('safe.php');
echo "Sie müssen eingeloggt sein um diese Seite zu sehen!";
header("Location:login.php");
}else{
?>
<section id="middle">
<div id="container">
<div id="content">
<table border="2" cellpadding="5" cellspacing="1" width="80%">
<tr>
<td colspan="2"><b>Suche</b></td>
</tr>
<tr>
<td>
<form name="form2" method="post" action="#">
<table border="1" cellpadding="5" cellspacing="1" width="100%">
<tr>
<td colspan="4" style="height:18px;">
<div style="width:100%;height:100%;overflow:hidden;">
Bitte gewünschten Suchbegriff eingeben.
</div>
</td>
</tr>
<tr>
<td><strong>Spielername</strong></td>
<td colspan="2" valign="middle" align="center" style="height:20px; width:365px;">
<div style="width:100%;height:100%;overflow:hidden;">
<input name="suche" type="text" id="suche" size="30">
</form>
</div>
</td>
<td style="height:25px;">
<div style="width:100%;height:100%;overflow:hidden;">
<input type="submit" name="searchname" value="suchen" >
</div>
</td>
</tr>
</table>
</table>
<p id="p_red">
<?php
$tbl_name="users_valid";
$tbl1_name="planets";
$i = 0;
// values sent from form
if($_POST)
{
$suche=protect($_POST['suche']);
//Kontrollstruktur für suche
if(isset($_POST['suche'])){
if($suche == ""){
echo "Bitte Suchbegriff einsetzen!";
}else{
/*
$i = 0;
$daten = mysql_query("SELECT * FROM `users_valid` WHERE `username` LIKE '%".$suche."%'");
$row=mysql_fetch_array($daten);
if ($daten){
*/
$abfrage = "Select * FROM users_valid WHERE username LIKE '%".protect($suche)."%'";
$ergebnis = mysql_query($abfrage);
/*
if (!$row[$i] = mysql_fetch_assoc($ergebnis))
{
//die ('Keine Ergebnisse zu dieser Suche');
echo "Spieler nicht gefunden.";
}
*/
/*elseif($row[$i] = mysql_fetch_assoc($ergebnis) < 1){
print "Spieler nicht gefunden.";
}else{*/
if($row[$i] = mysql_fetch_assoc($ergebnis)){
?>
<table border="1" cellpadding="5" cellspacing="1" width="80%">
<tr>
<td>Spielername</td>
<td>Rang</td>
<td>Gebäude Punkte</td>
<td>Forschungs Punkte</td>
<td>Gesamt Punkte</td>
</tr>
<tr>
<?php
//}elseif(!$row[$i] = mysql_fetch_assoc($ergebnis)){
//echo "Spieler nicht gefunden.";
}
$i = 0;
WHILE ($row[$i] = mysql_fetch_assoc($ergebnis))
{
//echo $row[$i]['username'] . "<br />";
//$i++;
?>
<td>
<?php
/*$i = 0;
while($i < count($daten))
{
*/
$stats_get = mysql_query("SELECT * FROM `planets` WHERE `id`='".$row[$i]['id']."'") or die(mysql_error());
$planets = mysql_fetch_assoc($stats_get);
/*
$search_get2 = mysql_query("SELECT * FROM `planets` WHERE `id` = '".$row[$i]['id']."'") or die(mysql_error());
$search2 = mysql_fetch_assoc($search_get2);
$row2[$i] = mysql_fetch_array($search2);
*/
echo "<a href=\"stats.php?id=" .$row[$i]['id']."\">" . $row[$i]['username'] . "</a>";
//echo $row[$i]['username'];
?>
</td>
<td>
<?php echo $planets['rank'] ?>
</td>
<td>
<?php echo $planets['points_buildings'] ?>
</td>
<td>
<?php echo $planets['points_research'] ?>
</td>
<td>
<?php echo $planets['points_buildings']+$planets['points_research'] ?>
</td>
</tr>
<?php
$i++;
}}}
?>
</table>
<?php
//else{
//echo "Spieler nicht gefunden.";
}
?>
</p>
<?php
}
?>
<?php include ('footer.php') ?>
<?php ob_end_flush(); ?>
#if no input-> tells you to input something
#if input->find the user/users and shows some of their stats
Problem:
it doesnt show all users and i dunno why
for example if there are folowing 3 playernames:
+hallo
+hallo1
+hallotest
and i search for "hal"
the output is only user "hallo1" + user "hallotest" but not user "hallo"...
dont understand this
and btw it has nothing to do with which player iam logged in and do the search..
Next problem is that iam not always get an output:
Example if i search for player "schatz1"
and my input is "sc" i dont find anything
but if i type in as serach term "ha" i find player "schatz1" and also find players "hallo1" and "hallotest"...(also not working with any other 2letter terms... - makes no sense to me...)
Any suggestions or someone can see my mistake?