nooobie needs help

Status
Not open for further replies.

ste2me

Beta member
Messages
1
I have been working on a website using PHP and MySQL and although I have knowledge in both these fields, my knowledge is quite limited and I have come across a problem I need help with.
I am creating a videos page and I would like the videos to be displayed (using PHP) in a format similar to what is found here:


hiphopdx.com/index/videos?nav

I would like the videos to display the date headline (the date being when the videos were posted) then the thumbnails of the videos to be displayed in 4 columns. I already have the videos page set up with the pagination, mysql connection and video details. I am currently displaying the videos in a single column as I dont know how to display PHP results in multiple columns.

So basically I am looking for the videos page to display the results like this (example):

Thursday, August 27, 2009
Video 1 | Video 2 | Video 3 | Video 4
Video 5 | Video 6 | Video 7 | Video 8

many thanks
 
An hml table is the way to go, if you don't want to use any additional classes you can always echo the code for the table to be created, however the source code would be really messy
 
i would create an html table to produce the requested output.

PHP Tables (table, tables) - PHP Classes

create a table with 4 columns and necessary amount of rows.

That's just unnecessary. You don't need a whole class to do this, it's quite simple actually.

Code:
<?php

$sql = mysql_query ("SELECT * FROM videos");

$cols = 4; // set number of columns
$i = 0;    // counter

echo '<table border="0" cellspacing="1" cellpadding="3">';

while ($row = mysql_fetch_array ($sql)) {
	// start new row
	if ($i % $cols == 0) {
		echo '<tr>';
	}

	// run through the columns
	echo '<td>'.$row['video_name'].'</td>';
	
	// we have reached the end of the specified number of columns, so close it
	if ($i % $cols == $cols) {
		echo '</tr>';
	}

	$i++;
}

// in case there are not the exact amount of columns as we specified, add some blank ones to clean up
if ($i % $cols != 0) {
	while ($i++ % $cols != 0) {
		echo '<td> </td>';
	}
	echo '</tr>';
}

?>
 
Status
Not open for further replies.
Back
Top Bottom