-1

How do I get my mysql records in an html table vertical with an mysql while or for clause? If I do it with the while clause I only get the horizontal line output.

$select = "SELECT * FROM kalender ORDER BY id DESC";
$query = mysql_query($select);
while($row = mysql_fetch_array($query)) {
    echo "<tr>";
    echo "<td>".$row['name']."</td>";
    echo "</tr>";
}

I want it like this

-Monday-  -Tuesday-  -Wednesday-  -Thursday-  -Friday-
Monday 1   Tuesday 1  Wednesday 1  Thursday 1  Friday 1
Monday 2   Tuesday 2  Wednesday 2  Thursday 2  Friday 2
Monday 3   Tuesday 3  Wednesday 3  Thursday 3  Friday 3

not like this...

-Monday-  -Tuesday-  -Wednesday-  -Thursday-  -Friday-
 Monday 1  Monday 2   Monday 3     Monday 4    Monday 5
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Nils Blaumer
  • 19
  • 1
  • 6

1 Answers1

1
"SELECT * FROM kalender ORDER BY RIGHT(name,1) ASC, id DESC";

UPDATE1 According to the fiddle you've provided: http://sqlfiddle.com/#!9/c1235/2

You have 5 columns in your table ForgeRock, so you should just change your php code to:

$select = "SELECT * FROM kalender ";
$query = mysql_query($select);
while($row = mysql_fetch_array($query)) {
    echo "<tr>";
    echo "<td>".$row['Monday']."</td>";
   echo "<td>".$row['Tuesday']."</td>";
   echo "<td>".$row['Wednesday']."</td>";
   echo "<td>".$row['Thursday']."</td>";
   echo "<td>".$row['Friday']."</td>";
    echo "</tr>";
}

But I don't trust your fiddle, because there is no name column. But you have it in OP. And table name in OP is kalender. Maybe that is not important, but questions are there.

Alex
  • 16,739
  • 1
  • 28
  • 51
  • And then? do you have an example for a while or for loop? – Nils Blaumer Apr 28 '15 at 18:50
  • I somehow doubt that the values given in the example represent real-world values as that would make the whole database unnecessary. And it breaks at `10`. Either way, an explanation would be nice, just one line of code doesn't really make an answer. – jeroen Apr 28 '15 at 18:51
  • 1
    Since there is no good data samples in OP I have no idea what you really need. If you provide more data and explanation I can help with better solution and explanation. But so far, it is just visual analysis of presentation you post. For example, visually we have one table= 5x3 but in your php code I see that you have only table=1xn. So I have no idea where is truth – Alex Apr 28 '15 at 18:54
  • @Alex I definitely agree with you there :-) – jeroen Apr 28 '15 at 18:55
  • I want a calendar, that show each meeting for Monday in the table column foreach meeting a new row. and this for Monday to Friday. Understood? – Nils Blaumer Apr 28 '15 at 19:00
  • no. I don't. Show data samples and table structure and expected result. – Alex Apr 28 '15 at 19:01