Saya cukup baru di php jadi tolong jangan panggang saya :)

Kode saya saat ini hanya menunjukkan pengguna yang masuk saat ini dan pekerjaan mereka dengan manajemen sesi namun saya ingin menampilkan semua pengguna dari database saya (anggota) yang telah mengunggah pekerjaan mereka dan memiliki hyperlink di bagian bawah halaman sehingga orang dapat mengkliknya beri nama dan lihat semua gambar yang telah mereka unggah. ( << tidak yakin bagaimana melakukannya ). Apakah ada cara untuk menampilkan hanya pengguna yang telah mengunggah file ke database dan bukan hanya pengguna terdaftar?

<?php
  session_start();
  $page_title="Gallery Home";
  include("header.inc");
  include("nav.inc");
  include("categorys.inc");
?>
    <!-- start of main content -->
    <div id="main-content">
<?php 

  $db = mysqli_connect("localhost", "root","", "artworks")  or die(mysqli_error($db));
  $q = "select * from artwork";

  $results = mysqli_query($db, $q) or die(mysqli_error($db));

  while($row=mysqli_fetch_array($results))
  {

    print "<a href='artwork.php?artwork_id={$row['artwork_id']}'</a><img src='uploads/{$row['filename']}'height= '300' width='333.33' >";

   }

?>
     </div>

     <!-- end of main content -->
<?php

  //gets username of current user 
  $username = $_SESSION['username'];

  //this is the link that shows all pictures uploaded by user  
  print "<td><a href='member.php?$username='$username'>$username</a></td>\n";
?>


<?php 
  include("footer.inc");
?>

Terima kasih Tumpukan!

0
Andrew Tran 28 Oktober 2019, 08:43

1 menjawab

Jawaban Terbaik

Semoga membantu :) Goodluck!

<!-- start of main content -->
<div id="main-content">
<?php 
$db = mysqli_connect("localhost", "root","","artworks");
$q = "SELECT * FROM artwork GROUP BY member_id";  //artwork table must have member id, this id will be used matching for table member member id
$results = mysqli_query($db, $q) or die(mysqli_error($db));
if(mysqli_num_rows($results) > 0){ //if there is file/member id from table artwork matched for table member member id
    while($row = mysqli_fetch_array($results)){
    $member_id1 = $row['member_id'];    

        $query_member = mysqli_query($db,"SELECT * FROM users WHERE id='$member_id1' ")or die(mysqli_error($conn)); //only display member that has uploaded file
        $res = mysqli_fetch_array($query_member);
        $member_id = $res['id']; //this will be use for displaying uploaded file
        $member_username = $res['username'];
    ?>
        <a href="member.php?member_id=<?php echo $member_id; ?>" target="_blank" ><?php echo $member_username; ?></a><br> <!--  -->
    <?php
    }
}
else{
    echo "No Result Found.";    
}
?>
 </div>
 <!-- end of main content -->

Ini akan menjadi member.php

<?php
$db = mysqli_connect("localhost", "root","","artworks");
$member_id = $_GET['member_id'];
$query_artwork = mysqli_query($db,"SELECT * FROM artwork WHERE member_id='$member_id' ")or die(mysqli_error($db));
if(mysqli_num_rows($query_artwork) > 0){
while($res = mysqli_fetch_array($query_artwork)){
    $filename = $res['filename'];
    ?>
    <img src="uploads/<?php echo $filename; ?>" height= "300px" width="333.33px" >
    <?php
}
}
else{   
echo "No artworks found.";
}
?>
1
not_null 28 Oktober 2019, 09:18