I am new to css and php, i want to retrieve information from db via php and display it to the user, all working fine but problem is with the UI part enter image description here
and my code is
<?
$result=mysql_query($query) or die (mysql_error());
echo "<div class='container'>";
while($row =mysql_fetch_array($result))
{
echo "<div class='row custom1'>";
echo "<div class='col-sm-12' id='dd' style='border-style:solid; border-width:1px; margin-left:10px; margin-top:20px'><a href='showit.php' class='kk'>";
echo '<p class="head1">QUESTION:',$row['title'],'</p><p clsss="head2" style="font-size:20px;"></br>Tags:',$row['tags'],'</br>Posted by:',$row['posted'],'</br>Posted On:',$row['postedon'],'</p>';
echo "</div>";
}
echo "</div>";
?>
is there any way to align the divs properly?
it's because you're missing the closing </div> for the second div and the closing </a> in your while loop making a bunch of children of each other, rather than inner nodes of the container parent, use this loop instead:
$result=mysql_query($query) or die (mysql_error());
echo "<div class='container'>";
while($row =mysql_fetch_array($result))
{
echo "<div class='row custom1'>";
echo "<div class='col-sm-12' id='dd' style='border-style:solid; border-width:1px; margin-left:10px; margin-top:20px'>";
echo "<a href='showit.php' class='kk'>";
echo "<p class=\"head1\">QUESTION:".$row['title']."</p>";
echo "<p class=\"head2\" style=\"font-size:20px;\">";
echo "</br>Tags:".$row['tags']."</br>Posted by:".$row['posted']."</br>Posted On:".$row['postedon'];
echo "</p>";
echo "</a>";
echo "</div>"; //col-sm-12
echo "</div>"; //row custom1
}
echo "</div>";
By careful you are not closing all tags. I saw that
<div class='col-sm-12' id='dd' style='border-style:solid; border-width:1px; margin-left:10px; margin-top:20px'><a href='showit.php' class='kk'>
is not closed.
Please go into your browser page and inspect the elements an verify how they are closed.
Related
I have a MYSQL database where I store images for reports I can import them to the Tinymce text area but they are being placed below each other. Is there away I can make them place two two next to each other. Some reports have 2 photos and other might have 10 depending on how many was loaded to the DB
This is my current code:
$result = mysqli_query($db, "SELECT * FROM images WHERE file_nr = '$id'");
?>
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div id='img_div'>";
echo "<img width='300' height='300' display: inline-block;
src='../../cases_1/overdue/images/".$row['image']."' >";
echo "<p>".$row['image_text']."</p>";
echo "</div>";
}
?>
I tried inline-block not working.
I don't think this is the cleanest method but got this working
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div id='img_div'>";
echo "<img width='350px' height='350px' style='float: left; padding: 4px;' src='../../cases_1/overdue/images/".$row['image']."' >";
echo "</div>";
}
?>
So I have a nested loop due to getting data from two different sources.
I want to count how many times it goes through the second loop, and use that value in the first loop.
I have 2 entries in the RaidFacade
And 10 entries in "GetRaidProgression"
$raid_facade = new RaidFacade();
$raids = $raid_facade->getAll();
unset($raid_facade);
<div class='col-lg-4' id='toggleraid'>
<div class='topbar'>Raid Progress</div>
<?php
$boss_count_alive = 0;
$boss_count_killed = 0;
foreach ($raids as $raid)
{
$raid_name = $raid->getName();
echo "<div class='raid'>";
echo "<div class='name'>";
echo "<a class='collapsed' data-toggle='collapse' data-target='#raid".$raid_name."' aria-expanded='false' aria-controls='raid".$raid_name."'>";
echo $raid_name;
echo "</a>";
echo "</div>";
echo "<div class='prog'>".$boss_count_killed."<mark>/</mark>".$boss_count_alive."</div>";
echo "<div class='bar'>";
echo "<div class='color' style='width: 60%'></div>";
echo "</div>";
echo "<div class='gradient'></div>";
echo "<img src='img/layout/raid/zul_gurub.jpg'>";
echo "</div>";
echo "<div id='raid".$raid_name."' class='collapse raidCollapse' data-parent='#toggleraid'>";
foreach ($raid->getRaidProgression() as $boss)
{
$boss_count_alive++;
$class = "fas fa-times fa-sm";
$youtube = "";
if ($boss->getStatus() == 1)
{
$class = "fas fa-check fa-sm";
$boss_count_killed++;
}
echo "<div>";
echo "<div><span><i class='".$class."'></i>".$boss->getBoss()."</span></div>";
echo "</div>";
}
echo "</div>";
}
?>
</div>
In the div class='prog' I would like to use the $boss_count_alive and $boss_count_killed values.
This is not happening, the first entry returns 0/0, the next one returns 3/10 (Which are my expected result for first entry)
To get a visual look:
Thanks in advance!
Your second loop will only run after you have echoed "<div class='prog'>".$boss_count_killed."<mark>/</mark>".$boss_count_alive."</div>";, which is why it's echoing 0/0 the first time.
If you want it to echo 3/10 the first time, you need to run your inner loop first to calculate the values, then echo. In your case it would be something like this:
foreach ($raids as $raid)
{
$raid_name = $raid->getName();
$bosses_html = "";
foreach ($raid->getRaidProgression() as $boss)
{
$boss_count_alive++;
$class = "fas fa-times fa-sm";
$youtube = "";
if ($boss->getStatus() == 1)
{
$class = "fas fa-check fa-sm";
$boss_count_killed++;
}
$bosses_html .= "<div>";
$bosses_html .= "<div><span><i class='".$class."'></i>".$boss->getBoss()."</span></div>";
$bosses_html .= "</div>";
}
echo "<div class='raid'>";
echo "<div class='name'>";
echo "<a class='collapsed' data-toggle='collapse' data-target='#raid".$raid_name."' aria-expanded='false' aria-controls='raid".$raid_name."'>";
echo $raid_name;
echo "</a>";
echo "</div>";
echo "<div class='prog'>".$boss_count_killed."<mark>/</mark>".$boss_count_alive."</div>";
echo "<div class='bar'>";
echo "<div class='color' style='width: 60%'></div>";
echo "</div>";
echo "<div class='gradient'></div>";
echo "<img src='img/layout/raid/zul_gurub.jpg'>";
echo "</div>";
echo "<div id='raid".$raid_name."' class='collapse raidCollapse' data-parent='#toggleraid'>";
echo "</div>";
echo $bosses_html;
}
In this example, the first set of echoes are moved below the inner loop. The html that would normally be echoed in the inner loop is stored in a variable to be echoed later at the end.
I have been trying to set up a page that lists prices of items from a table in a database. Here is my code:
<?php
$querylist = mysql_query("SELECT item_name,image,price,added_by FROM values");
while($row = mysql_fetch_array($querylist))
{
echo '<div class="post rareitem" style="margin-right: 15px;float: left;">
<div class="rarename">
<strong>';
// Shows Item Name
echo $row['item_name'];
echo '</strong>
</div>';
// Shows Item Image
echo '<div class="rareimage" style="background-image: url(/app/tpl/skins/Mango/images/values/rares/';
echo $row['image'];
echo ');"></div>';
// Shows Item Price
echo '<div class="rarecontrols">
<div class="coinsbox"></div>
<span>
<b> <b>Credits: </b> </b> ';
echo $row['price'];
echo '</span>';
// Shows Who Added the Item
echo '<div class="addedbox"></div><b><b><span><font color="#c93734"><font color="#c93734">Added By: </font> </font>';
echo $row['added_by'];
echo '</span></b></b>
</div>
<div class="clear"></div>
</div>';
}
?>
There is another chunk of code (shown below) that I have based this off of, and it works perfectly fine. I can't seem to get this to work though. I believe it has something to do with the SQL, the syntax, or something. No matter what I do, it produces absolutely no results, yet the code below results exactly as planned. I know for a fact it is not a connection issue because the below code can be placed on the same exact page as the above one and it works fine, however the above does not.
<?php
$querylist = mysql_query("SELECT id,username,motto,country,look,rank,account_created,role,account_created,online,last_online FROM users WHERE rank='9' ORDER BY ID LIMIT 20");
while($row = mysql_fetch_array($querylist))
{
echo '
<div class="team">';
// Showing Avatar
echo '<div style="float: left; margin-top:-1px;height: 60px; width: 64px; background: url(http://www.habbo.nl/habbo-imaging/avatarimage?figure=';
echo $row['look'];echo "&action=wav&direction=3&head_direction=3&gesture=sml&size=m) no-repeat 0px -10px";
echo "\"/>";
echo "<img alt=\"badge\" src=\"/app/tpl/skins/habbo/images/icons/";
echo $row['online'];echo ".gif\"></div>";
// Flags
echo "<br/><img src=\"/app/tpl/skins/habbo/images/icons/flags/";
echo $row['country'];echo ".png";
echo '" style="float:right;" /> <b><uf>';
echo $row['username'];echo "</u></b>";
// Bans & Ticket Count
$Bans = mysql_query("SELECT * FROM `bans` WHERE `added_by` = '" . $row['username'] . "'");
$BanCount = mysql_num_rows($Bans);
$Tickets = mysql_query("SELECT * FROM `moderation_tickets` WHERE `moderator_id` = '" . $row['id'] . "'");
$TicketCount = mysql_num_rows($Tickets);
//Role
echo "<br/><gb>Role: </b><fi> ";
echo $row['role'];echo "";
echo "</i>";
// Echoing bans & Tickets
echo "<br/><gb>Bans: </b><fi> ";
; echo $BanCount;
echo "</i>";
echo " <gb>Tickets: </b><if>";
; echo $TicketCount;
echo "</i>";
echo "</div>";
}
?>
Thanks in advanced, any assistance will be greatly appreciated!
values is Reserved Words in mysql it should be on backtick
SELECT item_name,image,price,added_by FROM `values`
And stop using mysql it is deprecated. Instead use mysqli or PDO
I am new to PHP; please help me.
I am trying to align two PHP tables with images in them side by side but they are displaying one below the other. I want two tables side by side under one heading and two tables side by side under second heading. I've seen some solutions in HTML but I am looking for PHP. Please find screenshot of my error and my code below:
Please feel free to ask for any clarifications.
$prodcatSQL="select prodcatid, prodcatname, prodcatimage from prodcat"; // create an $sql variable and store the sql statement
$exeprodcatSQL=mysql_query($prodcatSQL) or die (mysql_error());
while ($arrayprod=mysql_fetch_array($exeprodcatSQL))
{
echo "<strong>Using display: inline-block; </strong><br>\n";
echo "<table border=1 class=\"inlineTable\">\n";
echo "<tr>\n";
echo "<td><p><a href=products.php?u_prodcatid=".$arrayprod['prodcatid'].">";
echo $arrayprod['prodcatname'];
echo "<p><img src=images/".$arrayprod['prodcatimage']."></p>";
echo "</a></p></td>\n";
echo "</tr>\n";
echo "</table>\n";
}
echo "<h3><center>".$subheading."</center></h3>";
$treatcatSQL="select treatcatid, treatcatname, treatcatimage from treatcat"; // create an $sql variable and store the sql statement
$exetreatcatSQL=mysql_query($treatcatSQL) or die (mysql_error());
while ($arrayprod=mysql_fetch_array($exetreatcatSQL))
{
echo "<strong>Using display: inline-block; </strong><br>\n";
echo "<table border=1 class=\"inlineTable\">\n";
echo "<tr>\n";
echo "<td><p><a href=treatmentpackages.php?u_treatcatid=".$arrayprod['treatcatid'].">";
echo $arrayprod['treatcatname'];
echo "<p><img src=images/".$arrayprod['treatcatimage']."></p>";
echo "</a></p></td>\n";
echo "</tr>\n";
echo "</table>\n";
}
You have nested <p> tags which may be introducing unnecessary new lines. Remove the tags and replace them with separate <td> elements and the alignment should be fine.
$prodcatSQL="select prodcatid, prodcatname, prodcatimage from prodcat"; // create an $sql variable and store the sql statement
$exeprodcatSQL=mysql_query($prodcatSQL) or die (mysql_error());
while ($arrayprod=mysql_fetch_array($exeprodcatSQL))
{
echo "<strong>Using display: inline-block; </strong><br>\n";
echo "<table border=1 class=\"inlineTable\">\n";
echo "<tr>\n";
echo "<td><a href=products.php?u_prodcatid=".$arrayprod['prodcatid'].">";
echo $arrayprod['prodcatname'];
echo "</a></td><td><a href=products.php?u_prodcatid=".$arrayprod['prodcatid']."><img src=images/".$arrayprod['prodcatimage'].">";
echo "</td></a>\n";
echo "</tr>\n";
echo "</table>\n";
}
$treatcatSQL="select treatcatid, treatcatname, treatcatimage from treatcat"; // create an $sql variable and store the sql statement
$exetreatcatSQL=mysql_query($treatcatSQL) or die (mysql_error());
while ($arrayprod=mysql_fetch_array($exetreatcatSQL))
{
echo "<strong>Using display: inline-block; </strong><br>\n";
echo "<table border=1 class=\"inlineTable\">\n";
echo "<tr>\n";
echo "<td><a href=treatmentpackages.php?u_treatcatid=".$arrayprod['treatcatid'].">";
echo $arrayprod['treatcatname'];
echo "</a></td><td><a href=treatmentpackages.php?u_treatcatid=".$arrayprod['treatcatid'].">";
echo "<img src=images/".$arrayprod['treatcatimage']."></a>";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
}
If this does not work, please edit the HTML output into the question.
You need to add this to your table, if you don't want external CSS
Replace this in each,
echo "<table border=1 class=\"inlineTable\">\n";
With this
echo "<table border=1 class=\"inlineTable\" style=\"width:50%;float:left;\">\n";
So I'm trying to get the bootstrap accordion to dynamically show the Top 5 teams judged by most wins, I also use it for other rankings.
The problem is whenever I click tab 2, 3, or 4 it only opens tab 1 in the accordion. I know the issue is from "href='#collapse41'" being the same from every loop. I assume this will require a unique ID for each accordion div tab but I don't know how to implement it correctly. I could be 100% wrong, if so please correct me!
I've done about 15 searches on this and only found one answer, which wasn't very detailed or helpful. Any help or pointers to learn how to do this would be much appreciated.
(The reason I renamed it to #collapse41 is because I have multiple accordions on the same page.)
<div class="accordion" id="accordion2">
<?php
include 'db.php'; //connect to database
$result = mysql_query("SELECT * FROM teams ORDER BY wins DESC LIMIT 5");
$rank = 1;
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) {
echo "<div class='accordion-group'>";
echo "<div class='accordion-heading'>";
echo "<a class='accordion-toggle' data-toggle='collapse' data-parent='#accordion4' href='#collapse41'>";
echo "<td>{$row['name']} <br /> </td>";
echo "</a>";
echo "</div>";
echo "<div id='collapse41' class='accordion-body collapse'>";
echo "<div class='accordion-inner'>";
echo "<td>Rank: {$rank} <br /> </td>";
echo "<td>Wins: {$row['wins']} <br /> </td>";
echo "<td>Losses: {$row['losses']} <br /> </td>";
echo "</div>";
echo "</div>";
echo "</div>";
$rank++;
}
}
?>
</div>
You have to break the loop up....and loop once to get headings, and twice to get body...
So you need to echo the group div first....
echo "<div class='accordion-group'>";
Then start the loop to output headings...
Then run another loop to output divs....
if (mysql_num_rows($result)) {
//LOOP 1
while ($row = mysql_fetch_assoc($result)) {
//Build heading pieces
echo "<div class='accordion-heading'>";
echo "<a class='accordion-toggle' data-toggle='collapse' data-parent='#accordion-".$row['id']." href='#accordian-".$row['id']."'>";
echo "<td>{$row['name']} <br /> </td>";
echo "</a>";
echo "</div>";}
//LOOP 2
//Build inner pieces
while ($row = mysql_fetch_assoc($result)) {
echo "<div id='accordian-".$row['id']."' class='accordion-body collapse'>";
echo "<div class='accordion-inner'>";
echo "<td>Rank: {$rank} <br /> </td>";
echo "<td>Wins: {$row['wins']} <br /> </td>";
echo "<td>Losses: {$row['losses']} <br /> </td>";
echo "</div>";
echo "</div>"; }
echo "</div>";
$rank++;
}
}
Im not actually too sure of how your accordian is to be structured, so this may or may not be correct information, but whenever I do twiiter-bootstrap accordians, this is how I do it. If you could post your expected HTML output (template for accordian), that would help me greatly, and I can revamp my answer to suit what you actually need