I'm new to web development, currently, I'm creating a website that will allow students to rate their university. Since there's a lot of universities, I want to build a dynamic page to let the page load the contents from the database automatically. But the problem is, with my method(which I think is totally unusual and wrong), I can't copy the link of the school and send it to the others because the page is getting information from the previous page to load all the contents.
This is what I did on the first page
$sql = "SELECT * FROM schools WHERE state_id=$sid";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo"<form action='../school.php' method='post'><div class='states&school'>
<h3><button class='searchedschool' name='id' value=".$row['school_id']." >"
.$row['school_name']."</button>
</h3>
</div></form>";
}
}
?>
Basically, I have this PHP code to echo out the list of schools and with school_id
as button value
And on the school.php page
<?php
$sid=$_POST['id']
?>
h1 class="schoolheading"><?php
$result = mysqli_query($con,"SELECT school_name FROM schools WHERE school_id=$sid");
while($row = mysqli_fetch_assoc($result)) {
echo $row['school_name'];}
?></h1>
<div class="schoolmain">
<div class="schoolbody">
<div class="school_top">
<?php
$result = mysqli_query($con,"SELECT school_title FROM schools WHERE school_id=$sid");
while($row = mysqli_fetch_assoc($result)) {
echo"<img src='image/".$row['school_title'].".jpg' class='schoolphoto' alt=''>";}
?>
I use code like these to echo out all the information where school_id=$sid
$sid
is the value I get from the previous page.
So what is the actual way to do this, so I can have an actual URL for every page?
Aucun commentaire:
Enregistrer un commentaire