-6

i want to apply css for a while looping but it returns only the first data if i use css , and without css it returns all the data normally. here is my code it's simple.

     $users=mysql_query("select * from users");
        while($user=mysql_fetch_array($users))
        {
        echo "<table>";
        echo "<tr>";
        echo "<td class='user'>";
        echo $user['pseudo'];
        echo "</tr>";
        echo "</td>";
        echo "</table>";
}
  • 10
    There's no css in your code. – Ohgodwhy Jul 01 '14 at 12:33
  • I know !! the css was just simple i was trying to apply it on it .. `.user { position:fixed; right:500; left:500; top:100; background-color:red; }` – user3787287 Jul 01 '14 at 12:34
  • Do you mean you want to apply CSS to the `table`? – putvande Jul 01 '14 at 12:34
  • But there *is* a [use of the deprecated mysql](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)... – Matt Gibson Jul 01 '14 at 12:34
  • 1
    You're using malformed HTML. Your `td` gets opened inside the `tr`, but closed after it. Also, don't open and end the `table` inside the loop, but before and after it respectively. – padarom Jul 01 '14 at 12:34
  • 1
    I don't think you can `position:fixed` a `td`. – putvande Jul 01 '14 at 12:35
  • 1
    @putvande in fact this is quite true, you cannot. It completely breaks the `display:table;` logic. – Ohgodwhy Jul 01 '14 at 12:36
  • @putvande : Yes with getting all the data .. cause there is some data that desepears when applying position css i think it's behind each other .. i want to know how to use position that makes the one under the other.. – user3787287 Jul 01 '14 at 12:37
  • do i need to use relative position ? – user3787287 Jul 01 '14 at 12:39
  • @putvande : THANK YOU A LOT 'relative' worked .. i forgot to try it .. and now i'm getting -5 for a noob's question ..:S – user3787287 Jul 01 '14 at 12:41
  • @user3787287 -6 is for not asking the question properly and not for noob's question.You should have mentioned informations like `where you want to add the css code` , `what css code you use` . – krishna Jul 01 '14 at 12:50
  • I just didn't knew this .. i'm kind of new in this website .. and i get simple errors because of non-sleeping and then when i ask every body goes to -1 without trying to help – user3787287 Jul 01 '14 at 12:59

2 Answers2

1

Your problem is position:fixed. This tells the browser to lay all tables, one over the other, at window position right:500; left:500; top:100;. So, everything is there, but you tell the browser to put each new data set into a new table, and stack it in front of or behind the previous dataset (=table).

My best guess as to what you wanted to achieve is

$users=mysql_query("select * from users");
    echo "<table>";
    while($user=mysql_fetch_array($users))
    {
    echo "<tr>";
    echo "<td class='user'>";
    echo $user['pseudo'];
    echo "</td>";
    echo "</tr>";
    }
    echo "</table>";
Alexander
  • 19,906
  • 19
  • 75
  • 162
0
$users=mysql_query("select * from users");
echo "<table>";
while($user=mysql_fetch_array($users))
{
    echo "<tr>";
    echo "<td class='user'>";
    echo $user['pseudo'];
    echo "</td>";
    echo "</tr>";
}
echo "</table>";

Your HTML was malformed before. The tr was closed, before the td was (<tr><td></tr></td>) which is invalid. Also it makes more sense to wrap the loop in the table, instead of declaring it in every iteration.

padarom
  • 3,529
  • 5
  • 33
  • 57