I have this code which currently displays the information like this:
<?php
mysql_connect("localhost","example","password") or die("Could not connect to localhost");
mysql_select_db("exampledb") or die( "Could not connect to database");
$result = mysql_query("SELECT * FROM tablexample");
echo "<b>" . "Name" . "</b>" . " " . "<b>" . "Number" . "</b>";
echo "<br/>";
echo "<br/>";
while ($row = mysql_fetch_array($result))
{
echo ucwords($row['name']) . " " . ucwords($row['number']) . "<br>";
echo "<hr width='20%'>";
}
?>
Name Number
B (888) 888-3545
C (098) 545-4354
Cl (888) 888-3545
Da (888) 888-3545
H (888) 888-3545
H (888) 888-3545
Khzdf (888) 888-3545
BUT I want them to align like this (it should override how many letters each name has and have the same space:
Name Number
B (888) 888-3545
C (098) 545-4354
Cl (888) 888-3545
Da (888) 888-3545
H (888) 888-3545
H (888) 888-3545
Khzdf (888) 888-3545
-- Would this be done in CSS or PHP?
Have you considered using a table? Tables are great .... for displaying structured data
<table>
<thead>
<tr>
<th>Column1</th>
<th>column</th>
</tr>
</thead>
<tbody>
<tr>
<td>Column1 data</td><td>column 2 data</td>
</tr>
</tbody>
</table>
The quickest way to solve the problem would be this.
In your code you can change this:
echo ucwords($row['name']) . " " . ucwords($row['number']) . "<br>";
to this:
echo "<span style='display:inline-block; width:200px; text-align:left;'>" . ucwords($row['name']) . "</span><span style='display:inline-block; text-align:left;'>" . ucwords($row['number']) . "</span><br>";
Note: change 200px as needed.
Would this be done in CSS or PHP?
Neither! HTML <table> is what you are looking for.. they are also semantic adequate.
Related
First of all. I apologize for the poor English. I'm also sorry for the novice level of this question.
I would like to put my SQL results in a table, and add a new row for every result.
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "<p><b>".$results['FNAME']."</b> " .$results['LNAME']." ".$results['AGE']."</p>";
}
}
So I would like [FNAME] in a own TD, [LNAME] in it's on TD and the same with [AGE].
Thank you in advance!
Just put <tr> around each row of data, <td> around each column, and put everything inside <table>.
if (mysql_num_rows($raw_results) > 0) {
echo "<table><tr><th>First Name</th><th>LAst Name</th><th>Age</th></tr>";
while ($results = mysql_fetch_assoc($raw_results) {
echo "<tr><td>{$results['FNAME']}</td><td>{$results['LNAME']}</td><td>{$results['AGE']}</td></tr>";
}
echo "</table>";
}
use this code :
<table>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<?php
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "<tr><td>" . $results['FNAME'] . "</td><td>" . $results['LNAME'] . "</td><td>" .$results['AGE']."</td></tr>";
}
}
?>
</tbody>
</table>
I am new to MYSQL and i am trying to export my database to html, and put the data into specific html tables. I have looked around the site, but i cant get my code to work, can someone help me, and tell me if this code looks right ?
<?php
$con=mysqli_connect("xxx","xxx","xxx","xxx","xxx");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM xxx");
while($row = mysqli_fetch_array($result))
{
<tr>
<th bgcolor="#3281c6">" . $row["PO_nummer"]. "</th>
<th bgcolor="#3281c6">" . $row["Varenummer"]. "</th>
<th bgcolor="#3281c6">" . $row["Produkt_beskrivelse_"]. "</th>
<th bgcolor="#3281c6">" . $row["Antal"]. "</th>
}
mysqli_close($con);
?>
You seem to be expecting an associative array and not a regular (numbered) array, in this case try:
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
{
// code
}
Try and echo or print the html
echo "
<th bgcolor="#3281c6">" . $row["PO_nummer"]. " </th>
<th bgcolor="#3281c6">" . $row["Varenummer"]. "</th>
<th bgcolor="#3281c6">" . $row["Produkt_beskrivelse_"]. "</th>
<th bgcolor="#3281c6">" . $row["Antal"]. "</th>";
And use single quotes here bgcolor='#3281c6'
I am trying to do a query and update that query on a same page by using form but the problem is I have to submit form twice to get it updated. This code is ported from my last mysql project. My last project was search then query then update. This one is query then update. I can't see why form doesn't get variable to it on first click. Still learning PDO. Please point me to a right direction. Thank you.
require_once ('control/control.php');
$db = db_connect ();
$stmt = $db->query("SELECT * FROM offsite_inventory WHERE category != '' ORDER BY FIELD(category,'Sparkling Wine','Rose Wine','Riesling Magnum 1.5L','Riesling Magnum 3L','Austrian Riesling','Austrian Gruner','Trocken','Kabinett','Spatlese','Auslese','Chardonnay USA','Chardonnay France','Chablis','White Wine 1','White Wine 2','Pinot Noir 2','Pinot Noir 1','Cabernet And Bordeau','Red Wine 1','Red Wine 2','Red Wine 3','Red Wine 4','Rhone Valley Red')");
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<tr><td width=\”50\">" . $row['code'] . "</td>
<td width=\"380\">" . $row['name'] . "</td>
<td width=\"50\" align=\"center\">" . $row['instock_resto'] . "</td>
<td width=\"50\" align=\"center\">" . $row['instock_home'] . "</td>
<td width=\"100\"><form style='display:inline!important; width:10px!important;' name='inventory' method='post' action='" . $PHP_SELF . "?id=" . $row['id'] . "&instock_home=" . $row['instock_home'] . "&name=" . $row['name'] . "'>
<table width='1' border='0' align='center' style='margin-right:auto; margin-left:auto;'>
<tr>
<td valign='middle'>
<label><input style='display:inline!important; width:25px!important;' type='number' name='instock_home'/></label></td>
<td>
<input style='display:inline!important; width:100px!important; padding:3px 0px;' type='submit' name='instock_home2' value='update stock' /></td></tr></table>
</form>";
echo "</td></tr>";
}
require_once ('control/control.php');
$conn = db_connect ();
$instock_home = $_POST['instock_home'];
$id = $_GET['id'];
$name = $_GET['name'];
$stmt2= $conn->prepare("UPDATE offsite_inventory SET instock_home = ? WHERE id = ?");
$stmt2->execute(array($instock_home, $id));
echo"</table>";
I have a problem regarding the width in a bootstrap table, it goes way to the side of the website, screenshot under
http://i.stack.imgur.com/FLZwD.png
EDIT:
<div class="container">
<h1>URL Stats <small>Shortened URL's with their full stats.</small></h1>
<table class="table table-striped table-bordered" id="statstable">
<thead>
<tr>
<th>URL ID</th><th>URL Unique ID</th><th>Short Link</th><th>Redirect Link</th><th>Date Created</th><th>End Date</th><th>Days Left</th>
</tr>
</thead>
<hr>
<tbody>
<?php
$result = mysql_query("SELECT * FROM links WHERE shortlinkid='$shortlinkid'") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$now = date("Y-m-d");
$start = $row['date_created'];
$end = $row['end_date'];
$diff = (strtotime($end) - strtotime($now))/24/3600;
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['shortlinkid']."</td>";
echo "<td><a href='http://".$row['fullurl']."'>".$row['fullurl']."</a></td>";
echo "<td><a href='".$row['redirect']."'>".$row['redirect']."</a></td>";
echo "<td>".$row['date_created']."</td>";
echo "<td>".$row['end_date']."</td>";
echo "<td>".$diff."</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
This has not been an issue before, and it works fine in other browsers other than Chrome
Change this:
echo "<td><a href='http://".$row['fullurl']."'>".$row['fullurl']."</a></td>";
echo "<td><a href='".$row['redirect']."'>".$row['redirect']."</a></td>";
To this:
echo "<td><a href='http://".$row['fullurl']."'>Full URL</a></td>";
echo "<td><a href='".$row['redirect']."'>Redirect</a></td>";
Instead of echoing the entire URL for the link label, use some descriptive text to click on. Change labels as needed.
i have a code...server side and cant seem to make it load wherein HEADER would be vertical, i have tried the code below,
<?php
require 'include/DB_Open.php';
$ea_name = $_POST['ea_name'];
$sql="SELECT * FROM ea_error WHERE ea_name = '" . $ea_name . "'";
$myData = mysql_query($sql) or die(mysql_error());
//to count if there are any results
$numrow = mysql_num_rows($myData) ;
if($numrow == 0)
{
echo "No results found.";
}
else
{
echo '<fieldset><legend><strong>Information</strong></legend>
<table width="auto" border="0" align="center">
<tr><th scope="row">Error</th></tr>
<tr><th scope="row">Resolution</th></tr>
<tr><th scope="row">Contact/s</th></tr>';
while($info = mysql_fetch_array($myData))
{
echo "<form action='retrieve.php' method='post'>";
echo "<td align='center'>" . "<textarea readonly=readonly name=error cols=75 rows=8> " . $info['error'] . "</textarea></td>";
echo "<td align='center'>" . "<textarea readonly=readonly name=resolution cols=75 rows=8> " . $info['resolution'] . "</textarea></td>";
echo "<td align='center'>" . "<textarea readonly=readonly name=contacts cols=75 rows=8> " . $info['contacts'] . "</textarea></td>";
echo "</form>";
echo "</table>";
}
}
echo "</fieldset>";
include 'include/DB_Close.php';
?>
whats showing with this code is like below
Error
Resolution
Contact/s
then i would have the three text areas here on a single row
what i want to happen is
Error - TEXTAREA
Resolution - TEXTAREA
Contact/s - TEXTAREA
pls help...i also tried using a css style to no avail
table, td, th {
border: 1px solid red;
}
thead {
float: left;
}
ive also tried to use the code below,
echo "<form action='retrieve.php' method='post'>";
echo "<tr>";
echo "<td align='center'>" . "<textarea readonly=readonly name=error cols=75 rows=8> " . $info['error'] . "</textarea></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'>" . "<textarea readonly=readonly name=resolution cols=75 rows=8> " . $info['resolution'] . "</textarea></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'>" . "<textarea readonly=readonly name=contacts cols=75 rows=8> " . $info['contacts'] . "</textarea></td>";
echo "</tr>";
but what i am getting is
Error
Resolution
Contact/s
TEXTAREA
TEXTAREA
TEXTAREA
If I understood the question correctly, this could be an answer (although I would TOTALLY avoid using tables for layout design and not just tabular data):
$myRes = "<form action='retrieve.php' method='post'>
<fieldset>
<legend><strong>Information</strong></legend>
<table width='auto' border='0' align='center'>
<tr>
<th scope='row'>Error</th>
<td align='center'><textarea readonly=readonly name=error cols=75 rows=8>" . $info['error'] . "</textarea></td>
</tr>
<tr>
<th scope='row'>Resolution</th>
<td align='center'><textarea readonly=readonly name=resolution cols=75 rows=8>" . $info['resolution'] . "</textarea></td>
</tr>
<tr>
<th scope='row'>Contact/s</th>
<td align='center'><textarea readonly=readonly name=contacts cols=75 rows=8>" . $info['contacts'] . "</textarea></td>
</tr>
</table>
</fieldset>
</form>";
echo $myRes;