Greetings,

I am triying to diplay morethan one column from mysql database by limiting the display into three rows. I want all the row data to be shown as column data. I want the data in the fourth, fith and sixth row to be diplayed in the next columns, and so on.

Example:

A   B    C
1  10  100
2  11  101
3  12  103
4  13  104
5  14  105
6  15  106
7  16  107
8  17  108
9  18  109

I want the above data to be shown as:

10     11     12    etc
100   101   103
1       2      3

I am a fresh to PHP and mysql. I wrote the following code but it only diplays the first three rows in one column. I want to add another column next to it.

<html>
<head>


<title>Untitled</title>


</head>
<body>
<p>&nbsp;</p>


<?php
print("<font size=\"2\" face=\"Times New Roman\">");


$link = mysql_connect("mysql", "fikir", "yenene");
mysql_select_db("DB1") or die(mysql_error());
$data = mysql_query("SELECT * FROM Table2 LIMIT 3")
or die(mysql_error());


Print "<table border=0>";
while($info = mysql_fetch_array( $data ))


{
Print "<tr>";
Print "</tr><td></tr>".$info . "</td>";
Print "</tr><td></tr>".$info . "</td>";
Print "</tr><td></tr>".$info . "</td>";
}
?>
</body>
</html>

I would greatly appreciate if some one gives me an idea !

Dilnesaw

Recommended Answers

All 5 Replies

So you have 4 columns in your db that you are wanting to show and only the top 3 entries? I can see that you are missing the closing </table>. try adding it like this to display all 6 columns three per table column

{ 
Print "<tr>"; 
Print "<td>".$info['B'] . "</td>"; 
Print "<td>".$info['C'] . "</td>";
Print "<td>".$info['A'] . "</td>"; 
Print "</tr> <tr>";
Print "<td>".$info['D'] . "</td>"; 
Print "<td>".$info['E'] . "</td>";
Print "<td>".$info['F'] . "</td></tr>";

}  
Print "</table>";

Thank you very much for the prompt repsonse. It was helpful. I used what you suggested, I get duplicate rows listed in one column. What I want is, suppose we have one column data in mysql with 9 rows. Can I show the first three rows in the first column, the second three rows in the second row and the third three rows in the third column ?
Using the example above using clumn "B", the result should be diplayed as :-

10 13 16
11 14 17
12 15 18

I appreciate your repsonse !

Dilnesaw

After reading your topic this is what i gathered:

You want the 9 objects(10-18) to be display in order in groups of 3?

If so here is the code:

Print "<tr>";
Print "<td>";

while($info = mysql_fetch_array( $data ))
{
Print $info . "<br>";
$counter++;
if($counter % 3 == 0) //Every third row new td
Print "</td><td>";
}

Print "</td>";
Print "</tr>";

}

Note: I am unable to test the code, let me know how it goes. Hope it helps.

Regards, X

It worked. Thanks so much for your support - million thanx.

Now, suppose I have long text and I want to wrap the text, can I add something to the Print $info . "<br>"; code ?

Can I also add blank column space between the columns so that they are not congested ?

Thanks,
Dilnesaw

>It worked. Thanks so much for your support - million thanx.

Your welcome glad i could help. :)

>Now, suppose I have long text and I want to wrap the text, can I add something to the Print $info . "<br>"; code ?

Example of what your meaning? because with the above code you should be getting 1 word per column?

>Can I also add blank column space between the columns so that they are not congested ?

Thats easy just between the columns put an empty column with a br eg. <td><br></td>

Regards, X

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.