Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can the query jump columns 2

Status
Not open for further replies.

dmacster

Technical User
Jan 28, 2005
670
US
I didn't set this page up


But am tasked to setting up with a DB. Is it possible to setup as they want for advertisers with so many in the first column, jump to the second column, and then the third automatically?

The active advertisers will vary per week, and I think I'm comfortable enough to make a single column and limit to say 20 records, but not sure about the multiple columns.

Suggestions appreciated.

Thanks,
Donna
 
You can float the three columns, then populate them with one third of your categories in each column with however many entries that is
or
float the columns, calculate how many rows you need by adding the categories + the entries & split accordingly
or
use tables and one of the above methods, making sure not to split categories across columns


There is no need to limit to 20 entries. In your code, count the number of entries/categories and then split across columns accordingly.

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
The number will vary. Some weeks may have no advertisers in a particular category, some weeks there may be 200 advertisers altogether in maybe 15 different categories. That's why I wondered if it could be easily accomplished.

I may just have to run a single column.

thanks
donna
 
i wish i understood your question. i might be able to suggest a solution then!
 
Really I think traingamer has the right idea, 0 - 200 it doesn't really matter. You could automatically calculate the number of items that go into a column based on the number of columns you want to have.

This is fairly simple to do in PHP - and in fact I did something like this to display a dynamic list of DVDs into two columns.

You could do it something like the following:
Code:
$num = mysql_num_rows($rs);
$a = ceil($num / 2);
$i = 0;
while ($next = mysql_fetch_array($rs)){
	echo "\t\t\t\t<li><a href="detail.php'">'.htmlspecialchars($next['Title']).'</a></li>'."\n";
	if( ($i+1) == $a ){
		echo "\t\t\t</ul></div></div></td>\n";
		echo "\t\t<td><div class=\"outer\"><div class=\"inner\"><ul>\n";
	}
	$i++;
}
As you see here I get the number of results into $num and then divide by 2 (the number of columns). Then during each iteration of output I check to see if I've reached that limit - if so I output the closing of one column and the start of another column (here I used tables - you could just as easily use another method).

Are all your categories/advertisements going to be on the same page or are you breaking up the pages per category?
 
if i understand the OP (guess) it's not a question of splitting across columns but of completing one column then moving on to the next etc. varying number in each column. with the column break being triggered by some change in one of the fields or whatever.

that's not a 'count' based issue (or at least need not be). to me it looks like a pure css solution is called for: just a plain 3 column liquid design. using this the php would just have a linear output.
 
Even with a 3 column liquid design you still need some sort of linear output. The data in the 3 columns still needs to be grouped together. Yes I used a table, but it could just as easily have been floated DIVs with one div ending and the next starting. With the proper CSS there is your 3 column liquid design.

You could just as easily trigger a column change one something other than the count by checking the field results.
 
why does it need to be grouped together?

let's assume you have three categories and you want each category separated.
categories are fruit, vegetable and mineral

Code:
<?php
$query = 'Select id, name, category from stuff order by category DESC';
$result = mysql_query($query);
echo <<<STYLES
<style>
	.fruit{float:left; width:30%;}
	.vegetable{float:left; width:30%;}
	.mineral{float:left; width:30%;}
</style>
STYLES;
while ($row = mysql_fetch_assoc($result)){
	if (isset($category) && $row['category'] !== $category){
		$category = $row['category'];
		echo <<<HTML
		</div>
		<div id="{$category}">
HTML;
	} elseif (!isset($category)) {
		$category = $row['category'];
		echo <<<HTML
		<div id="{$category}">
HTML;
	}
	echo <<<HTML
			<span>
				<img src="images/{$row['id']}" alt="{$row['name']}"/>
			</span>
HTML;
}
?>
echo "</div>";
?>

 
In the example, there are more than 3 categories and the data was alphabetical down column 1, then to column 2, etc.
That's why I suggested counting.

If you simply want to float each category alphabetically across, that would be simpler and you could float them all, a category at a time. You could use a single class for all of the categories similar to jpadie's answer.
Just use a set of nested loops (one for the categories and one for the individual advertisers) to spit out the results.

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
Just got home and logged in.

Borvik - I do not believe the client will have enough entries to do another page. The sample they've sent me (and I've posted here) doesn't have too many and does have going down under category until the column is filled and then jumps. They have asked to have a "next" and "previous" link if they get more than 500, but I really can't see that happening.

jpadie - you've been such a help this week. It's to be grouped because that's what their designer presented without seeing what might need to be done to get that output.

I'm going to try both solutions you've presented tonight and see how they like them.

Stars to you.

Thanks,
Donna
 
Not a problem - I hope our banter has been of help to you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top