Maybe someone can help me out. Any help is appreciated! I'm trying to Combine the "???" row with "unknown files" row. So the total would be 4245. Just one row.
I'm using a while loop. Here is my code
<?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, username, COUNT(company), username FROM AdTracking WHERE DATE(dmy) = CURRENT_DATE GROUP BY company ORDER BY company ASC";
$result = mysql_query($query) or die(mysql_error());
echo "<div style='margin-top:100px;'><center><h2>";
echo date(' \ F jS Y - l');
echo "<br />";
echo "</h2><center></div>";
echo '
<center> <table class="pure-table pure-table-horizontal">
<thead>
<tr>
<th>Company</th>
<th>Total</th>
<th>Users</th>
</tr>
</thead>
<tbody>
';
// Print out result
while($row = mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td><strong>" .($row['company'] == NULL ? "???" : $row['company']). "</strong></td>";
echo "<td>" . $row['COUNT(company)'] . "</td>";
echo "<td> ... </td>";
echo "</tr>";
}
echo '
</tbody>
</table> </center>
';
?>
You will have to calculate total of ??? and unknown file outside the while loop
$total = 0;
while($row = mysql_fetch_assoc($result))
{
if($row['company'] == NULL || $row['company'] == "unknown file")
$total += $row['COUNT(company)'];
}
Then you can use that total in the main output loop
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td><strong>" .($row['company'] == NULL ? "???" : $row['company']). "</strong></td>";
if($row['company'] == "unknown file")
echo "<td>" . $total . "</td>";
else
echo "<td>" . $row['COUNT(company)'] . "</td>";
echo "<td> ... </td>";
echo "</tr>";
}
Related
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.
When i load it it comes up with this error : Notice: Trying to get property of non-object in /public_html/php/application/views/admin/index.php on line 29 and says it is not active when it is active.
Please help
<div class="content">
<?php
$con = mysql_connect("","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("", $con);
$result = mysql_query("SELECT * FROM users ORDER by user_id");
echo "<link rel='stylesheet' href='<?php echo URL; ?>public/css/style.css' /><div class='CSSTableGenerator' >
<table >
<tr>
<td>ID</td>
<td >Username</td>
<td>User Active</td>
</tr>";
while($row = mysql_fetch_array($result))
{
if ($row->user_active == "1")
{
$mark = 'Yes';
}
else
{
$mark = 'No';
}
echo "<tr>";
echo "<td>" . $row['user_id'] . "</td>";
echo "<td>" . $row['user_name'] . "</td>";
echo "<td>" . $mark . "</td>";
echo "</tr>";
}
echo "</table></div>";
mysql_close($con);
?>
</div>
Thanks josh_24_2
while($row = mysql_fetch_array($result))
{
if ($row['user_active'] == "1")
{
$mark = 'Yes';
}
else
{
$mark = 'No';
}
echo "<tr>";
echo "<td>{$row['user_id']}</td>";
echo "<td>{$row['user_name']}</td>";
echo "<td>{$mark}</td>";
echo "</tr>";
}
echo "</table></div>";
So this is my code but it does not work, I just get this
Title Article "; while($row = mysqli_fetch_array($result)) { echo ""; echo "" . $row['Title'] . ""; echo "" . $row['Article'] . ""; echo ""; } echo ""; mysqli_close($con); ?>
Any ideas?
<?php
$con=mysqli_connect("localhost","____","____","test_database");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM written");
echo "<table border='1'>
<tr>
<th>Title</th>
<th>Article</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Title'] . "</td>";
echo "<td>" . $row['Article'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Tripple check your quotation marks are set correctly. Either
echo "<table border='1'>
or
</tr>";
has an error in it.
You may also try using echo as a function (bracelets), it should make spotting the error easier :-)
It would be helpfull to see the resulting markup instead of the text ;-)
You have to do this:
echo "<table border='1'><tr><th>Title</th><th>Article</th></tr>";
or
echo "<table border='1'>";
echo "<tr>";
echo "<th>Title</th>";
echo "<th>Article</th>";
echo "</tr>";
instead of
echo "<table border='1'>
<tr>
<th>Title</th>
<th>Article</th>
</tr>";
Hi I have been using this code to fetch data from mysql database and displaying it in column format i.e
a
b
c
What i want is to show 4 names per row i.e
a b c d
e f g....
Can anybody help me in this regard
Thankyou.
Here is my code
<?php
$result = mysql_query("SELECT * FROM Persons");
echo "<table border='1'>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Name'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Use modulus operator %
$i = 0;
while($row = mysql_fetch_array($result))
{
$i++;
if ($i % 4 == 0) {
echo "<tr>";
}
echo "<td>" . $row['Name'] . "</td>";
if ($i % 4 == 0) {
echo "</tr>";
}
}
As a bonus, you've got syntax error in your code. Look at this line
echo "<table border='1'>;
which
should be
echo "<table border='1'>";
$cnt = 0;
while($row = mysql_fetch_array($result))
{
if($cnt%4==0) echo "<tr>";
echo "<td>" . $row['Name'] . "</td>";
$cnt++;
}
<?php
$con = mysql_connect("localhost","user","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
?>
<table border='1'>
<tr>
<?php
$count=1;
while($row = mysql_fetch_array($result))
{
if($count%4==0)
{ ?>
</tr><tr>
<?php }
<td><?php echo $row['Name']; ?></td>
$count++;
}
?>
</tr>
</table>
<?php
mysql_close($con);
?>
I want to create a compare sort of page. I currently have two tables with the information, but want it to be on table or join both together. The first row would show Name of brand, second would show cost, etc... I am grabbing the values of selected checkboxs and based on what they selected it get compared.
$testName = $_POST['testCompare'];
$rpl = str_replace("_", " ", $testName);
$firstOne = "$rpl[0]";
$secondOne = "$rpl[1]";
echo "$firstOne";
echo "<br/>";
echo "$secondOne";
$query = "SELECT * FROM test_table WHERE test_name = '$firstOne'";
$query2 = "SELECT * FROM test_table WHERE test_name = '$secondOne'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$result2 = mysql_query($query2) or die ("Error in query: $query2. " . mysql_error());
if (mysql_num_rows($result) > 0 && mysql_num_rows($result2) > 0) {
//if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_row($result)) {
if ($firstOne == $row[1]) {
{
echo "<table border=1>";
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<tr>";
echo "<td>" . $row[1] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row[2] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row[3] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row[4] . "</td>";
echo "</tr>";
}
}
}echo "</table>";
while($row2 = mysql_fetch_row($result2)) {
if ($secondOne == $row2[1]) {
{ echo "<table border=1>";
echo "<tr>";
echo "<td>" . $row2[0] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row2[1] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row2[2] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row2[3] . "</td>";
echo "</tr>";
echo "<td>" . $row2[4] . "</td>";
echo "</tr>";
}
}
}
echo "</table>";
}
else {
echo "No Results";
}[/CODE]
Thanks
Remove the </table> after the first loop.
Remove <table border=1> from both loops.
Add <table border=1 before the first loop.
Currently, you're defining a new <table border=1> each time you enter the loop. This will result in this HTML code:
<table ..>
<tr>...
<table ..>
..
<table>
..
Et cetera
</table>
<table ..>
Et cetera
</table>