RE: [PHP-DB] can you help to beginner?

From: Date: Thu, 23 Aug 2001 17:23:02 +0000
Subject: RE: [PHP-DB] can you help to beginner?
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-11731@lists.php.net to get a copy of this message
<? 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:andrius@internetmedia.lt] Sent: den 24 augusti 2001 04:05 To: php-db@lists.php.net 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: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#11731) next »