Well, I've been working on retrieving the data based on only the Regno and Subcode provided through GET method.
I did try out the getting output without the table format , just by using printf stmt .
<?php
$regNo=$_GET['Regno'];
$Subjectcode=$_GET['Subjectcode'];
( then there is the connection part )
$sql="SELECT Co1,Co2, Co3, Co4, Co5, Co6 FROM ab where Regno='$regNo' and
Subcode='$Subjectcode'";
$result=mysqli_query($con,$sql);
// Associative array
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
?>
<div>
<table >
<tr>
<th>Co1</th>
<th>Co2</th>
<th>Co3</th> // these get displayed
<th>Co4</th>
<th>Co5</th>
<th>Co6</th>
</tr>
<?php
If (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $row['Co1']; ?></td>
<td><?php echo $row['Co2']; ?></td>
<td><?php echo $row['Co3']; ?></td> // these don't get displayed
<td><?php echo $row['Co4']; ?></td>
<td><?php echo $row['Co5']; ?></td>
<td><?php echo $row['Co6']; ?></td>
</tr>
<?php
}
}
?>
</tr>
</table>
</div>
The output should be the data displayed in the table format . but the output I've been getting is just nothing !!!
EDIT 1
I've also tried this code
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
// 1. Enter Database details
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'all';
// Create connection
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$reg_no = isset($_POST['Regno']) ? $_POST['Regno'] : '';
$sql = "SELECT * FROM ab WHERE Regno='".$reg_no."'";
while ($rows = mysqli_fetch_array($sql)) {
$Sem = $rows['Sem'];
$Co1 = $rows['Co1'];
$Co2 = $rows['Co2'];
$Co3 = $rows['Co3'];
$Co4 = $rows['Co4'];
$Co5 = $rows['Co5'];
$Co6 = $rows['Co6'];
$Subname = $rows['Subname'];
$Externalmarks = $rows['Externalmarks'];
echo
"$Subname<br>$Sem<br>$Co1<br>$Co2<br>$Co3<br>$Co4<br>$Co5<br>$Co6<br>
$Externalmarks<br><br>";
}
?>
Okay, so in your edit you are not using mysqli_query() before passing the SQL into the mysqli_fetch_array() so it is not going to return any results.
Here is some reference materials: http://php.net/manual/en/mysqli-result.fetch-array.php
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
// 1. Enter Database details
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'all';
// Create connection
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the variable needed for the query. URL should look like ex: something.com/thispage.php?Regno=1220
$reg_no = isset($_GET['Regno']) ? $_GET['Regno'] : '';
$sql = "SELECT * FROM ab WHERE Regno='" . $reg_no . "'";
$query = $conn->query($sql);
?>
<div>
<table >
<tr>
<th>Co1</th>
<th>Co2</th>
<th>Co3</th>
<th>Co4</th>
<th>Co5</th>
<th>Co6</th>
</tr>
<?php
// Place each result into an array.
$rows = array();
while($row = $query->fetch_array()){
$rows[] = $row;
}
// Loop through the array and structure the table.
foreach($rows as $row){
echo "<tr>";
echo "<td>" . $row['Co1'] . "</td>";
echo "<td>" . $row['Co2'] . "</td>";
echo "<td>" . $row['Co3'] . "</td>";
echo "<td>" . $row['Co4'] . "</td>";
echo "<td>" . $row['Co5'] . "</td>";
echo "<td>" . $row['Co6'] . "</td>";
echo "</tr>";
}
// Free the result set.
$query->close();
// Close the connection.
$conn->close();
?>
</table>
</div>
I hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.