Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Splitting a table into three groups

Codes here !

Moderators: macek, egami, gesf

Splitting a table into three groups

Postby sametch » Thu Aug 29, 2002 9:46 pm

I am trying to divide the records returned from a table into three "equal" groups alphabetically.

I am using a for loop and switch to divide the groups up as shown below:

switch ($i)
{
case ($i >= $aStart && $i <= $aEnd):
$aValues = $aValues . $i . " = ". $letter . "<br>";
break;

case ($i >= $bStart && $i <= $bEnd):
$bValues = $bValues . $i . " = ". $letter . "<br>";
break;

case ($i >= $cStart && $i <= $cEnd):
$cValues = $cValues . $i . " = ". $letter . "<br>";
break;
}

The values for the comparitors are:

$aStart = 0 $aEnd = 4
$bStart = 5 $bEnd = 8
$cStart = 9 $cEnd = 12

Each time the results for the first run i.e when i=0 end up in the second group when it should clearly end up in the first.

It driving me mad.

here is the output:

1 = b
2 = c
3 = d
4 = e


0 = a
5 = f
6 = g
7 = h
8 = i


9 = j
10 = k
11 = l
12 = m

does anyone know why?

sametch :?
sametch
New php-forum User
New php-forum User
 
Posts: 17
Joined: Wed Jul 03, 2002 3:10 am

Postby DoppyNL » Fri Aug 30, 2002 12:24 am

I'm not completely sure what you're actually trying to do, I think it's this:

you want to run a mysql-query, and after that, split the result into 3 arrays of (almost) the same number of records, in alfabeticle order.

if so, run you're query, use "mysql_num_rows($result);" to get the number of records, then get them a record at a time, and place them in whatever array you want (or split them in 3 if you want)

Hope this helps...

Greetz Daan
DoppyNL
 

Postby sametch » Fri Aug 30, 2002 12:38 am

Thanks

I will give that a try for the future. In the meantime I have soolved it by replacing the switch statement with three seperate if() statements, performing the same logic. For some reason switch does not behave correctly when i=0. This leaves me well confused :?

sametch
sametch
New php-forum User
New php-forum User
 
Posts: 17
Joined: Wed Jul 03, 2002 3:10 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.