Arrange DIV side by side on demand - HTML PHP - php

I have been goggling this for a while to set one of my requirement. This is what my detailed flow of page.
I have below page and want to arrange DIV in this fashion. Each of this DIV will be filled from my DB. If i have only three item in the DB, then the page should show first row with only three divs and so on. How can i do this by using HTML 5 , CSS and PHP?
........... .............. ............... ..............
. . . . . . . .
. Div1 . . Div2 . . Div3 . . Div4 .
. . . . . . . .
. . . . . . . .
. . . . . . . .
...........
. .
. Div5 .
. .
. .
. .

You can create a counter and set a line break for every 4 divs listed for example, or you can set a maximum width for the parent div, so they will "break" automatically when it does not fit anymore (do not think this cool idea).

You need to assign the parent container a fixed width. Then probably assign the divs some set width and position them relative to the first one.Also set float:left; to all of the divs using css. This should get you working.

Related

Automatically Sort Table By Ascending Quantity in Php/html, not sql

I have data, from HTTP requests, that I am rendering in the form of a table. Right now, I just have it so that the listings are ordered as the for loop processes them, but I want it so that the for loop processes them and then sorts the data according to highest % of weight. Weight is a column header in a table wit h7 other column headers.
Now, this project is in php + html. I have never used php before, so am rather confused with syntax and where to put logic.
I have tried using the sort() and asort() functions in php, but I am clearly putting these things in the wrong order. I feel like what I want to do is: 1) save the output of the for_loop that renders the table in a table format as some data type 2) then sort that data type according to the column of weight in ascending order. 3) display this in a table
Here is some code!
"<div class='last-updated text-left'>" .
"<small>As of <span>$update_date</span></small>" .
"</div>" .
"<table class='ershares-table with-thead'>" .
"<thead><tr>" .
"<th>Company</th>" .
"<th>Weight</th>" .
"<th>Ticker</th>" .
"<th>Market Price</th>" .
"<th>Shares Held</th>" .
"<th>Market Value</th>" .
"<th>CUSIP</th>" .
"</tr></thead> " .
"<tbody>";
for ($i = 0; $i < $for_loop_limit; $i++) :
echo
"<tr>" .
"<td><strong>" . $ers_holdings[$i]["securityDescription"] . "</strong></td>" .
"<td>" . getMarketValuePercentage($ers_holdings[$i]["securityIdentifier"], $ers_holdings[$i]["marketValuePercentage"]) . "%</td>" .
"<td>" . $ers_holdings[$i]["ticker"] . "</td>" .
"<td>" . $ers_holdings[$i]["marketPriceOfSecurity"] . "</td>" .
"<td>" . $ers_holdings[$i]["sharesHeldOfSecurity"] . "</td>" .
"<td>" . $ers_holdings[$i]["marketValueOfHolding"] . "</td>" .
"<td>" . $ers_holdings[$i]["securityIdentifier"] . "</td>" .
"</tr>";
endfor;
echo "</tbody>" .
'</table>' .
I want to sort the table by having the highest value for getMarketValuePercentage... at the top. Thank you in advance.
You're looking for usort().
Before doing your foreach loop, you'll call something along the lines of:
usort($ers_holdings, function ($a, $b) {
return ($a['securityIdentifier'] <=> $b['securityIdentifier']);
});
which would sort the data in $ers_holdings based on the ['securityIdentifier'] value.

SQL display one entry from table one, then display all the entries corresponding, no repeats?

This is my first time using SQL, I'm using PHPMyAdmin. My connection to the database works fine.
I have 8 database tables, but I'm currently just trying to display the data from 5 of them. This is my ER model. I want to display city, place, photo and cat tables in an RSS feed.
Currently when load up the XML it repeats some of the entries, for example for each place it repeats the city information. So for place 1 it shows all the city data, then the place data, and the same for place 2 ect.This is what the first few entries for the current output looks like, it's a long XML file due to the repeats.
I want the city information to be displayed once, then the corresponding place data to be displayed after. So City 1, then place 1,2,3,4,5,6 (as they correspond to city 1), then City 2, then place 7,8,9,10 (as they correspond to city 2).
This is what my current select query looks like :
SELECT s.city_id, s.city_name, s.country_name, s.population,
s.city_long, s.city_lat, s.woeid, s.currency, s.region,
s.time_zone, s.area, s.postal_code, n.place_name, n.capacity,
n.place_long, n.place_lat, n.city_id, c.place_id, c.category_id,
ss.category_id, ss.category_name, ss.category_icon, cc.photo_id,
cc.place_id, cc.photo_name
FROM city s
JOIN place n ON s.city_id = n.city_id
JOIN place_cat c ON c.place_id = n.place_id
JOIN cat ss ON ss.category_id = c.category_id
JOIN photo cc ON cc.place_id = n.place_id
I don't know if it's an issue with the query or with the way I'm echoing the data. This is how I'm echoing it :
foreach($results as $result)
{
//
echo '<item>'. PHP_EOL;
echo '<city>'. PHP_EOL;
echo '<CityName>' . $result['city_name'] . '</CityName>'. PHP_EOL;
echo '<CountryName>' . $result['country_name'] . '</CountryName>'. PHP_EOL;
echo '<Population>' . $result['population'] . '</Population>'. PHP_EOL;
echo '<CityLat>' . $result['city_lat'] . '</CityLat>'. PHP_EOL;
echo '<CityLong>' . $result['city_long'] . '</CityLong>'. PHP_EOL;
echo '<Woeid>' . $result['woeid'] . '</Woeid>'. PHP_EOL;
echo '<Currency>' . $result['currency'] . '</Currency>'. PHP_EOL;
echo '<Region>' . $result['region'] . '</Region>'. PHP_EOL;
echo '<TimeZone>' . $result['time_zone'] . '</TimeZone>'. PHP_EOL;
echo '<Area>' . $result['area'] . '</Area>'. PHP_EOL;
echo '<PostalCode>' . $result['postal_code'] . '</PostalCode>'. PHP_EOL;
echo '<place>'. PHP_EOL;
echo '<PlaceName>' . $result['place_name'] . '</PlaceName>'. PHP_EOL;
echo '<Capacity>' . $result['capacity'] . '</Capacity>'. PHP_EOL;
echo '<PlaceLat>' . $result['place_lat'] . '</PlaceLat>'. PHP_EOL;
echo '<PlaceLong>' . $result['place_long'] . '</PlaceLong>'. PHP_EOL;
echo '<Category>' . $result['category_name'] . '</Category>'. PHP_EOL;
echo '<Photo>' . $result['photo_name'] . '</Photo>'. PHP_EOL;
echo '</place>'. PHP_EOL;
echo '</city>'. PHP_EOL;
echo '</item>'. PHP_EOL;
}
Is there a way to display the data the way I want to (city information to be displayed once, then the corresponding place data to be displayed after)? If so how?

How to format mass data pulled from a database?

I am using a PHP script to pull large amounts of entries from a database, it looks like this:
foreach($events as $e){ //sets each set of data as a value of $e
$vidID = $e["Test Video YouTube ID"]; //stores each video ID as this variable, so that it can be called when embedding the video
echo "<br>" . '<iframe width="250" height="140" src="http://www.youtube.com/embed/' . $vidID . '?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>' . "<br>"
. '<strong> DOC: </strong>' . $e["Axial Cut"] . " " . '<strong> IPM: </strong>' . $e["Inches Per Minute"] . "<br>" .
'<strong> WOC: </strong>' . $e["Radial Cut"] . " " . '<strong> FPT: </strong>' . $e["Inch per Tooth"] . "<br>" .
'<strong> SFM: </strong>' . round($e["Surface Feet per Minute"]) . "<br>"; //each value here is displayed. use the form '$e["Column to be dislplayed"].'
This displays each field for the entry I need, then goes to the next entry and does the same, displaying every entry in the database.
My issue is that it only displays them in a vertical line, so what is the best way to format the output in such a way that it displays in a grid, with a set amount of columns?
*EDIT - To clarify, I don't want to use something like a CSS table for this. It limits me in that the data cannot automatically fill into columns, instead each entry would either appear in a single column or I would have to update each field every time the database had a new entry which would be quite tedious. So what is the best way to have data automatically flow into these columns and rows?

How to loop though data in the database while only querying columns with certain values?

This is part of an issue that I had half of resolved in a previous question but this is another question entirely.
My previous question to give you a basis for what I am trying to achieve:
Using MySQLI how can I display data from my database on my website
NOTE: Column 17 in the table has a value of a number ranging 1-10. These are 10 different sets of information. With the code below I am only interested in query and displaying the results in the table that have the value of 1 in that specific column
How can I use the following code or modify it so that ONLY rows/items in the table that have a value of 1 (or w/e value i choose to run the script with) will be displayed as results when the loop iterates through.
IE: there are 5 columns one, two, three, four, and blooean. All the values in the boolean column are either true or false. I may only want to display results that have a true value. But instead used with my code below and have a vlue of 1.
My Code:
<?php while($row = $result->fetch_assoc()) {
echo
'<div class="list-item-container">'
. '<img class="favicon" src="http://www.google.com/s2/favicons?domain='. $row['favicon_url'] . '" />'
. '<div class="list-item"><a title="' . $row['affiliate_name_title'] . '" href="' . $row['affiliate_url'] . '">' . $row['affiliate_name'] . '</a><span class="tld">' . $row['tld'] . '</span><span class="list-item-note"> ' . $row['country'] . '</span></div>'
. '<div class="unverified_icon"><img title="' . $row['verified_title'] . '" src="img/icons/' . $row['verified_image'] . '" /></div>'
. '<div class="hover-img"><img class="games-icon" src="img/icons/games.png" alt="" title="' . $row['games_title'] . '"/><img class="payment-icon" src="img/icons/payment.png" alt="" title="' . $row['payment_title'] . '"/><img src="blank.gif" class="flag ' . $row['country_image'] . '" alt="Czech Republic" title="' . $row['flag_title'] . '"/></div>'
. '</div>';
}
?>
As always, thanks!
EDIT: No one seems to understand what I mean. Sorry, not sure how else to explain/ask it.
I am running this same script in a lot of different locations on the same page.
On each location of the page I want to run the same script
Each place I run it I would like to be able to display only certain items from the table based on a option(not sure what its called) i give it. In div_1 i run the script and I need to display all results with a column 17 value of 1.
In div 2 I run the script but want to display only results/values from the table that have a column 17 value of 2, etc, etc,.
Why not do it in your query ahead, like:
$query = "SELECT * FROM yourTable WHERE value=1";
Or using your own code, it would be:
<?php
// Connect to and select a database
$db = new mysqli('localhost', 'root', '', 'DATABASE');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
// Query the table 'TABLES' (I'm also assuming I only need to query just the table from here)
$sql = <<<SQL
SELECT *
FROM `TABLE`
WHERE `Column17` = 1
SQL;
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()) {
echo
'<div class="list-item-container">'
. '<img class="favicon" src="http://www.google.com/s2/favicons?domain='. $row['favicon_url'] . '" />'
. '<div class="list-item"><a title="' . $row['affiliate_name_title'] . '" href="' . $row['affiliate_url'] . '">' . $row['affiliate_name'] . '</a><span class="tld">' . $row['tld'] . '</span><span class="list-item-note"> ' . $row['country'] . '</span></div>'
. '<div class="unverified_icon"><img title="' . $row['verified_title'] . '" src="img/icons/' . $row['verified_image'] . '" /></div>'
. '<div class="hover-img"><img class="games-icon" src="img/icons/games.png" alt="" title="' . $row['games_title'] . '"/><img class="payment-icon" src="img/icons/payment.png" alt="" title="' . $row['payment_title'] . '"/><img src="blank.gif" class="flag ' . $row['country_image'] . '" alt="Czech Republic" title="' . $row['flag_title'] . '"/></div>'
. '</div>';
}
?>

inserting variable into table

I am able to generate the activation_key in the following code. But I can't manage to insert it into the table. Blank value gets inserted into the table.
What am I doing wrong? (using PEAR text password and other extensions)
$activation_key = Text_Password::createFromLogin($data['email'], 'rot13');
$sql = "INSERT INTO auth (firstname, lastname,gender,dob,mobileno,landlineno,addressline1,addressline2,addressline3,country,state,city,pincode,email,username,password,question,answer,activation_key)
VALUES ('" . $db->escapeSimple($data['firstname']) . "','"
. $db->escapeSimple($data['lastname'])."','"
. $db->escapeSimple($data['gender'])."','"
. $db->escapeSimple($data['dob'])."','"
. $db->escapeSimple($data['mobileno'])."','"
. $db->escapeSimple($data['landlineno'])."','"
. $db->escapeSimple($data['address1'])."','"
. $db->escapeSimple($data['address2'])."','"
. $db->escapeSimple($data['address3'])."','"
. $db->escapeSimple($data['country'])."','"
. $db->escapeSimple($data['state'])."','"
. $db->escapeSimple($data['city'])."','"
. $db->escapeSimple($data['pin'])."','"
. $db->escapeSimple($data['email'])."','"
. $db->escapeSimple($data['username'])."','"
. md5($db->escapeSimple($data['pwd']))."','"
. $db->escapeSimple($data['question'])."','"
. $db->escapeSimple($data['answer']). "', '"
. $db->escapeSimple($data['activiation_key'])."')";
$db->query($sql);
$data['$activiation_key'] doesn't actually appear to hold $activation_key
plus if you really cut and paste then $activiation_key is spelt wrongly

Categories