Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
I'm trying to generate HTML- table using following code:
<?php
$stid = oci_parse($conn, "select distinct concat(concat(order_no, '_'), sequence_no) from database
where order_no LIKE 'M114244' and release_no = '1'");
oci_execute($stid);
$stid2 = oci_parse($conn, "select oper_status_code from database
where order_no LIKE 'M114244' and release_no = '1' and operation_no = '22'");
oci_execute($stid2);
?>
<table style=" width: 60%; text-align: left; position: absolute; top:220px; left:440px; font-size: 10px;">
<tbody>
<tr>
<th>ORDER</th></td><th>STAGE</th></td>
</td>
<?php
while (($row = oci_fetch_array($stid, OCI_BOTH))) {
foreach ($row as $item) {
echo '</tr><td>'.($row[0]).'</td>';
}}
while (($row = oci_fetch_array($stid2, OCI_BOTH))) {
foreach ($row as $item) {
echo '</td><td>'.($row[0]).'</td>';
}}
?>
</tbody>
</table>
For some reason I will get duplicate M-numbers, which I should't get but this is not the main question this time. Maybe I will later on find out the reason for this. Please don't mind that Finnish language inside the table. I would like to echo this table with following structure:
That way the state of different stages could be seen from table.
Get the picture from the problem?
Appreciated from all possible help and tips.
<?php
$stid = oci_parse($conn, "select distinct concat(concat(order_no, '_'), sequence_no) from database
where order_no LIKE 'M114244' and release_no = '1'");
oci_execute($stid);
$stid2 = oci_parse($conn, "select oper_status_code from database
where order_no LIKE 'M114244' and release_no = '1' and operation_no = '22'");
oci_execute($stid2);
?>
<table style=" width: 60%; text-align: left; position: absolute; top:220px; left:440px; font-size: 10px;">
<tbody>
<tr>
<th>ORDER</th></td><th>STAGE</th>
</tr>
<?php $orders= [];
while (($row = oci_fetch_array($stid, OCI_BOTH))) {
foreach ($row as $item) {
$orders[] = ($row[0]);
}
}
$i = 0;
while (($row = oci_fetch_array($stid2, OCI_BOTH))) {
echo '<tr><td>'.$orders[$i].'</td>';
foreach ($row as $item) {
echo '<td>'.($row[0]).'</td>';
}
echo '</tr>';
$i++;
}
?>
</tbody>
</table>
Related
I am using MPDF Library to generate pdf file form database .
i want to show whatsapp number from database in html table TD using array with for loop in MPDF.
here is my code which i try but it cannot print any value .
please help me out to figure out the problem and able to show records using for loop
$query = "SELECT * from social_messaging_app where User_Id = '$split_ids[0]' and Request_Id='$split_ids[1]' and Social_Messaging_App_Name LIKE 'Wh%' ORDER BY Social_Messaging_App_Id DESC";
$res_cus = mysqli_query($connection, $query);
$total_rec_whatsaap = mysqli_num_rows($res_cus);
$whatsapp_accounts = array();
$whatsapp_id = 1;
while ($row = mysqli_fetch_array($res_cus)) {
$whatsapp_accounts[$whatsapp_id] = $row['Social_Messaging_App_No'];
$whatsapp_id++;
}
$html="";
if($total_rec_whatsaap>0){
$html .= '
<table style="width: 100%">
<tbody>
<tr>
<td style="width: 5%;font-size:14px;"></td>
<td style="width: 25%;font-size:14px;">Whatsapp Address(es)</td>
<td style="width: 70%; border-bottom: 1px solid black;text-align: left;font-size:14px;">';
for($i = 1; $i <= $total_rec_whatsaap; $i++)
{
strtoupper($whatsapp_accounts[$i]);
}
$html .= '
</td>
</tr>
</tbody>
</table> ';
}
Please assist me to print values in td. using below code it give me empty row.
You have missed concatenating the string in for loop
for ($i = 1; $i <= $total_rec_whatsaap; $i++)
{
$html .= strtoupper($whatsapp_accounts[$i]);
}
I have a problem. I have two tables in my database which I want to write as an output (their names) but it always writes only the first one in the database. Can anybody fix my code and explain why that fix is necessary?
$result = mysqli_query($conn, "SHOW TABLES");
while($tableName = mysqli_fetch_array($result))
{
$table = $tableName[0];
$result2 = mysqli_query($conn, "SELECT * FROM `".$table."`");
$query = "SELECT COUNT(*) FROM `".$table."`";
$result = mysqli_query($conn, $query);
$rows = mysqli_fetch_row($result);
$querys = "SELECT * FROM `".$table."` ORDER BY id DESC LIMIT 1";
$resulty = mysqli_query($conn, $querys);
$rowsy = mysqli_fetch_row($resulty);
while($row2 = mysqli_fetch_assoc($result2))
{
$p = $row2['authoroftopic'];
$s = $rows[0];
$l = $rowsy[1];
echo "<div class='discussionTable'>
<div class='dcolumn' style='width: 60%; position: absolute; padding-left: 10px;'>
<b><h3 style='padding: 15px;'><a href='discussion_gaming.php' style='color: white'>$table</a></b><br><p style='font-size: 13px'>Author: $p</p></h3>
</div>
<div style='padding-top: 10px;'>
<div class='dcolumn' style='width: 30%; float: right;'>
<p style='padding: 15px; line-height: 0px'>Total comments: $s</p>
<p style='padding-left: 15px; padding-top: 0px; line-height: 0px'>Last comment by: $l</p>
</div>
</div>
</div>";
}
}
You use the variable $result for two result sets at the same time - the first to hold the list of available tables, and the second one to gather data from a single table. You should rename one of the two occurences to not override the outer result within the loop
I have this structure on my page:
*{
margin: 0px;
}
.div1{
width: 1000px;
background-color: grey;
overflow: hidden;
}
.div2{
width: 300px;
background-color: orange;
height: 500px
}
.div3{
width: 300px;
background-color: orange;
height: 500px;
}
.float_left{
float: left;
}
.float_right{
float: right;
}
<div class="div1">
<div class="div2 float_left">
</div>
<div class="div3 float_right">
</div>
</div>
And inside the two orange container's I want to put some smaller divs, but I read the data from a database. The first row should be in div1, the second in div2, the third in div1 and so on.
$sql = "SELECT * FROM question ORDER BY question_id DESC";
$result = mysqli_query($db,$sql);
while($row = mysqli_fetch_assoc($result)){
}
But how can I do something like that? Can I open a div container closed container to place a div container inside the container?
You should really read and try by yourself, this is pretty basic question.
There are many ways, here is one of them.
Declare 2 variables to store the results for Div1 and Div2.
Declare a count variable and use the odd and even property to decide who turn is it to store the results.
Output the results.
PHP:
$sql = "SELECT * FROM question ORDER BY question_id DESC";
$result = mysqli_query($db,$sql);
$resultsForDiv1 = "";
$resultsForDiv2 = "";
$count = 0;
while($row = mysqli_fetch_assoc($result)){
if ($count%2 == 0) {
$resultsForDiv1 .= $row[0]; // You should change it to whatever data you need from $row.
}
else {
$resultsForDiv2 .= $row[0]; // You should change it to whatever data you need from $row.
}
$count++;
}
Html:
<div class="div1">
<div class="div2 float_left">
<?php echo $resultsForDiv1; ?>
</div>
<div class="div3 float_right">
<?php echo $resultsForDiv2; ?>
</div>
</div>
What you should do is store the data from the $row variable into new variables which you can then output in the two columns. Like this:
<?php
$sql = "SELECT * FROM question ORDER BY question_id DESC";
$result = mysqli_query($db, $sql);
// Use this to toggle column on the sql results
$left_right = true;
while ($row = mysqli_fetch_assoc($result)) {
if ($left_right) {
// Add to left column variable
// [some code to add the data from $row to $left_column_content]
} else {
// Add to right column variable
// [some code to add the data from $row to $right_column_content]
}
// Switch columns by inverting the boolean from true to false, false to true
$left_right = !$left_right;
}
?>
<div class="div1">
<div class="div2 float_left">
<?php echo $left_column_content; ?>
</div>
<div class="div3 float_right">
<?php echo right_column_content; ?>
</div>
</div>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
<td>
<p>
<div class="column">
<p><b>SELECT A DATABASE</b></p>
<p> <?php echo$this->form->getInput('Database_1');
include "db1.js.php" ?>
</div>
</td>
<td>
<p>
<div class="column" id="tbDiv">
<p><b>TABLES</b></p>
<select name="List of Tables" size="25" multiple id='table1' name='table1' title='List of Tables' class='inputbox'>
<option >Tables will be listed here...</option></select>
</div><p>
</td>
This the code in displaying the tables in a list from a selected database. I want to display the attributes of the table when i click it.
Try this using ajax and php
<?php
$db = new PDO('mysql:host=localhost;dbname=mysql','root','');
$dbs = $db->query( 'SHOW DATABASES' );
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
li:hover{
cursor: pointer;
}
#list{
float: left;
width: 30%;
}
#table{
float: right;
width: 68%;
}
#main{
width: 70%;
margin: 0 auto;
}
table,th,td{
border: 1px solid #000;
}
th{
width: 120px;
background-color: #000;
color: #fff;
text-transform: capitalize;
}
table {
border-collapse: collapse;
}
</style>
</head>
<body>
<div id="main">
<div id="list">
<select id="dbase" onchange="getTables(this.value)">
<option>Select databse</option>
<?php
while( ( $db = $dbs->fetchColumn( 0 ) ) !== false )
{
echo '<option>',$db,'</option>';
}
?>
</select>
<!-- displaying dropdown ************* -->
<option id="bulk" onchange="drop(this.value)"></option>
</div>
<div id="table"></div>
</div>
<script type="text/javascript">
//*************update for displaying dropdown menu *******
function drop(table){
var table = table;
var db = dbase.value;
var data = new XMLHttpRequest();
data.open("POST","list.php");
data.onreadystatechange = function(){
if(data.readyState === 4 && data.status === 200){
document.getElementById('table').innerHTML = data.responseText;
}
}
data.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
data.send('table='+table+'&dbase='+db);
}
//***********end of update **********
function getTables(table){
var data = new XMLHttpRequest();
data.open("POST","get_tables.php");
data.onreadystatechange = function(){
if(data.readyState === 4 && data.status === 200){
document.getElementById('bulk').innerHTML = data.responseText;
}
}
data.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
data.send('table='+table);
}
</script>
</body>
</html>
create get_tables.php
<?php
$dbname = $_POST['table'];
$db = new PDO("mysql:host=localhost;dbname=$dbname","root","");
$query = $db->prepare('show tables');
$query->execute();
$tabe_in = 'Tables_in_'.$dbname;
$results = $query->fetch(PDO::FETCH_ASSOC);
while ($results != null) {
// change <li> to <option> here **********
echo '<option>',$results[$tabe_in],'</option>';
$results = $query->fetch(PDO::FETCH_ASSOC);
}
?>
and res.php
<?php
$table = $_POST['table'];
$dbname = $_POST['dbase'];
$sql = "SHOW COLUMNS FROM $table";
$db = new PDO("mysql:host=localhost;dbname=$dbname","root","");
$table_headers = array();
$results = $db->prepare($sql);
$results->execute();
$res = $results->fetch();
?>
<table>
<tr>
<?php
while ($res != null) {
echo '<th>',$res['Field'],'</th>';
$table_headers[] = $res['Field'];
$res = $results->fetch();
}
?>
</tr>
<?php
$query = $db->prepare("SELECT * FROM $table");
$query->execute();
$rs = $query->fetchAll();
foreach ($rs as $value) {
echo '<tr>';
foreach ($table_headers as $val) {
echo '<td>',$value[$val],'</td>';
}
echo '</tr>';
}
?>
I'm getting a table appearing after the first result of the nested while loop.
What I'm trying to do is display the usernames as a list by selecting from the "users" table, then comparing that list with the project engineers from the "current projects" table.
This way there is a list of project engineers with their assigned projects underneath their names.
Unfortunately, I'm after the first nested while loop runs, it spits out a empty table and I'm not sure how to get rid of it.
I'm suspecting it has to do with the initial variable of $proj_engineer = "";
Does anyone know where this empty table is coming from and how to get rid of it?
Below is the code:
<?php
$query = mysql_query("SELECT * FROM `users` ORDER BY `username` ASC") or die(mysql_error());
while ($row = mysql_fetch_assoc($query)) {
$user_id = $row['user_id'];
$username = $row['username'];
$proj_engineer = "";
$query1 = mysql_query("SELECT * FROM `current_projects` WHERE `proj_engineer`='$username' ORDER BY `proj_engineer` ASC") or die(mysql_error());
while ($row1 = mysql_fetch_assoc($query1)) {
$proj_id = $row1['proj_id'];
$proj_engineer = $row1['proj_engineer'];
}
echo "<table border=1><tr><td colspan=12><p class='bold18'>" . $proj_engineer . "</p></td></tr>";
$query3 = mysql_query("SELECT * FROM `current_projects` WHERE `proj_engineer`='$username' ORDER BY `proj_id` DESC") or die(mysql_error());
while ($row3 = mysql_fetch_assoc($query3)) {
$proj_id = $row3['proj_id'];
$proj_number = $row3['proj_number'];
$proj_name = $row3['proj_name'];
$proj_sort = $row3['proj_sort'];
$proj_start = $row3['proj_start'];
$proj_finish = $row3['proj_finish'];
$proj_overstat = $row3['proj_overstat'];
$proj_dwgstat = $row3['proj_dwgstat'];
$proj_soostat = $row3['proj_soostat'];
$proj_substat = $row3['proj_substat'];
$proj_engineer = $row3['proj_engineer'];
$proj_drafter = $row3['proj_drafter'];
$proj_rating = $row3['proj_rating'];
$proj_pending = $row3['proj_pending'];
$proj_notes = $row3['proj_notes'];
$start_time = date("m/d/y", $proj_start);
$finish_time = date("m/d/y", $proj_finish);
echo "
<tr>
<td width=40>$proj_number</td>
<td width=100>$proj_engineer</td>
<td width=100><a href='./project-page.php?proj_id=$proj_id'>$proj_name</a></td>
<td width=40>$start_time</td>
<td width=40>$finish_time</td>
<td width=110>
<div style='position:relative; background:url(images/bar01.gif); width:$proj_overstat; height:20;'>
<div style='position:absolute; bottom:0; left:0; width:$proj_overstat; font-weight:bold; color:#000000; vertical-align:middle; height:20; text-align:center;'>$proj_overstat%</div>
</div>
</td>
<td width=110>
<div style='position:relative; background:url(images/bar02.gif); width:$proj_dwgstat; height:20;'>
<div style='position:absolute; bottom:0; left:0; width:$proj_dwgstat; font-weight:bold; color:#000000; vertical-align:middle; height:20; text-align:center;'>$proj_dwgstat%</div>
</div>
</td>
<td width=110>
<div style='position:relative; background:url(images/bar03.gif); width:$proj_soostat; height:20;'>
<div style='position:absolute; bottom:0; left:0; width:$proj_soostat; font-weight:bold; color:#000000; vertical-align:middle; height:20; text-align:center;'>$proj_soostat%</div>
</div>
</td>
<td width=110>
<div style='position:relative; background:url(images/bar04.gif); width:$proj_substat; height:20;'>
<div style='position:absolute; bottom:0; left:0; width:$proj_substat; font-weight:bold; color:#000000; vertical-align:middle; height:20; text-align:center;'>$proj_substat%</div>
</div>
</td>
<td width=40 align='center'><a href='project-notes.php?proj_id=$proj_id'><img src='images/note.png' border=0></a></td>
<td width=40 align='center'><a href='./project-edit.php?proj_id=$proj_id'>EDIT</a></td>
<td width=40 align='center'><a href='./project-delete.php?proj_id=$proj_id'>DELETE</a></td>
</tr>
";
}
echo "</table><br>";
}
?>
This might be because, your query: -
$query1 = mysql_query("SELECT * FROM `current_projects` WHERE
`proj_engineer`='$username' ORDER BY `proj_engineer` ASC")
or die(mysql_error());
fetched you an empty value for $proj_engineer. You can do a check before printing your table, whether your variable contains a value instead. Try printing the $proj_engineer before printing the table.
You can enclose your code echoing the table inside an if construct, which will print table only when your value is not empty.