<?php
// Create connection
$con=mysqli_connect("localhost","root","root");
mysql_select_db("test") or die( "Unable to select database");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//***************************** table 1 detail ***********
$query = "SELECT * FROM fraud WHERE a_number=" . $_GET["aNun_id"];
echo "<title>" . $_GET["aNun_id"] . "</title>";
echo "<table width='50%' border='5'>
<tr>
<th>Date & Time</th>
<th>A Number</th>
<th>B Number</th>
<th>Status</th>
</tr>";
$result=mysql_query($query) or die (mysql_error());
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['a_number'] . "</td>";
echo "<td><a href='?bNun_id=".$row['b_number']."'>" . $row['b_number'] . "</a></td>";
echo "<td>" . $row['status'] . "</td>";
echo "</tr>";
}
echo "</table>";
//***************************** table 2 detail ***********
//Here i'm trying to use bNum_id in below query
$query = "SELECT * FROM fraud WHERE b_number=" . $_GET["bNun_id"];
echo "<table width='50%' border='5'>
<tr>
<th>Date & Time</th>
<th>A Number</th>
<th>B Number</th>
<th>Status</th>
</tr>";
$result=mysql_query($query) or die (mysql_error());
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['a_number'] . "</td>";
echo "<td>" . $row['b_number'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "</tr>";
}
echo "</table>";
//connection close
mysqli_close($con);
?>
Here in table one , I used aNun_id to get the data from another PHP file with "GET" command.
In the table two, I want bNun_id to show its related data in that table. How do i call bNun _id data to the second table from table one. Pls help me..
Are those two tables in the same page?
If so, You need to append the bNum_id to the same query string to use both aNum_id & bNum_id.
echo "<td><a href='?aNun_id=".$_GET["aNun_id"]."&bNun_id=".$row['b_number']."'>" . $row['b_number'] . "</a></td>";
Related
I am new to PHP coding and don't understand where I have gone wrong, I'm trying to display data from a MySQL database onto an HTML table but doesn't register the column fields, keeps coming up with Notice: Undefined index: First, Notice: Undefined index: last etc. How do I define my column fields?
Edited: here are links to pictures of my database and the error codes I'm receiving: http://imgur.com/E5uohjr
http://imgur.com/BGDn9SQ
Here is my code:
</head>
$con = mysqli_connect('localhost', 'root', '', 'form_database') or die("Can not connect: " . mysqli_error());
$result = mysqli_query($con,"SELECT first, last, phone, class FROM form_submissions");
echo "<table border=1>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Class interested in</th>
</tr>";
while($row = mysqli_fetch_assoc($results)){
echo "<tr>";
echo "<td>" . $row['first'] . "</td>";
echo "<td>" . $row['last'] . "</td>";
echo "<td>" . $row['phone'] . "</td>";
echo "<td>" . $row['class'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
check if you do have results before displaying, them.
<?php
// Create connection
$con = mysqli_connect('localhost', 'root', '', 'form_database');
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM form_submissions";
$result = mysqli_query($con, $sql);
//check if you get any results
if (mysqli_num_rows($result) > 0) {
echo "<table border=1>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Class interested in</th>
</tr>";
// output data of each row
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $row['first'] . "</td>";
echo "<td>" . $row['last'] . "</td>";
echo "<td>" . $row['phone'] . "</td>";
echo "<td>" . $row['class'] . "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "No results found";
}
mysqli_close($con);
The following code adds a Accept/Decline Button per row. But for some reason, the decline button does not appear. I dont know whats wrong. Been stuck for a while now. Help would be appreciated. Thanks!!
<?php
$con=mysqli_connect("localhost","root","","rabco");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM service_request");
echo "<table border='1'>
<tr>
<th>Service ID</th>
<th>Service Type</th>
<th>Schuduled Date</th>
<th>Scheduled Time</th>
<th>Client Reference
<th>Client ID</th>
<th>Admin ID</th>
<th>Special Instructions</th>
<th>Status</th>
<th>Approve</th>
<th>Decline</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Service_ID'] . "</td>";
echo "<td>" . $row['Service_type'] . "</td>";
echo "<td>" . $row['Sched_date'] . "</td>";
echo "<td>" . $row['Sched_time'] . "</td>";
echo "<td>" . $row['Client_reference'] . "</td>";
echo "<td>" . $row['Client_IDN'] . "</td>";
echo "<td>" . $row['Admin_IDN'] . "</td>";
echo "<td>" . $row['Special_instructions'] . "</td>";
echo "<td>" . $row['Request_status'] . "</td>";
echo "<td>Approve</td>";
echo "<td>Decline</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
You are missing the closing quotes on your href attributes, which is creating malformed HTML output.
You need to change:
echo "<td>Approve</td>";
echo "<td>Decline</td>";
to
echo "<td><a href='approve.php?Service_ID=".$row['Service_ID']."'>Approve</a></td>";
echo "<td><a href='decline.php?Service_ID=".$row['Service_ID']."'>Decline</a></td>";
There is a missing closing quote here:
echo "<td>Approve</td>";
Change to:
echo "<td><a href='approve.php?Service_ID=".$row['Service_ID']."'>Approve</a></td>";
I'm trying to display members from my database using PHP, however the last name goes in with the first name and I'm not quite sure why... Could anyone point me in the right direction?
<?php
$mysql_db_hostname = "localhost";
$mysql_db_user = "alex";
$mysql_db_password="";
$mysql_db_database="gym";
$con = mysql_connect($mysql_db_hostname, $mysql_db_user, $mysql_db_password) or die("Could not connect database");
mysql_select_db($mysql_db_database, $con) or die("Could not select database");
$query = mysql_query("select * from users WHERE Category='Member'");
echo "<table border=1>
<tr>
<th>Users ID</th>
<th>First Name</th>
<th>Last Name</th>
</tr>";
while($row =mysql_fetch_assoc($query))
{
echo "<tr>";
echo "<td>" . $row['user_id']."<br>" . "</td>";
echo "<td>" . $row['First_Name']."<br>" . "</td";
echo "<td>" . $row['Last_Name']."<br>" . "</td";
echo "</tr>";
}
echo "</table";
?>
You aren't closing the tags. Syntax highlighter would show the error.
while($row =mysql_fetch_assoc($query))
{
echo "<tr>";
echo "<td>" . $row['user_id']."<br>" . "</td>";
echo "<td>" . $row['First_Name']."<br>" . "</td"; <-----------
echo "<td>" . $row['Last_Name']."<br>" . "</td"; <------------
echo "</tr>";
}
You are not closing your <td> tags properly
echo "<td>" . $row['First_Name']."<br>" . "</td>";
//^here
echo "<td>" . $row['Last_Name']."<br>" . "</td>";
//^and here
So the output is all one cell with both variables printed inside
You forgot to close the td on your first name field.
Just change
</td
to
</td>
I'm trying to assign anID to the table I'm generating with PHP but it keeps returning an error. Here is the full code that works fine so far. All I want is to add an 'id' to the table so I can apply css styles to it in the relevant sheet
<?php
$con=mysqli_connect("localhost","<un>","<pw>","monitor");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM presnationalresults ORDER BY Percentage DESC");
echo "<table border='1'>
<tr>
<th>President</th>
<th>Party</th>
<th>Votes</th>
<th>Percentage</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['PresidentName'] . "</td>";
echo "<td>" . $row['PartyCode'] . "</td>";
echo "<td>" . $row['Votes'] . "</td>";
echo "<td>" . $row['Percentage'] . "</td>";
}
echo "</table>";
mysqli_close($con);
Any help? maybe I'm going about it the wrong way?
Please try below block of code . I have added table id and also close </tr> inside while loop
<?php
$con = mysqli_connect("localhost", "<un>", "<pw>", "monitor");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM presnationalresults ORDER BY Percentage DESC");
echo "<table border='1' id='table-id'>
<tr>
<th>President</th>
<th>Party</th>
<th>Votes</th>
<th>Percentage</th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['PresidentName'] . "</td>";
echo "<td>" . $row['PartyCode'] . "</td>";
echo "<td>" . $row['Votes'] . "</td>";
echo "<td>" . $row['Percentage'] . "</td>";
echo "</tr>"; // you forget close tr
}
echo "</table>";
mysqli_close($con);
I am having some trouble with my first PHP project, I am trying to get the data from MySQL database (Has 3 records) and display it in tables. Problem is it only seem to display records 2 and 3, it skips the 1st record. Please see my code and display below.
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM unitstats");
while($row = mysqli_fetch_array($result)) {
echo "<table border='1' style='color:white'>
<tr>
<th>ID</th>
<th>Name</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
you are using two while loop which is unnecessary use following code
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "</table>";
echo "<table border='1' style='color:white'>
<tr>
<th>ID</th>
<th>Name</th>
</tr>";
$result = mysqli_query($con,"SELECT * FROM unitstats");
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "<table border='1' style='color:white'>
<tr>
<th>ID</th>
<th>Name</th>
</tr>";
$result = mysqli_query($con,"SELECT * FROM unitstats");
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";
Basically you didn't need the initial loop, this would have mainly caused an issue because you would have been redeclaring $row with the second loop.
Just remove your outer while loop and just use this:
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM unitstats");
echo "<table border='1' style='color:white'>
<tr>
<th>ID</th>
<th>Name</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";