retrieve two database table values in a single html table - html

I have a table(webmeasurementsuite) in my database(probe_config).I have written an php coding to retrieve the datas from the database and display it in the html table.Can anyone correct my errors please.when I load the php page to the browser,I am getting a blank page.
<?php
$con = mysql_connect("localhost","root","mysql");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM webmeasurementsuite");
echo "<table border='1'>
<tr>
<th>replication</th>
<th>wait</th>
<th>timeout</th>
<th>clearcache</th>
<th>name</th>
<th>wms</th>
</tr>;
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['replication'] . "</td>";
echo "<td>" . $row['wait'] . "</td>";
echo "<td>" . $row['timeout'] . "</td>";
echo "<td>" . $row['clearcache'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['wms'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>

I think you need to learn more about Web Development.
HTML is used only for rendering the information in an appropriate format. For accessing the database records, we got to use server side Scripting Languages or Web Technologies(J2EE, JSP, ASP, and more) to access the database. That one can not be done with HTML alone.
If am wrong, please brief your question bit more.

Related

Yii2.0 export function using kartik-v

I am new in using kartik. Can I just check with you whether kartik is able to do below things? And how to do it?
Display date in different format than in db. i.e. in db it is displayed as YYYY-MM-DD"T"HH:MM:SS" whereas on screen, I want to display it as YYYY-MM-DD.
Show subtotal and total?
Since in my report screen, im using a normal html to display data since from my understanding, the gridview does not have the subtotal function.
Below is my html:
$reports = $dataProvider->getModels();
$i=1;
echo "<table class='table table-striped table-bordered'>";
echo "<tr><th>#</th><th>Item</th><th>Total Summary Usage Qty</th><th>Current Stock On Hand</th><th>Measurement</th></tr>";
foreach ($reports as $report) {
$item_key = $report['report_item_key'];
$item_model = Item::find()->where(['item_key' =>$item_key])->one();
$item_e_desc_tx = $item_model->desc_e_tx;
$item_c_desc_tx = $item_model->desc_c_tx;
$item_qty_no = $item_model->qty_no;
$item_measurement_tx = $item_model->measurement;
echo "<tr>";
echo "<td>" . $i++ . "</td>";
echo "<td>" . Html::a($item_key, array('stockmovementreportdetailbyitem', 'item_key' => $item_key, 'search' => 'true', 'stockmovement_summary_from_sales_date' => $stockmovement_summary_from_sales_date, 'stockmovement_summary_to_sales_date'=>$stockmovement_summary_to_sales_date)) . "<br>" . $item_e_desc_tx . "<br>" . $item_c_desc_tx ."</td>";
echo "<td>" . $report['total_summary_usage_qty'] . "</td>";
echo "<td>" . $item_qty_no . "</td>";
echo "<td>" . $item_measurement_tx . "</td>";
echo "</tr>";
}
echo "</table>";
echo \yii\widgets\LinkPager::widget([
'pagination'=>$dataProvider->pagination,
]);

Having trouble using result of mysql Min() in php

$minTime = "Select MIN(categoryTime) FROM List WHERE personStatus='Atendiendo' AND depName='Admisiones'";
$Time = mysqli_query($con,$minTime);
echo "<table>
<tr>
<th>Main Record</th>
<th>Tiempo Categoria</th>
<th>Tiempo Estimando</th>
<th>Time IN </th>
</tr>";
while($min = mysqli_fetch_array($Time))
{
echo "<tr>";
echo "<td>" . $min['categoryTime'] . "</td>";
echo "<td>" . $min['categoryTime'] . "</td>";
echo "<td>" . $min['categoryTime'] . "</td>";
echo "<td>" . $min['categoryTime'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
If I delete the MIN() function the query works perfectly...
The query work if I delete the Min() fuction. I tried Least() with no success.
Several issues here.
I think the snippet is missing:
$Time =mysqli_query($con,$minTime);
where $con is the connection.
When you add the MIN function around the categoryTime field, the label of the column in the resultset changes, so the reference to $min['categoryTime'] no longer returns anything. Try changing query to
SELECT MIN(categoryTime) as minCat ...
then change the php array column reference to $min['minCat']
HTH

how to display images whose names are stored in database

I had created a table in mysql database. I am using php One column was for images, but it only stored images name. I wanted to print the whole table so did the coding but got got only the name of the images in the table.
Please explain how can I display images on the webpage that are stored in my PC. I don't want to save images in the database.
I used this code to print the table :
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$query="SELECT * FROM images LIMIT 0,5";
$result = #mysql_query($query);
echo "<table border='1'>
<tr>
<th>S.No.</th>
<th>Image</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['image_id'] . "</td>";
echo "<td>" . $row['filename'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Hope you got some answer....
All your code is doing is sending the filename to the screen as a string. You need to the use image tags.
You may find this page useful, http://www.htmlcodetutorial.com/images/_IMG.html

Present data from a MySQL view into HTML using PHP [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am trying to simply show a view in MySQL using PHP but I keep getting and error. Any advice on what the T_STRING error might be? Thanks.
Parse error: syntax error, unexpected T_STRING in
/home/theaudit/public_html/_sandbox/index.php on line 14
<?php
// connection parameters
$db_host="a";
$username="b";
$password="c";
$db_name="d";
// connection variables
$db_con=mysql_connect($db_host,$username,$password);
$connection_string=mysql_select_db($db_name);
// page variables
$query = SELECT * FROM a_aif_remaining;
$result = mysql_query($query);
// connection to mysql and db
mysql_connect($db_con) or die("Unable to connect to MySQL");
mysql_select_db($db_name) or die("Unable to select database");
// successful result
echo "<table border=1>
<tr>
<th>aif</th>
<th>fee_source</th>
<th>company_screename</th>
<th>filing_date</th>
<th>document_subtype</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['aif_id'] . "</td>";
echo "<td>" . $row['fee_source_id'] . "</td>";
echo "<td>" . $row['company_name_per_sedar'] . "</td>";
echo "<td>" . $row['document_filing_date'] . "</td>";
echo "<td>" . $row['document_subtype'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
$query = SELECT * FROM a_aif_remaining;
needs to be:
$query = "SELECT * FROM a_aif_remaining";
Get yourself a better editor and you can fix and improve your code in no time:
<?php
// connection parameters
$db_host = "a";
$username = "b";
$password = "c";
$db_name = "d";
// connection variables + connection to mysql and db
$db_con = mysql_connect($db_host, $username, $password);
$result = mysql_select_db($db_name, $db_con);
// page variables
$query = 'SELECT * FROM a_aif_remaining';
$result = mysql_query($query, $db_con);
// successful result
echo '<table border=1>
<tr>
<th>aif</th>
<th>fee_source</th>
<th>company_screename</th>
<th>filing_date</th>
<th>document_subtype</th>
</tr>';
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['aif_id'] . "</td>";
echo "<td>" . $row['fee_source_id'] . "</td>";
echo "<td>" . $row['company_name_per_sedar'] . "</td>";
echo "<td>" . $row['document_filing_date'] . "</td>";
echo "<td>" . $row['document_subtype'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($db_con);
?>

How to: Format a MySQL query result with currency signs using PHP

I have a MySQL query that fetches a numeric value VARCHAR (20) from a table, and I need to format the result to include thousands separators (,) and decimal separators (.) to two positions.
I've searched a lot for a simple query, so now I want to know if this is possible using CSS.
Here is the table data:
Income
-------------------
1234456789
234456000
987456000
And so on. Here's the query:
// Fetch data
$sql="SELECT * FROM scoreboard WHERE codcliente = '".$q."' OR nombre LIKE '%".$q."%'";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 0){
echo '<div align="center" style="background-color:#CCCCCC; font-weight:bold; color:#C0504D;">Record no existe. <input id="srchcreate" type="button" value="Crear" /></div>';
return;
}
//echo $result;
And the result:
// Construct the table
echo "<table>";
// Construct the array
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['codcliente'] . "</td>";
echo "<td>" . $row['nombre'] . "</td>";
// echo "<td>" . $row['ejecutivo'] . "</td>";
// echo "<td>" . $row['banca_as400'] . "</td>";
// echo "<td>" . $row['banca_real'] . "</td>";
// echo "<td>" . $row['ingresos'] . "</td>";
echo "<td>" . $row['ciiu'] . "</td>";
// echo "<td>" . $row['division'] . "</td>";
echo "<td>" . $row['actividad'] . "</td>";
echo "<td>" . $row['riesgo_industria'] . "</td>";
echo "<td>" . $row['riesgo_cliente'] . "</td>";
echo "<td>" . $row['fecha'] . "</td>";
echo "<td>" . $row['analista'] . "</td>";
echo "</tr>";
}
echo "</table>";
This gets inserted to a PHP file and displayed as a table.
No, CSS isn't designed to do that.
JavaScript does have that capability.
<?php
echo number_format(123456789, 2);
?>
123,456,789.00
echo "<td>".number_format($row['ingresos'], 2)."</td>\n"