here's my code i don't know where i do wrong here
<?php
$conn=oci_connect("martin","123","localhost/XE");
If (!$conn)
echo 'Failed to connect to Oracle';
else
echo 'Succesfully connected with Oracle DB';?>
<table border="1">
<?php $stid = oci_parse($conn, "select*from MsNama");
oci_execute($stid);
while ($row =
oci_fetch_array(
$stid,
OCI_ASSOC+OCI_RETURN_NULLS)
) {?>
<tr>
<td><?php echo $row[0]; ?></td>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
</tr>
<?php }?>
and here's my select on oracle database:
SQL> select * from MsNama
2 ;
NAMA ANGKA G
---------------------- -------- -
martin 1 m
this is what's it's look like
I changed the code with what i found on internet but still not working
<html>
<head><title>Oracle demo</title>
</head>
<body>
<?php
$conn=oci_connect("martin","123","localhost/XE");
If (!$conn)
echo 'Failed to connect to Oracle';
else
echo 'Succesfully connected with Oracle DB';
?>
<table border="1">
<?php $stid = oci_parse($conn, "select * from MsNama");
oci_execute($stid,OCI_DEFAULT);
while (oci_fetch($stid)) {
$empno = oci_result($stid, "NAMA");
$ename = oci_result($stid, "angka");
$job = oci_result($stid, "gender");
?>
<tr>
<td><?php echo $empno; ?></td>
<td><?php echo $ename;?></td>
<td><?php echo $job; ?></td>
</tr>
<?php }?>
</table>
</body>
</html>
i tried and always no result. nothing showing
oh my code not wrong but here's the code and it worked
<html>
<head><title>Oracle demo</title></head>
<body>
<?php
$conn=oci_connect("martin","123","localhost/XE");
If (!$conn)
echo 'Failed to connect to Oracle';
else
echo 'Succesfully connected with Oracle DB';
?>
<table border="1">
<?php $stid = oci_parse($conn, "select*from MsNama");
$r=oci_execute($stid);
while ($row = oci_fetch_array($stid, OCI_BOTH)) {?>
<tr>
<td><?php echo $row[0]; ?></td>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
</tr>
<?php }?>
</table>
</body>
</html>
the problem that i forgot to commit so .-.there's no result i'm sorry
Related
i have the following table on my database: student, mark, out_of ,subject, subject_routing, grade, and student_grade.
among these table, table student, mark, and out_of are where i face the problem.
the structure of those three table are as follow.
[[Mark of students tableout_of table(for mark)](https://i.stack.imgur.com/ATT8m.png)](https://i.stack.imgur.com/PYHUC.png)
from the above three table i want to display a table called "result" on HTML table which i need it looks like this.
Result table that i want to display on html table
the code i am trying is the following one. but it's not working rather it display repeated row values.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jion";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
<!DOCTYPE html>
<head>
<title> test table of data</title>
</head>
<body>
<table border="1">
<tr>
<th rowspan ="2">S/N</th>
<th rowspan ="2">ID</th>
<th rowspan ="2">Full Name</th>
<th colspan = "3">Student Mark(Mathematics Subject)</th>
<th>Sum</th>
</tr>
<?php
$sql="select DISTINCT student_name.index_number as id,
student_name.fname as First_name,
student_name.lname as last_name,
out_of.out_of as out_of,
mark.mark as mark
from student_name
INNER JOIN mark ON mark.st_id = student_name.index_number
INNER JOIN out_of ON out_of.subject_id = mark.subject_id
WHERE mark.subject_id=1";
$result=mysqli_query($conn,$sql);
$count = 0;
if(mysqli_num_rows($result) > 0){
while($row=mysqli_fetch_assoc($result)){
$count++;
$sum = $row['mark']++;
$sum_out = $row['out_of']++;
?>
<tr>
<td><?php echo $row['out_of']; ?></td>
<td><?php echo $row['out_of']; ?></td>
<td><?php echo $row['out_of']; ?></td>
<td><?php echo $sum_out; ?></td>
</tr>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['First_name']; ?> <?php echo $row['last_name']; ?></td>
<td><?php echo $row['mark']; ?></td>
<td><?php echo $row['mark']; ?></td>
<td><?php echo $row['mark']; ?></td>
<td><?php echo $sum; ?></td>
</tr>
<?php } } ?>
</table>
</body>
I'm having a problem where I made a website and I can successfully add data to every Student which works fine, however I'm trying to make a page, where I can basically search for the City(város in my php document) they live in, and it lists me all of those students data. I can succesfully insert into "város", however when I try to read the data, it doesn't work.
The Error message I get is:
SELECT * FROM Diák WHERE város = :város
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
my code is:
<?php
require "../config.php";
require "../common.php";
if (isset($_POST['submit'])) {
if (!hash_equals($_SESSION['csrf'], $_POST['csrf'])) die();
try {
$connection = new PDO($dsn, $username, $password, $options);
$sql = "SELECT *
FROM Diák
WHERE város = :város";
$város = $_POST['város'];
$statement = $connection->prepare($sql);
$statement->bindParam(':város', $város, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
?>
<?php require "../../../htdocs/test/public/templates/header.php";?>
<?php
if (isset($_POST['submit'])) {
if ($result && $statement->rowCount() > 0) { ?>
<h2>Találatok</h2>
<table>
<thead>
<tr>
<th>Oktatási_id</th>
<th>Vezeték név</th>
<th>Keresztnév</th>
<th>Évfolyam</th>
<th>Születési dátum</th>
<th>Város</th>
<th>Utca</th>
<th>Házszám</th>
<th>Irányítószám</th>
<th>Szak</th>
<th>Kar</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $row) : ?>
<tr>
<td><?php echo escape($row["oktatási_id"]); ?></td>
<td><?php echo escape($row["vezeték_név"]); ?></td>
<td><?php echo escape($row["kereszt_név"]); ?></td>
<td><?php echo escape($row["évfolyam"]); ?></td>
<td><?php echo escape($row["születési_dátum"]); ?></td>
<td><?php echo escape($row["város"]); ?></td>
<td><?php echo escape($row["utca"]); ?> </td>
<td><?php echo escape($row["házszám"]); ?> </td>
<td><?php echo escape($row["irányítószám"]); ?> </td>
<td><?php echo escape($row["szak"]); ?> </td>
<td><?php echo escape($row["kar"]); ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php } else { ?>
<blockquote>Nem találtunk diákot, aki ilyen Városban lakna. <?php echo escape($_POST['város']); ?>.</blockquote>
<?php }
} ?>
<h2>Városon alapuló keresés.</h2>
<form method="post">
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
<label for="város">Város</label>
<input type="text" id="város" name="város">
<input type="submit" name="submit" value="View Results">
</form>
Vissza a fő oldalra.
<?php require "../../../htdocs/test/public/templates/footer.php"; ?>
Apparently PDO doesn't understand named parameters that contain accented characters (I guess anything outside 7-bit ASCII). So change :város to :varos.
Im setting up a html table that connected from the database. But I want the table design like the excel which in html table using rowspan. but I cant work out the problem which Im working out.
Please help me to create this format. See the code below
<tbody>
<?php
include_once('connection.php');
$sql = "SELECT * FROM rqn ";
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($query)){
$result = $row['rqn_no'];
?>
<tr>
<td rowspan="2"><?php echo $row['rqn_no'] ?></td>
<td><?php echo $row['date_filed'] ?></td>
<td><?php echo $row['desc_text'] ?></td>
<td><?php echo $row['remarks'] ?></td>
<td><?php echo $row['date_approved'] ?></td>
<td>
<?php
include_once('connection.php');
$sql1 = "SELECT * FROM po_data where po_data.rqn_base = $result ";
$query1 = mysqli_query($conn, $sql1);
while($row1 = mysqli_fetch_assoc($query1)){
?>
<?php echo $row1['po_no'] ?>
<?php
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
Result I Wanted:
https://prnt.sc/md2t2s
Actual Result:https://prnt.sc/md2tpk
You can use rowspan with a div to achieve the result you want. Try this,
<tbody>
<?php
include_once('connection.php');
$sql = "SELECT * FROM rqn ";
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($query)){
$result = $row['rqn_no'];
?>
<tr>
<td rowspan="2"><?php echo $row['rqn_no'] ?></td>
<td><?php echo $row['date_filed'] ?></td>
<td><?php echo $row['desc_text'] ?></td>
<td><?php echo $row['remarks'] ?></td>
<td><?php echo $row['date_approved'] ?></td>
<?php
include_once('connection.php');
$sql1 = "SELECT * FROM po_data where po_data.rqn_base = $result ";
$query1 = mysqli_query($conn, $sql1);
$total_rows = mysqli_num_rows($query1);
// open <td>
echo "<td rowspan=$total_rows>";
while($row1 = mysqli_fetch_assoc($query1)){
?>
<?php echo "<div style='border-bottom:1px solid black'>" . $row1['po_no'] ."</div>" ?>
<?php
}
// close </td>
echo "</td>";
?>
</td>
</tr>
<?php
}
?>
</tbody>
Adjust the CSS according to your need.
Hi this is the final answer to my result.
Output
<tbody>
<?php
include ("connection.php");
$sql = "SELECT * FROM rqn ";
$result= mysqli_query($conn, $sql);
while($row=mysqli_fetch_array($result)):
$ename = $row['rqn_no'];
// count the esal in each ename
$sql2 = "SELECT * FROM po_data WHERE rqn_base=$ename";
$result2 = mysqli_query($conn, $sql2);
$count_result2 = mysqli_num_rows($result2);
?>
<tr >
<td rowspan="<?php echo $count_result2; ?>"><?php echo $row['rqn_no']; ?></td>
<td rowspan="<?php echo $count_result2; ?>"><?php echo $row['date_filed']; ?></td>
<td rowspan="<?php echo $count_result2; ?>"><?php echo $row['desc_text']; ?></td>
<td rowspan="<?php echo $count_result2; ?>"><?php echo $row['remarks']; ?></td>
<td rowspan="<?php echo $count_result2; ?>"><?php echo $row['date_approved']; ?></td>
<?php
// loop each esal
while($row2 = mysqli_fetch_array($result2)):
?>
<td><?php echo $row2['po_no']; ?></td>
</tr>
<?php
endwhile; // endwhile for each esal looping
endwhile; // endwhile for the main looping
?>
</tbody>
Tnx for helping me guys
I am making a page where it displays a table with staffID and staffName using PHP. When the user clicks the staffID it should then display a new table using the code from another file with extra details about that staffID such as shippingDate, OrderID, etc.
task9.php file below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PHP Task 9</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<?php
$sID= isset($_GET['staffID']) ? $_GET['staffID'] : '';
$conn = mysqli_connect('localhost', 'TWA', 'TWA_test', 'factory');
if ( !$conn ) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT s.staffID,s.staffName
FROM staff s";
$results = mysqli_query($conn, $sql)
or die ('Problem with query' . mysqli_error($conn));
?>
<h1> Staff Table </h1>
<table>
<tr>
<th>Staff ID</th>
<th>Staff Name</th>
</tr>
<?php while($row = mysqli_fetch_array($results)) { ?>
<tr>
<td> <?php echo $row[0] ?></td>
<td><?php echo $row[1] ?></td>
</tr>
<?php } ?>
<?php mysqli_close($conn); ?>
</table>
</body>
</html>
task8.php asks a user to enter a staffID and it displays all of the details, if the staffID does not exist then it displays an error. This file works fine and displays everything correctly. task8.php file below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PHP Task 8</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<?php
$conn = mysqli_connect('localhost', 'TWA', 'TWA_test', 'factory');
if ( !$conn ) {
die("Connection failed: " . mysqli_connect_error());
}
//obtain the staff ID input from the $_GET array
$sID= isset($_GET['staffID']) ? $_GET['staffID'] : '';
$sql = "SELECT s.staffID, p.orderID, p.orderDate, p.shippingDate,s.staffName
FROM purchase p
INNER JOIN staff s
ON p.staffID = s.staffID
WHERE p.staffID = '$sID'";
$results = mysqli_query($conn, $sql)
or die ('Problem with query' . mysqli_error($conn));
?>
<h1> Order Details </h1>
<?php $rows = mysqli_num_rows($results); ?>
<?php if($rows <= 0){ ?>
<p><?php echo "The staff ID entered is invalid"; ?></p>
<?php } else { ?>
<table>
<tr>
<th>Staff ID</th>
<th>Order ID</th>
<th>Order Date</th>
<th>Shipping Date</th>
<th>Staff Name</th>
</tr>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<?php if($row[0] != ""): ?>
<td><?php echo $row[0]; ?></td>
<?php else: ?>
<td><?php echo "N/A"; ?></td>
<?php endif; ?>
<?php if($row[1] != ""): ?>
<td><?php echo $row[1]; ?></td>
<?php else: ?>
<td><?php echo "N/A"; ?></td>
<?php endif; ?>
<?php if($row[2] != ""): ?>
<td><?php echo $row[2]; ?></td>
<?php else: ?>
<td><?php echo "N/A"; ?></td>
<?php endif; ?>
<?php if($row[3] != ""): ?>
<td><?php echo $row[3]; ?></td>
<?php else: ?>
<td><?php echo "N/A"; ?></td>
<?php endif; ?>
<?php if($row[4] != ""): ?>
<td><?php echo $row[4]; ?></td>
<?php else: ?>
<td><?php echo "N/A"; ?></td>
<?php endif; ?>
</tr>
<?php } ?>
<?php } ?>
<?php mysqli_close($conn); ?>
</table>
</body>
</html>
The problem I am facing is that when I click the staffID from the table on task9.php it just shows the error I included in task8.php "The staff ID entered is invalid". I don't know why it isn't displaying the details from task8.php
you did not build your link correctly, it should be
<?php echo $row[0] ?>
also, i feel somehow uncomfortable echoing outputs without htmlentities().
Yes, it is boring to type that everytime so i usually keep a function in every of my PHP projects like this
function e($whatToConvert){
return htmlentities($whatToConvert); //or htmlspecialchars
}
so the above code for instance becomes
<?php echo e($row[0]) ?>
You need to pass the parameter like this
<a href = "task8.php?staffID=<?php echo $row[0]?>">
Trying to list the data from mysql to a html table using php in main html file. I've been through all of the other questions on here and I'm sure I have mostly the same methods and code as them.
For some reason (which I suspect has something to do with mysql and not the code) the only result is a blank table with one row and five columns. Each time I try to implement the other codes they just seem to print text onto the site.
I'm very confused as I think I've done the right thing. I've even been able to list the data from mysql through php echo so I know it's there and that I can access it. Really would appreciate some help on this. Thank you.
<table border="1">
<tbody>
<?php
$connect = mysqli_connect("localhost", "daemon", "xampp", "test");
if (!$connect) {
die(mysqli_error());
}
$results = mysqli_query("SELECT title,url,details,file,submission_date FROM input");
while($row = mysqli_fetch_array($results)) {
?>
<td><?php echo $row['title']?></td>
<td><?php echo $row['url']?></td>
<td><?php echo $row['details']?></td>
<td><?php echo $row['file']?></td>
<td><?php echo $row['submission_date']?></td>
<?php
}
?>
</tbody>
</table>
You say this code is in your mail html file? And it is printing out onto the screen? Try changing your file to .php not .html! Php code won't run in a .html file, and will likely output your code directly onto the page.
Mysqli_query expect connection link as first parameter.
$results = mysqli_query($connect, "SELECT title,url,details,file,submission_date FROM input");
Just a quick not so related improvement. You can avoid inserting most of the php opening and closing clauses:
...
while($row = mysqli_fetch_array($results)){
echo "<td>".$row['title']."/td>";
echo "<td>".$row['url']"</td>";
...
}
?>
Use <tr> because table must have atleast one row(<tr>) and one column(<td>)
<table border="1">
<tbody>
<tr>
<?php
$connect = mysqli_connect("localhost", "daemon", "xampp", "test");
if (!$connect) {
die(mysqli_error());
}
$results = mysqli_query("SELECT title,url,details,file,submission_date FROM input");
while($row = mysqli_fetch_array($results)) {
?>
<td><?php echo $row['title']?></td>
<td><?php echo $row['url']?></td>
<td><?php echo $row['details']?></td>
<td><?php echo $row['file']?></td>
<td><?php echo $row['submission_date']?></td>
<?php
}
?>
</tr>
</tbody>
<table border="1">
<tbody>
<?php
$connect = mysqli_connect("localhost", "daemon", "xampp", "test");
if (!$connect) {
die(mysqli_error());
}
$results = mysqli_query($connect, "SELECT title,url,details,file,submission_date FROM input");
if (!$results) {
mysqli_error($results);
die();
}
while ($row = mysqli_fetch_array($results)) {
?>
<tr>
<td><?php echo $row['title'] ?></td>
<td><?php echo $row['url'] ?></td>
<td><?php echo $row['details'] ?></td>
<td><?php echo $row['file'] ?></td>
<td><?php echo $row['submission_date'] ?></td>
</tr>
<?php
}
?>
</tbody>
</table>