Jump to content

requinix

Administrators
  • Posts

    15,067
  • Joined

  • Last visited

  • Days Won

    414

Everything posted by requinix

  1. The time is in there too. Are you sure the dtDate field is a DATETIME and not just a DATE?
  2. Okay. So. echo " <div class='podatak'>That's where the class needs to go. You already have $boja1="divclass1"; $boja2="divclass2";but I don't know which is the normal class and which is the highlight class so I'm just going to guess. Use an if to decide which class you should use. if ($redak['kolicina'] == 0) { $boja = $boja1; } else { $boja = $boja2; }Now put that variable into the HTML. echo " <div class='podatak {$boja}'>
  3. Alright so we're back to my original interpretation of your question. $redak['kolicina'] is the value. If the value is 0 then output one class, otherwise output another class. And as you already know the HTML markup will look like So put the right class name in there.
  4. Uh, what? We're going to need to see some proof of that if you want help.
  5. Then your code doesn't match up with your screenshot? Easiest way: do the query to get the data you want, like normal. Maybe SELECT naziv_lijeka, sifra, jedmjera, kolicina FROM stanje_lijekova WHERE some conditionThen do another query that looks similar but gets a count of how many rows have kolicina=0. SELECT COUNT(1) FROM stanje_lijekova WHERE some condition AND kolicina = 0The first value in the first row will tell you how many there are. So don't use mysql_num_rows() for it.
  6. if (mysql_num_rows($q)>0) { echo $boja1; } else { echo $boja2; }Or maybe I don't understand the question?
  7. Not really: shuffle() is random so you'd end up with a different quote every time. You'd need something more than that. The standard way to deal with this is to use PHP's random number generators (rand(), mt_rand()) but seeding, the way you could get a set of stable random results, isn't reliable anymore: srand() is disabled if PHP is installed with the Suhosin patch/extension and that's popular with shared hosting environments, while mt_srand() won't guarantee the stability because of what it can do to the seed number. A sort of pseudo-random shuffle would be fine: shuffle the items in the array so that quote #N doesn't always appear before quote #N+1. Something like function RandomQuoteByInterval($TimeBase, $QuotesArray){ // Make sure it is a integer $TimeBase = intval($TimeBase); // How many items are in the array? $ItemCount = count($QuotesArray); // Shuffle the array in a way that looks random // 1. Create an array of random strings for each quote $QuotesKeys = array(); foreach ($QuotesArray as $N => $Quote) { $QuotesKeys[$N] = md5($TimeBase . $Quote); } // 2. Sort the keys array normally, and at the same time // rearrange the quotes to match array_multisort($QuotesKeys, $QuotesArray); // By using the modulus operator we get a pseudo // random index position that is between zero and the // maximal value (ItemCount) $RandomIndexPos = ($TimeBase % $ItemCount); // Now return the random array element return $QuotesArray[$RandomIndexPos]; }The downside to using randomness is that a particular quote may show up twice (or more) in a row. There are ways to avoid that...
  8. Pretty simple: use a form to post a password to the page, then only show the page if the right password was sent. Basically, <!-- header of your page, up until the content area --> <?php if (!isset($_POST["password"]) || $_POST["password"] != "yourpasswordhere") { // no password or wrong password ?> <form action="" method="post"> <p>Password: <input type="password" name="password"> <button type="submit">Enter</button></p> </form> <?php } else { // correct password ?> <!-- normal page content --> <?php } ?> <!-- footer of your page -->Every time they visit the page they have to enter the password. It won't "remember" them.
  9. Correct. And it's not random: it cycles through each quote in order... with a limit of 12 quotes because the 'h' value has a range of 1-12. Almost. You have to do the modulus (%) on the total number, not on just the $TimeBase. $RandomIndexPos = ($TimeBase + $currentYear + $currentMonth + $currentDay) % $ItemCount;However, you don't have to do it in RandomQuoteByInterval. In fact I would not. Just call the function with the new number. And while I'm in the code, here's another way of getting the random result: $TimeValue = floor(time() / 3600); // number of hours since Jan 1 1970 // Example array with some random quotes $RandomQuotes = array( 'No animals were harmed in the making of this snippet.', 'Nice snippets', 'The modulus operator rocks!', 'PHP is cool.' ); print RandomQuoteByInterval($TimeValue, $RandomQuotes);As before this is not random: it will cycle through quotes in order. If you wanted it in "truly" random order then you'd need different code...
  10. What's the code for init_session()?
  11. Then rearrange the code so you determine the $mainNav before the header gets included.
  12. str_replace() works by doing each pair of replacements in turn. First, then second, then third, and so on. Since "TBD" will replace to something containing "TB", the "TB" replacement will also work on that. You have to make sure that the array is ordered so that doesn't happen. Moving TBD to the end should do it.
  13. How are you doing the replace? What's the rest of the code?
  14. What? $query = <<<SQL //set NOCOUNT ON /*optional*/ SELECT cast(h1.Weeknum AS varchar) +'|' +cast(h1.Year AS varchar) +'|' +QUOTENAME(CASE WHEN Cty.CountryName = 'Singapore' THEN 'SG' WHEN Cty.CountryName = 'Hong Kong' THEN 'HK' WHEN Cty.CountryName = 'Japan' THEN 'JP' WHEN Cty.CountryName = 'China' THEN 'CN' WHEN Cty.CountryName = 'Indonesia' THEN 'ID' WHEN Cty.CountryName = 'Taiwan' THEN 'TW' WHEN Cty.CountryName = 'Thailand' THEN 'TH' WHEN Cty.CountryName = 'Philippines' THEN 'PH' WHEN Cty.CountryName = 'Macau' THEN 'MO' WHEN Cty.CountryName = 'Malaysia' THEN 'MY' ELSE '' END , '""') +'|' + QUOTENAME(Loc.LocationName,'"') +'|' +QUOTENAME(CASE WHEN Cust.CustomerName = 'McDonalds'THEN'MCD' WHEN Cust.CustomerName = 'Subway' THEN 'SWY' WHEN Cust.CustomerName = 'Oishi' THEN 'OIS' WHEN Cust.CustomerName = 'Shell' THEN 'SHE' WHEN Cust.CustomerName = 'FSB' THEN 'FSB' WHEN Cust.CustomerName = 'Ikea' THEN 'IKE' WHEN Cust.CustomerName = 'Yellow Cab' THEN 'YEL' WHEN Cust.CustomerName = 'PUB' THEN 'PUB' ELSE '' END, '""') +'|'+cast(round(k1.[Value], 0) as varchar) +'|'+'0' -- Tonnage Delivered, assume 0 for now +'|'+cast(k2.[VALUE] as varchar) +'|'+cast(k3.[VALUE] as varchar) +'|'+cast(k4.[VALUE] as varchar) +'|'+'0' -- Deliveries with error, assume 0 for now +'|'+cast(k5.[VALUE] as varchar) +'|'+cast((round(k9.[VALUE]+k1.[VALUE],0)) as varchar) +'|'+cast(round(k7.[VALUE],0) as varchar) +'|'+'0' -- Tonnage Handled, assume 0 for now +'|'+cast(round(k8.[VALUE],0) as varchar) +'|'+'20151130' +'|'+'20151206' FROM [KeyPerformance].[dbo].[KpiDetails] as k1, [KeyPerformance].[dbo].[KpiDetails] as k2, [KeyPerformance].[dbo].[KpiDetails] as k3, [KeyPerformance].[dbo].[KpiDetails] as k4, [KeyPerformance].[dbo].[KpiDetails] as k5, [KeyPerformance].[dbo].[KpiDetails] as k6, [KeyPerformance].[dbo].[KpiDetails] as k7, [KeyPerformance].[dbo].[KpiDetails] as k8, [KeyPerformance].[dbo].[KpiDetails] as k9, [KeyPerformance].[dbo].[KpiHeader] as h1, [KeyPerformance].[dbo].[Customer] as Cust, [KeyPerformance].[dbo].[Location] as Loc, [KeyPerformance].[dbo].[Country] as Cty, [KeyPerformance].[dbo].[CalendarWeekOfYear] as Cal where k1.[KpiHeaderID] = k2.[KpiHeaderID] AND k2.[KpiHeaderID] = k3.[KpiHeaderID] AND k3.[KpiHeaderID] = k4.[KpiHeaderID] AND k4.[KpiHeaderID] = k5.[KpiHeaderID] AND k5.[KpiHeaderID] = k6.[KpiHeaderID] AND k6.[KpiHeaderID] = k7.[KpiHeaderID] AND k7.[KpiHeaderID] = k8.[KpiHeaderID] AND k8.[KpiHeaderID] = k9.[KpiHeaderID] AND k1.[KpiHeaderID] = h1.[KpiHeaderID] AND h1.[CustomerID] = Cust.[CustomerID] AND h1.[LocationID] = Loc.[LocationID] AND Loc.[CountryID] = Cty.[CountryID] AND h1.[WeekNum] = Cal.WeekOfYear AND h1.[Year] = Cal.Year -- AND k1.[KpiHeaderID] = 122 AND k1.[KpiItemsID] = 2 AND k2.[KpiItemsID] = 1 AND k3.[KpiItemsID] = 9 AND k4.[KpiItemsID] = 10 AND k5.[KpiItemsID] = 31 AND k6.[KpiItemsID] = 2 AND k7.[KpiItemsID] = 18 AND k8.[KpiItemsID] = 11 AND k9.[KpiItemsID] = 3 AND h1.Year = '2015' and Cal.WeekofYear = 48 --AND Cal.MonthID = 11; SQL;(huh. okay. pretend there's appropriate highlighting) Doing that would have completely bypassed the quotes problem.
  15. 1. Just post code normally. With the code highlighting. Most people don't bother looking at attachments. 2. Don't post database credentials. Stop what you're doing and go change your password. Right now. $query =" //set NOCOUNT ON /*optional*/ SELECT cast(h1.Weeknum AS varchar) +'|' +cast(h1.Year AS varchar) +'|' +QUOTENAME(CASE WHEN Cty.CountryName = 'Singapore' THEN 'SG' WHEN Cty.CountryName = 'Hong Kong' THEN 'HK' WHEN Cty.CountryName = 'Japan' THEN 'JP' WHEN Cty.CountryName = 'China' THEN 'CN' WHEN Cty.CountryName = 'Indonesia' THEN 'ID' WHEN Cty.CountryName = 'Taiwan' THEN 'TW' WHEN Cty.CountryName = 'Thailand' THEN 'TH' WHEN Cty.CountryName = 'Philippines' THEN 'PH' WHEN Cty.CountryName = 'Macau' THEN 'MO' WHEN Cty.CountryName = 'Malaysia' THEN 'MY' ELSE '' END , '""') +'|' + QUOTENAME(Loc.LocationName,'"') +'|' +QUOTENAME(CASE WHEN Cust.CustomerName = 'McDonalds'THEN'MCD' WHEN Cust.CustomerName = 'Subway' THEN 'SWY' WHEN Cust.CustomerName = 'Oishi' THEN 'OIS' WHEN Cust.CustomerName = 'Shell' THEN 'SHE' WHEN Cust.CustomerName = 'FSB' THEN 'FSB' WHEN Cust.CustomerName = 'Ikea' THEN 'IKE' WHEN Cust.CustomerName = 'Yellow Cab' THEN 'YEL' WHEN Cust.CustomerName = 'PUB' THEN 'PUB' ELSE '' END, '""') +'|'+cast(round(k1.[Value], 0) as varchar) +'|'+'0' -- Tonnage Delivered, assume 0 for now +'|'+cast(k2.[VALUE] as varchar) +'|'+cast(k3.[VALUE] as varchar) +'|'+cast(k4.[VALUE] as varchar) +'|'+'0' -- Deliveries with error, assume 0 for now +'|'+cast(k5.[VALUE] as varchar) +'|'+cast((round(k9.[VALUE]+k1.[VALUE],0)) as varchar) +'|'+cast(round(k7.[VALUE],0) as varchar) +'|'+'0' -- Tonnage Handled, assume 0 for now +'|'+cast(round(k8.[VALUE],0) as varchar) +'|'+'20151130' +'|'+'20151206' FROM [KeyPerformance].[dbo].[KpiDetails] as k1, [KeyPerformance].[dbo].[KpiDetails] as k2, [KeyPerformance].[dbo].[KpiDetails] as k3, [KeyPerformance].[dbo].[KpiDetails] as k4, [KeyPerformance].[dbo].[KpiDetails] as k5, [KeyPerformance].[dbo].[KpiDetails] as k6, [KeyPerformance].[dbo].[KpiDetails] as k7, [KeyPerformance].[dbo].[KpiDetails] as k8, [KeyPerformance].[dbo].[KpiDetails] as k9, [KeyPerformance].[dbo].[KpiHeader] as h1, [KeyPerformance].[dbo].[Customer] as Cust, [KeyPerformance].[dbo].[Location] as Loc, [KeyPerformance].[dbo].[Country] as Cty, [KeyPerformance].[dbo].[CalendarWeekOfYear] as Cal where k1.[KpiHeaderID] = k2.[KpiHeaderID] AND k2.[KpiHeaderID] = k3.[KpiHeaderID] AND k3.[KpiHeaderID] = k4.[KpiHeaderID] AND k4.[KpiHeaderID] = k5.[KpiHeaderID] AND k5.[KpiHeaderID] = k6.[KpiHeaderID] AND k6.[KpiHeaderID] = k7.[KpiHeaderID] AND k7.[KpiHeaderID] = k8.[KpiHeaderID] AND k8.[KpiHeaderID] = k9.[KpiHeaderID] AND k1.[KpiHeaderID] = h1.[KpiHeaderID] AND h1.[CustomerID] = Cust.[CustomerID] AND h1.[LocationID] = Loc.[LocationID] AND Loc.[CountryID] = Cty.[CountryID] AND h1.[WeekNum] = Cal.WeekOfYear AND h1.[Year] = Cal.Year -- AND k1.[KpiHeaderID] = 122 AND k1.[KpiItemsID] = 2 AND k2.[KpiItemsID] = 1 AND k3.[KpiItemsID] = 9 AND k4.[KpiItemsID] = 10 AND k5.[KpiItemsID] = 31 AND k6.[KpiItemsID] = 2 AND k7.[KpiItemsID] = 18 AND k8.[KpiItemsID] = 11 AND k9.[KpiItemsID] = 3 AND h1.Year = '2015' and Cal.WeekofYear = 48 --AND Cal.MonthID = 11;"You have unescaped "s within that string.
  16. First, the condition should have been $x because $dep[$max] is one too far since the array keys will be 0 through $max-1. What he said. The problem is the loop is going too far, right? So don't make it go that far. for ($x = 0; $x and then output the final lat/long pair since the loop didn't reach it.
  17. Sure. Just keep in mind that buying pink tennis balls could mean the user has a dog, car fluid could mean they have a lawnmower, and baby cream could mean they use moisturizing cream. Profiling is nice but only if you get it perfectly right, otherwise you start thinking a 70 year old man is a young single mother. My take after, like, 5 minutes of thought: Store in the database a list of different profiles: woman, sports, dog owner, etc. Each one is tied to a particular PHP class*, implying that testing or invoking the profile will run the code. Then store another list of items with profiles: pink tennis balls -> woman, pink tennis balls -> sports, pink tennis balls -> dog owner, etc. Each class follows a particular interface. interface IProfiledItem { public function __construct(Item $item); public function evaluate(ShoppingCart $cart); }Adding an item fires up the code and has the class decide whether it's an appropriate profile according to the cart. Eventually you've gathered up a bunch of (potential) profiles. * The code approach is faster but takes more effort to maintain over time. Long term, I'd probably try to put much more information in the database so more work can be generalized (eg, "profile A + profile B = profile C" or "item D suggests profile E at 50% and profile F at 20%").
  18. That's not IPN. If $insert_row = $mysqli->query("INSERT INTO BuyerTable (BuyerName,BuyerEmail,TransactionID,ItemName,ItemNumber,ItemAmount) VALUES ('$buyerName','$buyerEmail','$TransactionID','$ItemName','$ItemNumber', '$ItemTotalPrice')");is not executing properly then it means (a) code never reached that statement to begin with or (b) the query failed. You don't really do any logging in there. Add some: log when certain lines are reached, log assorted interesting values, log error messages from MySQL if they come up, log stuff. And test until you figure out precisely what went wrong. Couple obvious things to check out first: 1. Can't connect to the database - probably because you're using default values for the host and username/password. 2. One or more of the values you're trying to insert contain apostrophes which is why your code is vulnerable to SQL injection. Use prepared statements instead of putting values directly in queries like you're doing now.
  19. A single equals sign means comparison; @cum=0 would be saying "is @cum equal to 0". Colon+equals does assignment and will set @cum to 0 in the first part and then add profit in the second part. And yes, the init part is working like the init part in a for loop. for ($cum = 0; ; $cum = $cum + $profit) {You could do the assignment in a separate query beforehand SELECT 0 INTO @cumwhich would be like $cum = 0; for (; ; $cum = $cum + $profit) {
  20. You can put gallery.php anywhere you want. In the main folder makes the most sense. I'm making a couple changes: RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z0-9_-]+)/?$ profile.php?username=$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^gallery/([a-zA-Z0-9_-]+)/?$ gallery.php?username=$1 [L]1. Note the two (pairs of) RewriteConds: they make sure that you don't accidentally rewrite from an existing file or (more likely) directory.2. Most of the time you should use the [L] flag so that when one rewriting rule matches it will stop processing the rest of the rules and immediately go with the new URL you told it to use. And a suggestion: decide whether you want to officially have trailing slashes or not - don't do both. You can still redirect from one to the other, of course. Something like RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ $1 [L,R=301]should be able to handle redirecting away from a trailing slash for pretty much anything you have. Directories still need the trailing slash so those aren't affected.
  21. Because it isn't using a variable in the first place. All you did was make a string that contains an apostrophe, the word "jobno", another apostrophe, a period, and "xslx". If you want a variable in there then put a variable in there. if (!isset($_POST["jobno"])) { // error: value missing } else if ($_POST["jobno"] == "") { // error: empty value } else if (!ctype_digit($_POST["jobno"])) { // replace with whatever validation you need // error: invalid jobno } else { $jobno = $_POST["jobno"]; } // ... $objWriter->save($jobno . ".xlsx");
  22. Step 0: Fix your HTML and code. - Use type="text/javascript"s on <div id="map_canvas"></div> <div id="map_canvas2"></div>Step 2: Make sure your initialization code can work with particular elements and does not (eg) cause output when executed. Your function already does that with the param1 parameter. Step 3: Exactly what you do here varies by how you want to do it. You said something about the number of maps varying? Then I suggest making your page look like <div id="map_canvas_0"></div> <script type="text/javascript">initialize("map_canvas_0", 51.5403, -2.5463);</script>Repeat that sort of thing for each map to display. "But that doesn't follow the best practice of everything being just before the closing !" True, but the purpose of the best practice is (a) to keep code in a logical place and not scattered around the document and (b) because you can't run code immediately if it uses an element defined later down the page. Reasons behind my suggestion: - Lends itself to being generated in a loop - Puts the code and the map container in very close proximity to each other - initialize() does not set up the map immediately but on load (as it should be) The end result is basically <html> <head> ... <script src="https://maps.googleapis.com/maps/api/js"></script> <script type="text/javascript"> function initialize(canvas, lat, long) { $(function() { // for jquery. use whatever method to cause the function to be executed only after page/DOM load var mapCanvas = document.getElementById(canvas); var mapOptions = { center: new google.maps.LatLng(lat, lng), zoom: 17, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(mapCanvas, mapOptions); }); } </script> </head> <body> <div id="map_canvas_0"></div> <script type="text/javascript">initialize("map_canvas_0", 51.5403, -2.5463);</script> <div id="map_canvas_1"></div> <script type="text/javascript">initialize("map_canvas_1", 41.5403, -2.5463);</script> </body> </html>
  23. Great. Then. Get PHPMailer, write code to send an email according to their documentation, and then use that if block you have to set the right To: address.
  24. So is your question about how to send emails? Get yourself a copy of PHPMailer and read through their documentation. It's pretty easy to use.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.