Re: beginner: why does this not work

From: Date: Tue, 06 May 2003 22:20:10 +0000
Subject: Re: beginner: why does this not work
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-19785@lists.php.net to get a copy of this message
Hi, here are my two cents > mysql_connect ('localhost','',''); > mysql_select_db("tristan"); Here you should have used variables.stored in an extra file like config.inc.php $dbhost = "localhost"; $dbpw = ""; $dbuser = ""; $dbname ="tristan"; and then included ( include('config.inc.php'); )it in your main file. The reason is if have more pages accessing the Database and you change your server, your dbuser, pw and possibly your host will probably change and you would have to edit every single file. With a central Config file, you can change the values for every page. > $query = "SELECT voornaam, achternaam, adres, adres_nr, postcode, > woonplaats, telefoonnr, geslacht, notitie, id FROM persoon"; > $result = mysql_query($query); Somebody said it already SELECT * from persoon gets the job done just fine > while ($rij = mysql_fetch_array($result)) { > > $voornaam = $rij["voornaam"]; > $achternaam = $rij["achternaam"]; > $adres = $rij["adres"]; > $adresnr = $rij["adres_nr"]; > $postcode = $rij["postcode"]; > $woonplaats = $rij["woonplaats"]; > $telefoonnr = $rij["telefoonnr"]; > $geslacht = $rij["geslacht"]; > $notitie = $rij["notitie"]; > $id = $rij["id"]; the ten lines above equal: extract($rij); the entire code in the while-loop can be replaced by <? echo "<center><table border=\"2\" width=\"100%\" bordercolor=\"black\" cellspacing=\"1\" style=\"font-size:12pt; background-color: #ffffff;\"> foreach($rij as $temp) { echo "<tr><td>".strtoupper(key($rij)).":".$temp."</td></tr>"; } echo "</table></center><br><br>"; ?> let me know if it doesn't work.. diggn

« previous php.windows (#19785) next »