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
<?php require("db.php"); ?>
<html>
<head>
<title>Manage categories</title>
</head>
<body>
<h1>Category list</h1>
<table>
<thead>
<tr>
<td>catid</td>
<td>catname</td>
<td>catdesc</td>
<td>icon</td>
<td>displayorder</td>
<td>-----</td>
<td>-----</td>
</tr>
</thead>
<tbody>
<?php
$qry=" select * from categories order by catid ";
$res=mysql_query($qry) or die("gabim komande");
$n=mysql_num_rows($res);
for($i=1;$i<=$n;$i++)
{
$rresht=mysql_fetch_array($res);
?>
<tr>
<td><?php echo $rresht['catid']; ?></td>
<td><?php echo $rresht['catname']; ?></td>
<td><?php echo $rresht['catdesc']; ?></td>
<td><?php echo $rresht['icon']; ?></td>
<td><?php echo $rresht['displayorder']; ?></td>
<td>
<a href="edit.php?id=<?php echo $rresht['catid']; ?>">
Edit
</a>
</td>
<td>
<a href="delete.php?id=<?php echo $rresht['catid']; ?>">
Delete
</a>
</td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
</tr>
</tfoot>
</table>
<p> </p>
</body>
</html>