Connecting Tech Pros Worldwide Forums | Help | Site Map

Dynamic Data Layout

Newbie
 
Join Date: Nov 2008
Posts: 7
#1: Nov 18 '08
Hi there,

I apologise if I'm posting in the wrong section - I Have absolutely no idea how my problem is resolved.

I have a recordset that queries my SQL data base the the results are displayed in a list - all normal so far.

What I want is insert a line between all the products that my SQL query displays and/or have each one in an alternative coloured background.

How is this done?
Thanks for any help given!

Member
 
Join Date: Nov 2008
Posts: 80
#2: Nov 18 '08

re: Dynamic Data Layout


It's very easy if I get it correct. The proper HTML element to use should be a list (ul for unordered lists).

You can style you list with CSS (Insert margins between lits items, change backgrounds etc.).

For alternative background colors you may use classes. Here is an example:
[HTML]<ul>
<li class="odd">item 1</li>
<li class="even">item 2</li>
<li class="odd">item 3</li>
</ul>[/HTML]

Styles for classes above:
Expand|Select|Wrap|Line Numbers
  1. odd {background:#ccc;}
  2. even {background:#ddd;}
Newbie
 
Join Date: Nov 2008
Posts: 7
#3: Nov 19 '08

re: Dynamic Data Layout


Thanks for the post serdar but styling is pages is really not my strong point and um unsure how to implement your code into my Sql results.

Can you please elaborate on how I insert lines between my results.

Thanks once again.
Member
 
Join Date: Nov 2008
Posts: 80
#4: Nov 19 '08

re: Dynamic Data Layout


Okay, which scripting language (PHP, ASP, JSP, etc.) are you using to query your database?
Newbie
 
Join Date: Nov 2008
Posts: 7
#5: Nov 19 '08

re: Dynamic Data Layout


Hi, Im using PHP in dreamweaver CS3
Member
 
Join Date: Nov 2008
Posts: 80
#6: Nov 19 '08

re: Dynamic Data Layout


Here is a sample php script, upload it to your server and test:

[PHP]<?php

//this is a sample result set, you should replace it with your SQL query results
$results=array("result 1", "result 2", "result 3", "result 4", "result 5");

$odd=true;

foreach ($results as $r) {
if ($odd) {$listClass='odd';}
else {$listClass='even';}
$odd=!$odd;
$list.='<li class="'.$listClass.'">'.$r.'</li>';
}

?>

<html>
<head>
<style>
li {margin:10px 0;}
.odd {background:#ccc;}
.even {background:#ddd;}
</style>
</head>
<body>
<ul>
<?php echo $list; ?>
</ul>
</body>
</html>[/PHP]
Reply