Re: Combining recordsets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm not sure about your question, specially when you say "unlimited number",
but I wrote this little code to show you how to handle the 3 recordsets:

<?
$myconn = mysql_connect("localhost", <username>, <password>);
$db = mysql_select_db("test");
$onefld = true; // to get in one field all field combinations you want,
using the CONCAT function, set this var to true
$sep = "' - '"; // to separate every in field in CONCAT function
if ($onefld) $sql= "SELECT concat(strcolor, ".$sep.", strsize, ".$sep.",
strshape) ";
else $sql = "SELECT strcolor, strsize, strshape ";
$sql .= "FROM color, sizes, shape  order by codcolor, codsize, codshape";
$rst=mysql_query($sql);
echo mysql_error();
$arr = array();
while ($row=mysql_fetch_array($rst)) {
    if (!$onefld) {
        $arr[]= $row[0].", ".$row[1].", ".$row[2]; // if you want to use any
other separator
    } else{
        $arr[]= $row[0]; // when using the CONCAT function every combination
comes in one field
    }
}
// just to display what $arr contains
for ($i = 0; $i < count($arr); $i++) {
    echo $arr[$i]."<br>";
}
?>

Please, let me know if this is what you wanted.

Roger

2007/8/2, Tony Dillon <tony_dillon_99@xxxxxxxxxxx>:
>
>
>
>
>
> Hi everyone, I have to combine the results of a potentially unlimited
> number of mysql recordsets into a single array. For example, if I have the
> following record sets:   Colours (with 3 records)   Sizes   (with 3
> records)   Shapes (with 3 records) I need to create an array with one row
> for all possible (27) combinations. Does anybody have a handy function for
> achieving this? Many thanks in advance,Tony
> _________________________________________________________________
> 100's of Music vouchers to be won with MSN Music
> https://www.musicmashup.co.uk/index.html
>
> [Non-text portions of this message have been removed]
>
>
>
> PHP Data object relational mapping generator
> http://www.metastorage.net/
> Yahoo! Groups Links
>
>
>
>


[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux