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);
?>
Related
I am new to HTML CSS, I have tried many time but fail. Please help.
I want to create table like this:
I have inserted relevant data in mysql but i am unable to show data in given format/table.
<tbody>
<?php
foreach($record as $row)
{
$pre_stop = $row['pre_stop'];
$current_stop_id = $row['current_stop'];
$cur_stop_name=mysql_query("SELECT stop_name_urd FROM stop WHERE stop_id = '$current_stop_id'");
while($cur_stop=mysql_fetch_array($cur_stop_name))
{
$stop_name=$cur_stop[0];
}
$inter_distance = $row['inter_distance'];
$total_distance += $row['inter_distance'];
echo "<tr>";
echo "<td class='border' style='text-align:center;'>" . $inter_distance . "</td>";
echo "<td class='border' style='text-align:center;'>" . $stop_name . "</td>";
echo "<td class='border' style='text-align:center;'>".$total_distance."</td>";
for ($i=0; $i < 1; $i++) {
echo "<td rowspan='".$count."' class='noBorder' style='text-align:center;'>" . "" . "</td>";
echo "<td class='noBorder'>" . $stop_name . "</td>";
}
}
//echo "<td class='noBorder' style='text-align:center;'>" . $stop_name . "</td>";
//echo "<td></td>";
?>
</tr>
</tbody>
If you're new to coding HTML, then I recommend you try to manually create a smaller version of your table (say 3 rows) so that you know how the resulting HTML code is supposed to look and that you're fetching the SQL data correctly. Then you can transfer that knowledge into PHP code.
Do watch out for your loop, though:
for ($i=0; $i < 1; $i++) {
echo "<td rowspan='".$count."' class='noBorder' style='text-align:center;'>" . "" . "</td>";
echo "<td class='noBorder'>" . $stop_name . "</td>";
}
This will only loop once, which seems to defeat your purpose, as your logical check is odd. Your for loop reads:
$i=0 - Make a variable named i
$i < 1 - Stop if i ever becomes
greater than or equal to 1
$i++ - Add 1 to the value of i
This means that it will go through the loop one time only and then break out of the loop.
I don't see from your code example how you're getting your data but I imagine you'd want something like this:
for ($i=0; $i < $resultCount; $i++) {
echo "<td rowspan='".$count."' class='noBorder' style='text-align:center;'>" . "" . "</td>";
echo "<td class='noBorder'>" . $stop_name . "</td>";
}
Where $resultCount is equal to the number of rows returned by your SQL query.
It looks like you reversed the order of the columns when echo-ing out your html. Also, it would be easier to use colspan vs rowspan in this approach. Not knowing the initial value of count, we shall assume the header is 0 and all other rows are 1 through m (where m is the number of rows since we read a matrix as m x n (rows x columns)).
In conclusion, try this:
$count = 0;
$total_distance = 0;
// the header row
echo "<tr>" . PHP_EOL;
// Apply the space on the left
echo "\t<th colspan='" . (count($record) - $count) . "' class='noBorder' style='text-align:right;'></th>" . PHP_EOL;
// Provide headers on the last three columns
echo "\t<th class='border' style='text-align:center;'>Total Distance</th>" . PHP_EOL;
echo "\t<th class='border' style='text-align:center;'>Stop Name</th>" . PHP_EOL;
echo "\t<th class='border' style='text-align:center;'>Inter-Distance</th>" . PHP_EOL;
echo "</tr>" . PHP_EOL;
foreach($record as $row)
{
// get the values
$pre_stop = $row['pre_stop'];
$current_stop_id = $row['current_stop'];
$inter_distance = $row['inter_distance'];
$total_distance += $inter_distance;
// Assume the last stop in the results has the desired stop name
$cur_stop_name=mysql_query("SELECT stop_name_urd FROM stop WHERE stop_id = '$current_stop_id'");
while($cur_stop=mysql_fetch_array($cur_stop_name))
{
$stop_name = $cur_stop[0];
}
// Start the row
echo "<tr>" . PHP_EOL;
// Apply the space on the left
echo "\t<td colspan='" . (count($record) - $count) . "' class='noBorder' style='text-align:right;'>" . $stop_name . "</td>" . PHP_EOL;
// Apply the last three columns
echo "\t<td class='border' style='text-align:center;'>".$total_distance."</td>" . PHP_EOL;
echo "\t<td class='border' style='text-align:center;'>" . $stop_name . "</td>" . PHP_EOL;
echo "\t<td class='border' style='text-align:center;'>" . $inter_distance . "</td>" . PHP_EOL;
// End the row
echo "</tr>" . PHP_EOL;
// increment the count
$count++;
}
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,
]);
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
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"
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.