-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Problem displaying database attribute inside a javascript popup
Barand replied to webdeveloper123's topic in PHP Coding Help
All that matters is that the popuptext id should be unique. Using the room id gives that uniqueness, but so would a simple incremented value. But in no case would the id be an array. -
php count lines in a text file with a specific variable
Barand replied to erisoov's topic in PHP Coding Help
code $data = file('data.txt', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); usort($data, fn($a, $b)=>substr($a,11,2)<=>substr($b,11,2)); // sort by code number $codes = []; foreach ($data as $d) { $p = strpos($d, ')'); $k = substr($d, 11, $p-10); if (!isset($codes[$k])) { $codes[$k] = 1; } else { $codes[$k]++; } } echo (join("<br>", $data)); echo ("<h3>Total clicks</h3>"); foreach ($codes as $code => $total) { printf("%s Total clicks = %d<br>", $code, $total); } output 15/09/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 Finland Helsinki Uusimaa 18/09/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 Finland Helsinki Uusimaa 21/09/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 Germany Gera Thuringia 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Edmore Michigan 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Alhaurin de la Torre Malaga 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Alhaurin de la Torre Malaga 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Cedar Springs Michigan 15/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Cedar Springs Michigan 15/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Madrid Madrid 15/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Cedar Springs Michigan 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Nerja Malaga 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Nerja Malaga 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Nerja Malaga 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Nerja Malaga 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Cartagena Murcia 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 21/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Nerja Malaga 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Garden City New York 21/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 Norway Sira Agder 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United Kingdom Sheffield Sheffield 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United Kingdom Sheffield Sheffield 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United Kingdom Sheffield Sheffield 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 Spain Muro del Alcoy Alicante 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Edmore Michigan 10/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 11/09/2023 20 The Legacy of Jesus (El Legado de Jesús)20-8-2023.mp3 United States Ashburn Virginia 15/09/2023 20 Be With Me Where I Am (Está Conmigo Donde Estoy)20-8-2017.mp3 Finland Helsinki Uusimaa 18/09/2023 20 Be With Me Where I Am (Está Conmigo Donde Estoy)20-8-2017.mp3 Finland Helsinki Uusimaa 21/09/2023 20 Be With Me Where I Am (Está Conmigo Donde Estoy)20-8-2017.mp3 Germany Gera Thuringia Total clicks 03 Resist the Curse (Resiste la Maldición) Total clicks = 3 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) Total clicks = 19 05 Day of Atonement 2023 (Día de la Expiación) Total clicks = 12 19 The Bread of Life (El Pan de la Vida) Total clicks = 11 20 The Legacy of Jesus (El Legado de Jesús) Total clicks = 1 20 Be With Me Where I Am (Está Conmigo Donde Estoy) Total clicks = 3 -
Problem displaying database attribute inside a javascript popup
Barand replied to webdeveloper123's topic in PHP Coding Help
Keep it simple <script type='text/javascript'> function myFunction(n) { var popup = document.getElementById("myPopup"+n); if (popup.style.display == "block") { popup.style.display = "none" } else { popup.style.display = "block" } } </script> <style type='text/css'> .popup { cursor: pointer; } .popuptext { display: None; background-color: #eee; padding: 16px 80px; } </style> html <div class="searchresults"> <div class="resultdetails"> <h2> Room</h2> <h1> Superior Queen</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 825.00</p> <p class='details'> Amenities: Queen Size Bed • Mini-Bar • WiFi • Wheel chair access • Safe</p> <div class="popup" onclick="myFunction(1)">See all <span class="popuptext" id="myPopup1"><p class='details'> Amenities:<br> 55 Inch Smart TV<br>Mini-Bar<br>Queen Size Bed<br>Safe<br>Wheel chair access<br>WiFi</p></span> </div> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior Queen</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 825.00</p> <p class='details'> Amenities: WiFi • Wheel chair access • Safe • 55 Inch Smart TV • Queen Size Bed</p> <div class="popup" onclick="myFunction(2)">See all <span class="popuptext" id="myPopup2"><p class='details'> Amenities:<br> 55 Inch Smart TV<br>Mini-Bar<br>Queen Size Bed<br>Safe<br>Wheel chair access<br>WiFi</p></span> </div> </div> <div class="resultdetails"> <h2> Room</h2> <h1> Superior Queen</h1> <p class="details"> Sleeps 2</p> <p class="details"> Price 850.00</p> <p class='details'> Amenities: Safe • 55 Inch Smart TV • Twin Beds • Mini-Bar • WiFi</p> <div class="popup" onclick="myFunction(3)">See all <span class="popuptext" id="myPopup3"><p class='details'> Amenities:<br> 55 Inch Smart TV<br>Mini-Bar<br>Safe<br>Twin Beds<br>WiFi</p></span> </div> </div> -
Problem displaying database attribute inside a javascript popup
Barand replied to webdeveloper123's topic in PHP Coding Help
You need to a way for your js function to specify which popup to show. One way would be to pass the room id in the function call onclick = "myFunction(xx)" and to append the room id to your ids to make them unique id="mypopupxx" -
Problem displaying database attribute inside a javascript popup
Barand replied to webdeveloper123's topic in PHP Coding Help
As I said earlier, I don't now think the group_concat_max_len is your problem. I am struggling with your html, trying to get the popup to work for me. I notice you have many elements all with the same id ("mypopup"). Ids must be unique. You are probably getting the same (short list) popup displaying every time, regardless of which room you click. -
Problem displaying database attribute inside a javascript popup
Barand replied to webdeveloper123's topic in PHP Coding Help
Your html is displaying all that it is being asked to display. From your html source... <span class="popuptext" id="myPopup"><p class='details'> Amenities: 55 Inch Smart TV<br>Mini-Bar<br>Queen Size Bed<br>Safe<br>Wheel chair access<br>WiFi</p></span> The fault appears to be in the PHP/SQL and not on the client side. -
Problem displaying database attribute inside a javascript popup
Barand replied to webdeveloper123's topic in PHP Coding Help
It was just a theory, but as you are displaying about 100 characters your limit would need to be very small for that to be the cause. -
Problem displaying database attribute inside a javascript popup
Barand replied to webdeveloper123's topic in PHP Coding Help
What does this query give you? SELECT @@group_concat_max_len; -
@aarti789 You may have corrected the grammar but apostrophes in a variable name are not a good idea.
-
From my first experience above, I came to the conclusion that asp was particularly slow whenever string concatenation was involved.
-
I started my web programming using ASP but after a while decided to give PHP a go. A couple of examples spring to mind. A simple page which allowed users in one of our departments to view daily comments from a log. One day I had a complaint that the page took 15 seconds to load in the browser. Repeated tests on that day's data gave the same result. The comments on this day were particularly verbose. I wrote a PHP version which, when tested on that same day's data, repeatedly produced the results in just over 0.2 seconds (70x faster). This was an exception but, normally, PHP was better that 3x faster. A page which allowed the public to enter their location and a search radius and it would find the time of all bus services, in the next hour, which departed from stops in the search radius. There was, however, a problem in the city centre with a high stop density. A radius of 200m would cause the whole thing to timeout after 30 seconds. Again a PHP rewrite was tried. Even at a radius of 2000m it displayed all the stops and times within a few seconds - no timing out. Score 2 for PHP. After those my boss stopped objecting to my using PHP. (His objection had been on the grounds that it wasn't a MS product!)
-
In much the same way as Superman uses kryptonite.
-
Using row_number on attribute to only return 5 rows
Barand replied to webdeveloper123's topic in MySQL Help
Another way to it is to forget about row_number() OVER etc and, instead, use the simpler SELECT ... , substring_index(GROUP_CONCAT(f.description separator ' • '), ' • ', 5) as rmfac to get the whole list of facilies then select the first 5 -
Using row_number on attribute to only return 5 rows
Barand replied to webdeveloper123's topic in MySQL Help
It would be if it allowed window functions in WHERE clauses - but it doesn't, so some rewriting needed.. -
Using row_number on attribute to only return 5 rows
Barand replied to webdeveloper123's topic in MySQL Help
Try getting your 5 facilities for each room in a table subquery. Then join to that subquery on room_id. -
Using row_number on attribute to only return 5 rows
Barand replied to webdeveloper123's topic in MySQL Help
Yes. Aliases don't exist at the time the query uses the WHERE clause - they are created on output. So... WHERE rb.room_id IS NULL AND row_number() OVER (order by f.facility_id) <= 5 -
Using row_number on attribute to only return 5 rows
Barand replied to webdeveloper123's topic in MySQL Help
You cannot use a column alias in a WHERE clause, you need the whole expression -
Using row_number on attribute to only return 5 rows
Barand replied to webdeveloper123's topic in MySQL Help
Yes. A single WHERE preceding the GROUP BY -
Using row_number on attribute to only return 5 rows
Barand replied to webdeveloper123's topic in MySQL Help
Both -
No problem. For example, the one with a score of 76 has five pupils with a higher score and is, therefore, sixth in the class.
-
Have you removed that function definition that was in the first post? Why?
-
try foreach ($res as $r) { if (!isset($data[$r['subjectname']])) { $data[$r['subjectname']]['students'] = []; } $position = ordinal($r['rank']); $data[$r['subjectname']]['students'][] = [ 'name' => $r['stname'], 'score' => $r['score'], 'rank' => $position ]; }
-
You do need to call the function.
-
scraping from a page using file_get_contents and preg_match_all
Barand replied to wilsoc31's topic in PHP Coding Help
Sure, simple_html_dom preserves the hyperlink (as my sample output showed) The first bit of the html output from my original code was... <a href="/test1.html?ti=1327"><b><span style="color: #AB1717;">2023 NSA AUTUMN BY THE SEA - 1ST/2ND PLACE TEAMS WIN BOWNET PRIZE PACK </span></b></a><br> MAD BCH ROC/STARKEY RANCH<br> MAD BCH/TRINITY<br> 2023-09-23<br> 2023-09-24<br> 8U - 18U<br> <a href="/test1.html?ti=1326"><b><span style="color: #AB1717;">2023 NSA LIGHT OF AUBRIEN SCHOLARSHIP TOURNAMENT</span></b></a><br> BLACKSTONE PARK<br> PALMETTO<br> 2023-09-23<br> 2023-09-24<br> 8U - 18U<br> Or you can try experimenting with DOMDocument ( https://www.php.net/DOM ) It took me ages to find the right incantations for my second post. -
scraping from a page using file_get_contents and preg_match_all
Barand replied to wilsoc31's topic in PHP Coding Help
You need to change all "&" in your html text to the correct html entities "&" (simple_html_dom is more forgiving)