I have two sql tables I'm reading from and I would like to display each table as its own, separate table. First the internal, and then the external. And I'd like to have a simple title prefacing each one. For instance:
INTERNAL
Table here
EXTERNAL
Table here
What's happening though is the INTERNAL and EXTERNAL titles keep appearing
on the same line, or both come before the tables. Like this:
INTERNAL
EXTERNAL
Internal Table here
External Table here
I've tried including the titles as part of the php tags. Those are the currently commented out lines. And I've also tried adding the html outside of the php tags like this:
<br><br>
<b>INTERNAL</b>
<br><br>
<?php Internal Table here ?>
And then:
<br><br>
<b>EXTERNAL</b>
<br><br>
<?php External Table here ?>
But that still results in both titles appearing first, before the tables. Does the html get processed prior to the php? I must be interpreting this too linearly, like a script because it's certainly not being processed in the order in which it is coded on my page.
This is my code as is, which has the titles commented out. The tables appear sandwiched together which tells me they are not being interpreted as two distinct elements on the page. Do I need to put each one in it's own tag?
<?php
$internal = getInternalNetworkTable();
if ($internal->num_rows > 0){
//echo " <b>INTERNAL</b>";
echo "<table cellspacing=\"0\">";
echo "<tr>";
echo " <th><b>Device</b></th>";
echo " <th><b>Label</b></th>";
echo " <th><b>Address</b></th>";
echo " <th><b>Type</b></th>";
echo " <th><b>DisplayNumber</b></th>";
echo " <th><b>Wiki</b></th>";
echo "</tr>";
while ($row = $internal->fetch_assoc()){
echo "<tr>";
echo ("<td>" . $row["Device"] ."</td>");
echo ("<td>" . $row["Label"]."</td>");
echo ("<td>" . $row["Address"]."</td>");
echo ("<td>" . $row["Type"]."</td>");
echo ("<td>" . $row["DisplayNumber"]."</td>");
echo ("<td>" . $row["Wiki"]."</td>");
echo "</tr>";
}
} else {
echo "No results founds";
}
?>
<?php
$external = getExternalNetworkTable();
if ($external->num_rows > 0){
//echo " <b>EXTERNAL</b>";
echo "<table cellspacing=\"0\">";
echo "<tr>";
echo " <th><b>Device</b></th>";
echo " <th><b>Label</b></th>";
echo " <th><b>Address</b></th>";
echo " <th><b>Type</b></th>";
echo " <th><b>DisplayNumber</b></th>";
echo " <th><b>Wiki</b></th>";
echo "</tr>";
while ($row = $external->fetch_assoc()){
echo "<tr>";
echo ("<td>" . $row["Device"] ."</td>");
echo ("<td>" . $row["Label"]."</td>");
echo ("<td>" . $row["Address"]."</td>");
echo ("<td>" . $row["Type"]."</td>");
echo ("<td>" . $row["DisplayNumber"]."</td>");
echo ("<td>" . $row["Wiki"]."</td>");
echo "</tr>";
}
} else {
echo "No results founds";
}
$conn->close();
?>
EDIT:
Needed to add:
echo "</table>";
New code:
<?php
$internal = getNovatoInternalNetworkTable();
if ($internal->num_rows > 0){
echo " <b>INTERNAL</b>";
echo "<table cellspacing=\"0\">";
echo "<tr>";
echo " <th><b>Device</b></th>";
echo " <th><b>Label</b></th>";
echo " <th><b>Address</b></th>";
echo " <th><b>Type</b></th>";
echo " <th><b>DisplayNumber</b></th>";
echo " <th><b>Wiki</b></th>";
echo "</tr>";
while ($row = $internal->fetch_assoc()){
echo "<tr>";
echo ("<td>" . $row["Device"] ."</td>");
echo ("<td>" . $row["Label"]."</td>");
echo ("<td>" . $row["Address"]."</td>");
echo ("<td>" . $row["Type"]."</td>");
echo ("<td>" . $row["DisplayNumber"]."</td>");
echo ("<td>" . $row["Wiki"]."</td>");
echo "</tr>";
}
echo "</table>";
} else {
echo "No results founds";
}
?>
<?php
$external = getNovatoExternalNetworkTable();
if ($external->num_rows > 0){
echo " <b>EXTERNAL</b>";
echo "<table cellspacing=\"0\">";
echo "<tr>";
echo " <th><b>Device</b></th>";
echo " <th><b>Label</b></th>";
echo " <th><b>Address</b></th>";
echo " <th><b>Type</b></th>";
echo " <th><b>DisplayNumber</b></th>";
echo " <th><b>Wiki</b></th>";
echo "</tr>";
while ($row = $external->fetch_assoc()){
echo "<tr>";
echo ("<td>" . $row["Device"] ."</td>");
echo ("<td>" . $row["Label"]."</td>");
echo ("<td>" . $row["Address"]."</td>");
echo ("<td>" . $row["Type"]."</td>");
echo ("<td>" . $row["DisplayNumber"]."</td>");
echo ("<td>" . $row["Wiki"]."</td>");
echo "</tr>";
}
echo "</table>";
} else {
echo "No results founds";
}
$conn->close();
?>
You're missing </table> in both display of tables.
Therefore your table will be merge in each other.
echo '</table>';
Before both of your } else { should do the trick
Related
I have tried below code; as you can see in bold line i want to add two hyperlink but i am not getting results.I want to create a variable hyperlink.
<?php
echo "<!DOCTYPE html>";
echo "<html>";
echo "<title> disorders </title>";
echo "<body>";
include ('menu.php');
echo "<br>";
echo "<br>";
$disorder = $_GET ['disorder'];
$sql_disorder= "SELECT * FROM `disorders raw datasets` WHERE `Name of disorder` = '$disorder' ";
if ($result_disorder = mysqli_query($conn, $sql_disorder));
{
echo "<table border='1' cellpadding='2' cellspacing='1'> ";
echo "<tr>";
echo "<th>Accession ID</th>";
echo "<th>Title</th>";
echo "<th>Abstract</th>";
echo "<th>Tissue type</th>";
echo "<th>PMID</th>";
echo "<th>Other information</th>";
echo "</tr>";
while($row_disorder = mysqli_fetch_array($result_disorder))
{
echo "<tr>";
**echo "<td><a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc= href='https://www.ebi.ac.uk/arrayexpress/experiments/" . $row_disorder['Accession ID'] . " ' ' >" . $row_disorder['Accession ID'] . "</a> </td>";**
echo "<td>" . $row_disorder['Title'] . " </td>";
echo "<td>" . $row_disorder['Abstract'] . "</td>";
echo "<td>" . $row_disorder['Tissue type'] . " </td>";
echo "<td><a href='https://www.ncbi.nlm.nih.gov/pubmed/" . $row_disorder['PMID'] . " '>" . $row_disorder['PMID'] . "</a></td>";
echo "<td><a href='disorder_info.php?" . $row_disorder['Other information'] . " ' >" . $row_disorder['Other information'] . "</a></td>";
echo "</tr>";
}
echo "</table>";
}
echo "</body>";
echo "</html>";
?>
I don't know why you are using two href in a single tag, that does not support by any dom. Although replace your code with the following line.
echo "
<td><a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=' href='https://www.ebi.ac.uk/arrayexpress/experiments/' " . $row_disorder['Accession ID'] . " ' '>" . $row_disorder['Accession ID'] . "</a> </td>";
You will have to use urlencode for it to work
$queryString = urlencode("href='https://www.ebi.ac.uk/arrayexpress/experiments/{$row_disorder['Accession ID']}'");
echo "
<td>
<a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=$queryString'>
{$row_disorder['Accession ID']}
</a>
</td>";
In the car page,i already input all the data into mysql database(car table).So i want to ease the user to find the car that available on pickup date and return date.So,I made search pickup date and return date in search page.But the error is "could not be execute".
This is using mysql and php.
car.php
</body>
<table align='center' width='40%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<form action="search.php" method="post" enctype="multipart/form-data">
<td><input type="date" name="Pickup_date" placeholder="Pickup_date" style='height:38px' required /></td>
<td><input type="date" name="Return_date" placeholder="Return_date" style='height:38px' required /></td>
<td><input type="submit" name="submitbook" value="Search" style='background-color: blue; border: none; color: white; padding: 10px 10px; text-align: center; text-decoration: none; display: inline-block; font-size: 14px;'/></td>
</div>
</form>
</table>
<?php
$link = mysqli_connect("localhost", "root", "", "online_car_rental");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt select query execution
$sql = "SELECT * FROM car";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>Id</th>";
echo "<th>Name</th>";
echo "<th>Price(RM)</th>";
echo "<th>Colour</th>";
echo "<th>Mode</th>";
echo "<th>Image</th>";
echo "<th>Status</th>";
echo "<th>Add to Booking</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['car_id'] . "</td>";
echo "<td>" . $row['car_name'] . "</td>";
echo "<td>" . $row['car_price'] . "</td>";
echo "<td>" . $row['car_colour'] . "</td>";
echo "<td>" . $row['car_mode'] . "</td>";
echo "<td><img src='" . $row['car_image'] . "' height='100'
width='100'></td>";
echo "<td>" . $row['car_status'] . "</td>";
echo '<input type="hidden" name="pickup_date"
value="'.$pickup_date.'">';
echo '<input type="hidden" name="return_date"
value="'.$return_date.'">';
echo "<td><button onclick=\"booking_car('" . $row['car_id'] .
"')\">Book</button>
</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
</html>
search.php
<?php
$link = mysqli_connect("localhost", "root", "", "online_car_rental");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$search=$_GET['s'];
$query="SELECT * FROM car WHERE date BETWEEN 'pickup_date' AND
'return_date'";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>Id</th>";
echo "<th>Name</th>";
echo "<th>Price(RM)</th>";
echo "<th>Colour</th>";
echo "<th>Mode</th>";
echo "<th>Image</th>";
echo "<th>Status</th>";
echo "<th>Add to Booking</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['car_id'] . "</td>";
echo "<td>" . $row['car_name'] . "</td>";
echo "<td>" . $row['car_price'] . "</td>";
echo "<td>" . $row['car_colour'] . "</td>";
echo "<td>" . $row['car_mode'] . "</td>";
echo "<td><img src='" . $row['car_image'] . "' height='100' width='100'></td>";
echo "<td>" . $row['car_status'] . "</td>";
echo "<td>" . $row['pickup_date'] . "</td>";
echo "<td>" . $row['return_date'] . "</td>";
echo "<td><button onclick=\"booking_car('" . $row['car_id'] .
"')\">Book</button>
</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
</html>
i expect the output is based on pickup_date and return_date.But the output is "ERROR:Could not able to execute".
You Can check with this , When you have two tables you can use inner join query to fetch the data
SELECT columns
FROM table WHERE pickup_date < 'your_pickup_date' AND return_date >= 'your_pickup_date' ORDER
BY car or date;
Without knowing your schema, it's difficult to provide a detailed solution, but an example of a plausible query might be as follows:
"
SELECT c.olumns
, y.ou
, a.ctually
, w.ant
FROM car c
WHERE pickup_date < :return_date
AND return_date >= :pickup_date
ORDER
BY pickup_date
, car_id;
"
Two questions in one:
First question, mainly about presentation:
I'm echo-ing the following code which should create a table. The table should have a single column, but it's being rendered with the elements above the image as a single line. can anyone see why?
<?php
$sql = "SELECT * FROM catdata WHERE featured='yes' LIMIT 2";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['manufacturer'] . "</td>";
echo "</tr";
echo "<tr>";
echo "<td>" . $row['title'] . "</td>";
echo "</tr";
echo "<tr>";
echo "<td><img src=\"6.diesel.png\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['size'] . "l</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['mileage'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['fitsmodel'] . "</td>";
echo "</tr>";
echo "<tr class=\"tablePriceBlock\">";
echo "<td>£" . $row['pricefitted'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>£" . $row['pricedel'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else {
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Unable to execute $sql. " . mysqli_error($link);
}
?>
Question 2:
Can I show the second result in a second column, or as a separate table? Also, is it possible to access the $result elements like say, $[manufacturer][1]?
Always look at the emitted source your code generates by either "View Source" or using a tool like curl. You'll find this mistake:
echo "</tr";
You're missing a >.
Many people who write HTML have browser plugins that can link through to an HTML validator to ensure they've got the correct syntax. You may want to find and install one of these.
To generate the second result is a separate table follow the following code.
echo "<table>";
$count = 1;
while($row = mysqli_fetch_array($result)){
if($count == 2){
echo "<table>";
echo "<tr>";
echo "<td>put your code here</td>";
echo "</tr>"
echo </table>
}else{
echo "<tr>";
echo "<td>" . $row['manufacturer'] . "</td>";
echo "</tr";
echo "<tr>";
echo "<td>" . $row['title'] . "</td>";
echo "</tr";
echo "<tr>";
echo "<td><img src=\"6.diesel.png\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['size'] . "l</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['mileage'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['fitsmodel'] . "</td>";
echo "</tr>";
echo "<tr class=\"tablePriceBlock\">";
echo "<td>£" . $row['pricefitted'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>£" . $row['pricedel'] . "</td>";
echo "</tr>";
}
$count ++;
}
echo "</table>";
As you are limiting your query to only two record so this method is not bad for that and hope this will help.
I can't seem to get this figured out. What am I doing wrong? I have a table in my database and some rows have an empty column for the "company" field.
I'm trying to get the "Users own uploaded files in the html table below. It belongs with "1629"
<?php
// Make a MySQL Connection
mysql_connect("localhost", "", "") or die(mysql_error());
//echo "Connected to MySQL<br />";
mysql_select_db("") or die(mysql_error());
//echo "Connected to Database";
$query = "SELECT company, dmy, COUNT(company) FROM AdTracking WHERE DATE(dmy) = CURRENT_DATE GROUP BY company";
$result = mysql_query($query) or die(mysql_error());
echo "<div style='margin-top:100px;'><center><h2>";
echo date('l jS \ F Y');
echo "<br />";
echo "</h2><center></div>";
echo '
<center> <table class="pure-table pure-table-horizontal">
<thead>
<tr>
<th>Company</th>
<th>Total</th>
</tr>
</thead>
<tbody>
';
// Print out result
while($row = mysql_fetch_array($result)){
if ($row['company'] == NULL) {
echo "Users own uploaded files";
};
echo "<tr>";
echo "<td><strong>" . $row['company'] . "</strong></td>";
echo "<td>" . $row['COUNT(company)'] . "</td>";
echo "</tr>";
}
echo '
</tbody>
</table> </center>
';
?>
You are printing outside of td and tr.
You have maintain format .
Try like this
echo "<tr>";
echo "<td><strong>" .($row['company'] == NULL ? "Users own uploaded files" : $row['company']). "</strong></td>";
echo "<td>" . $row['COUNT(company)'] . "</td>";
echo "</tr>";
you should use mysql_fetch_assoc() instead of mysql_fetch_array()
while($row = mysql_fetch_array($result)){
if (!$row['company']) // it check null or have something value
$value = "Users own uploaded files";
else
$value = $row['company'];
echo "<tr>";
echo "<td><strong>" . $value . "</strong></td>";
echo "<td>" . $row['COUNT(company)'] . "</td>";
echo "</tr>";
}
use mysqli or PDO instead of mysql because "mysql" is deprected.
I tried to use php to create a dropdown list populated by a SELECT query but it would not dropdown. Here is my php script
<?php
require_once ('mysqli_connect.php');
#mysqli_select_db($dbc,"test");
$query = "SELECT category_id, category_name FROM forum_category ORDER BY category_name";
$result = #mysqli_query($dbc, $query);
if(!$result)
{
echo "query error: " . mysqli_error($dbc);
}
// while($row = #mysqli_fetch_array($result))
// {
// echo "<p>$row[0] $row[1]</p>\n"; //this works
// }
echo "<td bgcolor=\"#E6E6E6\"";
echo "<strong>Category:</strong>";
echo "<select name=\"category\">";
while($row = #mysqli_fetch_array($result))
{
// echo "<p><option value='".$row[0]."'>".$row[1]."</option></p>\n";
echo "<option value='".$row[0]."'>".$row[1]."</option>";
}
mysqli_close($dbc);
echo "</select>";
echo "</td>";
?>
The query worked (the commented while loop outside the dropdown list displayed 15 records). But the dropdown list only showed one category_name and would not dropdown. Can someone help me figure out the problem? Thanks.
There are a few problems with your code.
You can either remove both echo "<td bgcolor=\"#E6E6E6\""; and echo "</td>";
which is the reason why your data is not showing.
Or, add the appropriate <table></table> tags.
Plus this echo "<td bgcolor=\"#E6E6E6\""; should be echo "<td bgcolor=\"#E6E6E6\">"; there was a missing > so that alone is breaking your <td>.
So in order to have the proper table syntax do:
Sidenote: I added . "\n" in order to get clean and well-aligned HTML source.
<?php
require_once ('mysqli_connect.php');
#mysqli_select_db($dbc,"test");
$query = "SELECT category_id, category_name FROM forum_category ORDER BY category_name";
$result = #mysqli_query($dbc, $query);
if(!$result)
{
echo "query error: " . mysqli_error($dbc);
}
echo "<table>" . "\n";
echo "<tr>" . "\n";
echo "<td bgcolor=\"#E6E6E6\">" . "\n";
echo "<strong>Category:</strong>" . "\n";
echo "<select name=\"category\">" . "\n";
while($row= mysqli_fetch_array($result)){
echo "<option value='".$row[0]."'>".$row[1]."</option>" . "\n";
}
echo "</select>" . "\n";
echo "</td>" . "\n";
echo "</tr>" . "\n";
echo "</table>" . "\n";
mysqli_close($dbc);
?>
Edit: (Try this) since I don't know what your full code looks like.
<form id="form1" name="form1" method="post" action="form1_handler.php">
<?php
require_once ('mysqli_connect.php');
#mysqli_select_db($dbc,"test");
if(isset($_POST['submit'])){
$query = "SELECT category_id, category_name FROM forum_category ORDER BY category_name";
$result = #mysqli_query($dbc, $query);
if(!$result)
{
echo "query error: " . mysqli_error($dbc);
}
echo "<table>" . "\n";
echo "<tr>" . "\n";
echo "<td bgcolor=\"#E6E6E6\">" . "\n";
echo "<strong>Category:</strong>" . "\n";
echo "<select name=\"category\">" . "\n";
while($row= mysqli_fetch_array($result)){
echo "<option value='".$row[0]."'>".$row[1]."</option>" . "\n";
}
echo "</select>" . "\n";
echo "</td>" . "\n";
echo "</tr>" . "\n";
echo "</table>" . "\n";
mysqli_close($dbc);
} // brace for if(isset($_POST['submit']))
?>
<input type="submit" name="submit" value="Submit">
</form>