Jump to content

requinix

Administrators
  • Posts

    15,053
  • Joined

  • Last visited

  • Days Won

    413

Everything posted by requinix

  1. Possible? Sure. Though I'm not sure I understand what you want. Someone enters an email in a form and you send them a random color, code, and place? You're probably not using a database for anything. Make three files, each one with a different color, code, or place on each line. Then the PHP code picks a random line from each file and sends an email with them. Expensive? Depends what you consider to be expensive. It should take less than an hour for a knowledgeable PHP developer to do this.
  2. Use SimpleXML. Example: $xml = new SimpleXMLElement("URL", 0, true); foreach ($xml->property as $property) { // $node["key"] for attributes $reference = (string)$property["reference"]; // $node->name for sub nodes $type = (string)$property->property_type; $street = (string)$property->street; // multiple elements are accessed by their shared name $rooms = count($property->rooms->room); // room is basically an array of <room>s echo "Property {$reference} is a {$type} on {$street} with {$rooms} room(s).\n"; }
  3. If there are any redirections then it should be easy to spot: go to one domain, see if you're redirected to another domain. But if you don't have those redirections then you'll suffer with SEO: having four domains with the same content is not good. You should pick one and go with it, either by redirecting everyone to it or using a rel=canonical to point to the "main" domain's version of the page. Either way, though, search engines will only show one of the sites in their search results. Varying the image on www or non-www domains is... silly. I have no idea why you would want to do that. Varying by .co.uk or .com? Sure. But that sounds like an internationalization thing, and those kinds of issues are handled differently than showing the same site on multiple domains.
  4. What's the rest of the code? The stuff between the query you posted and where you output the date.
  5. Link to an online assignment? Picture of the homework? Something that proves you're not some evil person trying to create an actual phishing website. No offense, but you're new here and this wouldn't be the first time someone's asked for help with something criminal. Not using a proxy would be nice too. (if you don't want it public then you can IM it to me - which you should be able to do so let me know if not)
  6. The time is in there too. Are you sure the dtDate field is a DATETIME and not just a DATE?
  7. 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}'>
  8. 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.
  9. Uh, what? We're going to need to see some proof of that if you want help.
  10. 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.
  11. if (mysql_num_rows($q)>0) { echo $boja1; } else { echo $boja2; }Or maybe I don't understand the question?
  12. 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...
  13. 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.
  14. 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...
  15. What's the code for init_session()?
  16. Then rearrange the code so you determine the $mainNav before the header gets included.
  17. 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.
  18. How are you doing the replace? What's the rest of the code?
  19. 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.
  20. 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.
  21. 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.
  22. 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%").
  23. 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.
  24. 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) {
×
×
  • 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.