<?

Mysql_connect("$server","$user","$pass");
Mysql_select_db("$database");

$sql = "SELECT companyid,companyname FROM companies ORDER BY companyname
ASC";
$result = mysql_query($sql);
$num = mysql_num_rows($result);

if ($num) {
        while($row = mysql_fetch_array($result)) {
                print "$row[companyname]<br>";
                print getServices($row[companyid]) . "<br>";
                print "<hr>";
        }
} else {
        print "No Companies";
}

Function getServices ($id) {
        $sql = "SELECT services FROM services WHERE companyid = $id";
        $result = mysql_query($sql);
        $num = mysql_num_rows($result);

        if ($num) {
                while ($row = mysql_fetch_array($result)) {
                        $html.= "$row[services]<br>";
                }
        } else {
                $html = "No Services";
        }
        return $html;
}
?>

that should do it I think.. :)

/BoNzO
http://bonzo.sineleven.nu

-----Original Message-----
From: Andrius Jakutis [mailto:[EMAIL PROTECTED]] 
Sent: den 24 augusti 2001 04:05
To: [EMAIL PROTECTED]
Subject: [PHP-DB] can you help to beginner?

Hello All,

Maybe you can help me, becouse I was searching for various
documentations,
and it seems too difucult for me, becouse everything is so crowded.

I need to built small html file, where I could get listed companies.

I have two tables in my MYSQL database, companies and services.
Company table:
companyid and companyname

services table:
id companyid services.

So I need simply to get listings like this:

Company name
services

Company2 name
Services

etc...

Can you help me? I know that for this example its better to use one
table,
not two, but I am just learning..

Thanks



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to