RUC... RUC... -4 years ago 132
PHP Question

Get one query using two tables

I want to get details from two table in my database.I use following code`

$sqlall="SELECT
student_detail.reg_no
, student_detail.full_Name
, student_detail.year_of_study
, student_detail.faculty
, student_detail.course
,student_hostel.reg_no
,student_hostel.room_no
,student_hostel.hostel_id
FROM student_detail,student_hostel
WHERE student_detail.reg_no = student_hostel.reg_no; ";


//This is print part

$result = $conn->query($sqlall);

if ($result->num_rows > 0) {
// output data of each row
//create table

echo "<table class=\"table table-hover\">
<tr>
<th>Reg. No.</th><th>Hostel id</th><th>Room No</th></tr>";
while($row = $result->fetch_assoc()) {

echo"<tr id=\"".$row["student_detail.reg_no"]."\" onclick=\"Redirect(this.id)\"><td>".$row["student_detail.reg_no"]."</td><td>".$row["student_hostel.room_no"]."</td><td>".$row["student_hostel.room_no"]."</td></tr>";
}
echo "</table>";
}
else
{
echo "<table class=\"table table-hover\">
<tr>
<th>Reg. No.</th><th>Hostel id</th><th>Room No</th></tr>;
<span id></span>
</table>";
}


after going to get data then become errors
this is print part**

Notice: Undefined index: student_detail.reg_no in C:\xampp\htdocs\HMS\HMS\lib\HOS_current.php on line 47
came this error

how can i fix it

Answer Source

TRY THIS:

 $sqlall="SELECT student_detail.reg_no, student_detail.full_Name, student_detail.year_of_study, student_detail.faculty, student_detail.course,student_hostel.reg_no,student_hostel.room_no,student_hostel.hostel_id FROM student_detail INNER JOIN student_hostel ON student_detail.reg_no=student_hostel.reg_no; ";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download