The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Help! pulling my hair out ...
Today I found out that I'm still a noob when it comes down to php :ermm: and would like to ask for help here once again, and I hope someone will be able to do so.
Goal: what I'm trying to do is to display some data from mysql in a php page in a table containing 3 columns. Problem: I can't get the code to work and display the data in columns. I already know how to display the data in rows using the loop, but what I don't know is how I would go ahead and display the data in columns. So instead of having something like this, data 1 data 2 data 3 I want to have something like this data 1 data 2 data 3 The code that I'm working with is the following, and it just doesn't work for me, PHP Code:
Sean |
#2
|
|||
|
|||
Code:
while($row = mysql_fetch_assoc($getbikes)) { echo "<table><tr>"; Code:
$getbikes = mysql_query("SELECT * FROM $table ORDER BY id DESC LIMIT $number "); //Retrieves all of the Data from table while($row = mysql_fetch_assoc($getbikes)) { echo "<table><tr>"; echo "<td><a href='http://baldjf.com' class=''>$row[bikename]</a>"; echo "<a href='http://www.static-design.com'>"; echo "<img border='0' height='65'width='75' src='$filepath'>"; echo "<span>"; echo "<br>something here<br>"; echo "</a><br></font><br>"; echo "</span>"; if ($i == '$pp_column') { echo "</td></tr><tr>"; $column = $col_value*$e; $e++; } else { echo "</td>"; } $i++; } Code:
$getbikes = mysql_query("SELECT * FROM $table ORDER BY id DESC LIMIT $number "); //Retrieves all of the Data from table echo "<table><tr>"; while($row = mysql_fetch_assoc($getbikes)) { echo "<td><a href='http://baldjf.com' class=''>$row[bikename]</a>"; echo "<a href='http://www.static-design.com'>"; echo "<img border='0' height='65'width='75' src='$filepath'>"; echo "<span>"; echo "<br>something here<br>"; echo "</a><br></font><br>"; echo "</span>"; echo "</td>"; $i++; } Also, some HTML, you close a font tag, but you don't open it, and your <span> and <a> tags go like this: <a><span></a></span> (a.k.a., they aren't nested properly), which may screw them up. You might want to fix these. I hope Brandon doesn't mind me posting from his account -___- |
#3
|
||||
|
||||
if all you want is a 3 column (will never change)
echo <table> while (loop) { echo <tr><td>col 1</td><td>col 2</td><td>col 3</td></tr> } echo </table> |
#4
|
||||
|
||||
Quote:
Using your code superfly also did help, I changed it around a bit and got this. However the problem with this one is that the number of columns only applies to the first row, so I end up having data like this, data 1 data 2 data 3 data 4 data 5 data 6 dtat 7 data 8 .... I just can't understand why the value 3 for columns only applies to the first row now , you guys know why this happens? this is the final code that I have, PHP Code:
|
#5
|
|||
|
|||
I'm the same guy who posted as Superfly before. Anyway...
Code:
$col_value = "$column"; //number of columns of the table generated $column = 3; Code:
<?php $username="xxxxx"; $password="xxxxx"; $database="xxxxx"; $table="testing"; $number="8"; $i = 1; $e = 2; //number of columns of the table generated $column = 3; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $getbikes = mysql_query("SELECT * FROM $table ORDER BY id DESC LIMIT $number"); //Retrieves all of the Data from table echo "<table><tr>"; while($row = mysql_fetch_assoc($getbikes)) { echo "<td><a href='http://baldjf.com' class=''>$row[bikename]</a>"; echo "<a href='http://www.static-design.com'>"; echo "<img border='0' height='65'width='75' src='$filepath'>"; echo "<span>"; echo "<br>something here<br>"; echo "</a><br></font><br>"; echo "</span>"; echo "</td>"; if ($i == $column) { echo "</tr><tr>"; $column = 3*$e; $e++; } $i++; } echo "</table>"; ?> |
#6
|
||||
|
||||
wow thank you so much Aesma, it worked great!
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|