-1

How should my test.php get data from a database? My database name is "example" and the things i want to get are test1, test2, test3.

<html>
<a  href="test.php?ID=<?php echo $kerko_rezultatin['id_object'];?>">
</a> 
</html
Fabulous
  • 2,393
  • 2
  • 20
  • 27
notsoeasy
  • 41
  • 1
  • 9

1 Answers1

0

First you need to create a connection to you database:

$conn = mysqli_connect("localhost", "username", "pass", 
"db_name");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

Then you need to create a query to select data from your database:

$sql = "SELECT *
    FROM table
    WHERE 1";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) { 
  while($kerko_rezultatin = mysqli_fetch_assoc($result)) {
echo "<a  href='test.php?ID=".$kerko_rezultatin['id_object']."'> </a>"  
;}
  • I already have this one , but the question is what should I write in test.php, this code that u have wrote is in my index.php. Simplier , when I click the id--> to get only information of that ID . do you get it ? – notsoeasy Jun 26 '17 at 19:44
  • btw qenke shqiptare , shpresoj qe mkuptove – notsoeasy Jun 26 '17 at 19:45
  • Nope ste kuptova – Alkida Osmani Jun 26 '17 at 19:47
  • ket qe e ke shkru ti e kam paraqit ne index.php, dmth i got the id from database, kur e klikoj linkun e mar rezultatin "test.php?ID=1" por un dua te marr me shum te dhena prej databazes dhe posaqerisht prej qasaj Id, dhe te me paraqiten ne test.php – notsoeasy Jun 26 '17 at 19:52
  • $get_id = $_GET['ID']; //to get the value of id from your url SELECT * FROM table WHERE ID=$get_id //use this query to get the other data from your table – Alkida Osmani Jun 26 '17 at 19:57