06 - Baza e te dhenave MySQL

Ne kete leksion

MySQL

Lidhja me serverin e bazes se te dhenave

faqa db.php

<?php

$theserver='localhost';

$theuser='root';

$thepassword='';

$thedatabase='mydb';

mysql_connect($theserver,$theuser,$thepassword)

or die('nuk lidhem dot me serverin');

mysql_select_db($thedatabase)

or die('nuk zgjedh dot database');

?>

Leximi i te dhenave nga DB dhe shfaqja ne browser

index.php

tabela Categories

  1. <?php require("db.php"); ?>

  2. <html>

  3. <head>

  4. <title>Manage categories</title>

  5. </head>

  6. <body>

  7. <h1>Category list</h1>

  8. <table>

  9. <thead>

  10. <tr>

  11. <td>catid</td>

  12. <td>catname</td>

  13. <td>catdesc</td>

  14. <td>icon</td>

  15. <td>displayorder</td>

  16. <td>-----</td>

  17. <td>-----</td>

  18. </tr>

  19. </thead>

  20. <tbody>

  21. <?php

  22. $qry=" select * from categories order by catid ";

  23. $res=mysql_query($qry) or die("gabim komande");

  24. $n=mysql_num_rows($res);

  25. for($i=1;$i<=$n;$i++)

  26. {

  27. $rresht=mysql_fetch_array($res);

  28. ?>

  29. <tr>

  30. <td><?php echo $rresht['catid']; ?></td>

  31. <td><?php echo $rresht['catname']; ?></td>

  32. <td><?php echo $rresht['catdesc']; ?></td>

  33. <td><?php echo $rresht['icon']; ?></td>

  34. <td><?php echo $rresht['displayorder']; ?></td>

  35. <td>

  36. <a href="edit.php?id=<?php echo $rresht['catid']; ?>">

  37. Edit

  38. </a>

  39. </td>

  40. <td>

  41. <a href="delete.php?id=<?php echo $rresht['catid']; ?>">

  42. Delete

  43. </a>

  44. </td>

  45. </tr>

  46. <?php

  47. }

  48. ?>

  49. </tbody>

  50. <tfoot>

  51. <tr>

  52. <td colspan="5"></td>

  53. </tr>

  54. </tfoot>

  55. </table>

  56. <p>&nbsp; </p>

  57. </body>

  58. </html>