Avatar billede mccookie Seniormester
15. august 2001 - 17:49 Der er 5 kommentarer og
2 løsninger

PHP / MySQL

Jeg er lige startet på PHP/MySQL og har en masse ideer med mangler lige færdighederne !!!

Jeg er ved at lave et lille test-database ting

Jeg har en database med 2 tabeler, der hedder kundeid og navn.

Jeg har også fint kunne hente data ud og vise dem !!!

Men jeg kunne tænke mig at udskrive dem i én tabel.

<?php

  $conn = mysql_connect(\"localhost\", \"root\", \"\");
  mysql_select_db(\"videobutik\");

  $getdata = mysql_query(\"select * from kunde\");

  while ($row = mysql_fetch_array($getdata)) {
  extract($row);

  echo \"<Table border=1 width=300>

    <Tr>
      <Td width=80><B>Kundenr:</B></Td>
          <Td width=220><B>Navn:</B></Td>
      </Tr>

 
    <Tr>
      <Td width=80>$kundenr</Td>
          <Td width=220>$navn</Td>
      </Tr>


      </Table>\";}

  mysql_close($conn);

JEg bruger denne løsning nu, men jeg vil kun have at der skal stå kundeId og navn én gang !!!!!

Er der nogen der kender nogle gode danske sider med MySQL

Kender i forvejen:

webcafe.dk
Avatar billede mccookie Seniormester
15. august 2001 - 17:51 #1
Kan måske bruges:

In this lesson, we\'re going to dive right in and create some simple yet useful pages using PHP and MySQL. Let\'s start by displaying the database we created yesterday, but with a little more panache.

First, let\'s query our database using the following code.





<html>



<body>



<?php







$db = mysql_connect(\"localhost\", \"root\");



mysql_select_db(\"mydb\",$db);



$result = mysql_query(\"SELECT * FROM employees\",$db);



echo \"<table border=1>\\n\";



echo \"<tr><td>Name</td><td>Position</tr>\\n\";



while ($myrow = mysql_fetch_row($result)) {



    printf(\"<tr><td>%s %s</td><td>%s</td></tr>\\n\", $myrow[1], $myrow[2], $myrow[3]);







}



echo \"</table>\\n\";







?>



</body>



</html>








You probably noticed that we introduced a couple of new features here. Most obvious is the while() loop. The loop says that as long as there are new rows of data to be grabbed (using the mysql_fetch_row() function), assign that row to the $myrow variable. Then execute the instructions between the curly brackets ({}). Take a look for a second, and this should make sense.

The mysql_fetch_row() function bears a closer look. One small problem with mysql_fetch_row() is that it returns an array that supports only numeric references to the individual fields. So the first field is referred to as 0, the second as 1, and so on. With complex queries this can become something of a nightmare.

Now let\'s examine the loop in more detail. The first few lines you\'ll recognize from the example in Lesson 1. Then in the while() loop we fetch a row from the result and assign it to the array $myrow. Then we print the contents of the array on the screen with the printf function. After that it loops around again, and another row is assigned to $myrow. It will do this until it runs out of rows to grab.

The great thing about a while() loop is that if your query returns no records, you won\'t get an error message. The first time through there won\'t be any data to assign to $myrow, and the program will just move on.

But if the query returns no data, we have no way of letting the user know, and
Avatar billede myplacedk Nybegynder
15. august 2001 - 18:19 #2
Jeg retter lige lidt rundt omkring.
Nogle af mine rettelser er bare min personlige smag, andre er bredt anerkendt som \"god programmeringsskik\".:)

<table border=\"0\" width=\"300\">
    <tr>
        <th width=\"80\">Kundenr:</th>
        <th width=\"220\">Navn:</th>
    </tr>
<?php
$conn = mysql_connect(\'localhost\', \'root\', \'\');
mysql_select_db(\'videobutik\', $conn);

$getdata = mysql_query(\"select kundenr, navn from kunde\");

while ($row = mysql_fetch_array($getdata)) {
    echo \'<tr><td>\'.$row[\'kundenr\'].\'</td>\';
    echo <td>\'.$row[\'navn\'].\'</td></tr>\';
}
?>
</table>
Avatar billede myplacedk Nybegynder
15. august 2001 - 18:20 #3
    echo \'<td>\'.$row[\'navn\'].\'</td></tr>\';

Der manglede lige en \' før <td>. :)
Avatar billede mccookie Seniormester
15. august 2001 - 18:24 #4
myplacedk>>>>

Perfekt :o)

Er meget ny i PHP/MySQL ca. igår startede jeg !!!

Kender du et godt med PHP/MySQL toturials ???
Avatar billede myplacedk Nybegynder
15. august 2001 - 19:15 #5
Hmm...
http://mbn.dk/
http://webcafe.dk/
http://webmonkey.com/
http://php.dk/
http://hotscripts.com/

og ellers er manualen http://php.net/manual nu ganske god, selv om man skal være lidt nørdet for at kunne forstå den fra starten. :)
Avatar billede nexoz Nybegynder
15. august 2001 - 22:24 #6
http://www.webmasterbase.com
De har i hvert fald også MANGE lækre artikler om alt muligt... Et must hvis man skal igang med hjemmeside, eller ønsker at lærer nogle standarder eller nye tricks :)
Avatar billede nexoz Nybegynder
15. august 2001 - 22:25 #7
Hov glemte lige
http://www.mysql.com/doc/
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester