-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
Adding two columns of different rows
kicken replied to Pradeep_Chinna's topic in Microsoft SQL - MSSQL
As you loop through the result set, add the amount for the current row to a total variable and save that variable to the row. eg: $total = 0; $allRows = array(); while ($row=$result->fetch()){ $total += $row['amount']; $row['total'] = $total; $allRows[] = $row; } Then when you output the data in your table you'll have the total field in each row to output. -
A friend of mine was recently nearly duped by a scam. He asked me for some money and when I asked why he was telling me about how he'd been chatting with this girl online who was stuck in Nigeria and wanted him to send some money so she could get out. Some sob story about how her and her boyfriend went there for their vacation then he ran off and left her there with nothing. I stumbled across some police reports from my home town the a few weeks back also and there was one report about some guy who actually had sent some money to one of these scams and then filed a complaint after he stopped getting replies back. I'm always amazed that people fall for this stuff too, but apparently it still happens.
-
Yes, you need to send back a proper 404 response status otherwise google and other bots will see it as a normal web page and index it as such.
-
Use something like Markdown. There are libraries for it and it's relatively popular so the syntax will be more likely to be known by people.
-
MOUSE SCROLLING WEHN USING THIS PHP CODE. (VERSION 2)
kicken replied to rleahong's topic in PHP Coding Help
My best guess at what you mean by the mouse is scrolling is that you get a busy cursor like the application froze. Beyond that I don't really have any idea what you mean. I see you are doing queries within loops which you should not be doing, use a JOIN instead. Perhaps that will solve your problem. -
Untested, but something like this would keep it simple. <?php if($dirHandler = opendir($images_dir)){ $regex = '#^(\d{4})-\d+\.(jpeg|jpg)$#i'; while(false !== ($file = readdir($dirHandler))){ if (!preg_match($regex, $file, $m)) continue; $files[$m[1]][] = $file; } } krsort($files, SORT_NUMERIC); foreach($files as $year=>$list){ echo '<div class="'.$year.'_div">'; natsort($list); foreach ($list as $file){ echo '<div class="thumb"><a href="' . $images_dir . '/' . $file . '"><img src="' . $images_dir.'/thumb/' . $myFile . '"></a></div>'; } echo '</div>'; } } ?> The files get grouped by year as they are read, then the years are sorted in descending order using krsort.
-
kicken@web1:~$ php <?php $mylink = 'http://www.myntra.com/sales?nav_id=1#!sortby=PRICEA'; echo urlencode($mylink); ?> http%3A%2F%2Fwww.myntra.com%2Fsales%3Fnav_id%3D1%23%21sortby%3DPRICEA The # is still there, it's just been encoded as %23. As I said, var_dump your variable to verify what it actually contains. If the # and everything after it are infact missing, then you need to revisit my first point: Make sure you urlencode() your values before putting them into a link or header redirect so that special characters such as # are not mis-interpreted.
-
You're missing the $ on your variable name.
-
Works fine for me, so either you're still leaving out some information, or you fixed it during posting. var_dump your $mylink variable to make sure it contains what you expect. Make sure you are not making any typos such as a case-mismatch ($mylink vs $myLink for example).
-
outputs: 29 So your example works perfectly fine. Going on an assumption that you are trying to identify the # in the current url (ie, $_SERVER['REQUEST_URI']) then your problem is that the hash portion of the URL (the # and everything after it) is not sent to the server as it's strictly for client-side use. When the above example is requested the actual request made to the server is only for /sales?nav_id=1 and then once the page is loaded the browser interprets the #!sortby=PRICEA portion.
-
PHP, MySqli comparing and displaying results
kicken replied to skygremlin's topic in PHP Coding Help
Do the comparison in your template when you generate the table. <?php foreach ($result as $row): ?> <tr> <td>..</td> <td <?php if ($row['expenses']>$row['payments']): ?>style="background: red;"<?php endif; ?>><?=$row['expense']?></td> <td <?php if ($row['payments']>$row['expenses']): ?>style="background: red;"<?php endif; ?>><?=$row['payments']?></td> </tr> <?php endforeach; ?> -
The number 2 does not need to be encoded. Only special characters / high-order characters need to be encoded. Also there is no need to decode the URL. PHP does that automatically when it parses the variables out. So on your receiving page you'd just do $_GET['code'] like normal.
-
Sending emails in a foreach loop. Best way to do this?
kicken replied to eMonk's topic in PHP Coding Help
If you're going to include their login and password in the email, then you have to send out individual emails since each email needs to be customized for the target recipient. -
You're mixing mysqli_* and mysql_* functions, you can't do that. Since your initial connection is mysqli, you will want to change your mysql_real_escape_string and mysql_query functions to the mysqli_ equivalents.
-
Use json_encode when outputting variables: $(function() { // validate signup form on keyup and submit $("#loginform").validate({ rules: { user: "required", password: "required", }, messages: { user: <?php echo json_encode($lang['login_error']); ?>, password: "Please enter your password", } }); }); This is assuming your JS is within the PHP page. If it's in a separate .js file you'll need to either make the JS file parsed by PHP or possibly load the messages w/ ajax or similar.
- 5 replies
-
- php
- javascript
-
(and 3 more)
Tagged with:
-
You can use several if's like you showed, but it will not necessarily do as you intended. When you do several if's as shown, then they are all evaluated independantly. Depending on what the condition is that you check, it may emulate the same behaviour as using elseif. When you use elseif, then everything is treated as a single block so only one of the if statements (or else block) can be evaluated, all others are skipped. Take for example: $x = 52; if ($x < 100){ echo '< 100'; } else if ($x < 75){ echo '< 75'; } else if ($x < 50){ echo '< 50'; } else { echo 'None of the above'; } The output of that would be '< 100'. Since that if condition matches, all other elseif's and the else block are skipped. If however you wrote them as separate statements such as $x = 52; if ($x < 100){ echo '< 100'; } if ($x < 75){ echo '< 75'; } if ($x < 50){ echo '< 50'; } else { echo 'None of the above'; } You would get the output '< 100< 75None of the above' since each if is evaluated separately. The first if passes, the second if passes, the third doesn't pass so it's associated else block gets executed.
-
Just gotta dig around in the source code for a few minutes. Then you would have been lead to the Isotope plugin
-
You need to make sure the PDF file itself is served with the proper no cache headers, which means either modifying the server config or serving the file via PHP. Another option is the append a query string to the pdf url that changes each time (or at minimum when the pdf is changed). A random number, or the pdf file's last modified date would work for this.
-
To expand on why it did not work with method="get" (which it would have defaulted to when you had the invalid _GET value), it is because any query string that is part of the form's action is stripped and replaced with the contents of the form fields upon submit. They are not merged together as you seemed to expect. Basically, when your form is a GET form, your ACTION cannot contain any query string parameters. Any such parameters you want to have passed need to be converted to hidden inputs: <form method="get" action="index.php"> <input type="hidden" name="p" value="r"> Such a restriction does not apply when using the POST method, since the form data is sent via the body of the request not the URL.
-
Using ftp_fget to output the file directly may work. Something like: header('Content-type: text/plain'); //Whatever headers you need to send $outfile = fopen('php://output', 'w'); ftp_fget($ftp, $outfile, 'the_file.txt', FTP_BINARY);
-
$_REQUEST[ ] works right, but is not running the query
kicken replied to jParnell's topic in PHP Coding Help
if ($email && $name && $password && $password && $earned) That tests that each of those values has a truthy value, ie something that is considered to be true if converted to a boolean value. "0" is considered to be false if converted to a boolean value, hence your test fails when you enter 0 for earned. If you want to check if the values were posted, you should be using isset on the original $_REQUEST variables. -
Google seems to agree with PHP: 2.82332938169 I think you are either entering the formula incorrectly in your calculator, or you are translating it to PHP incorrectly. The answer you are expecting to get would be given by: 0.4723*pow(7.73, 0.8015);
-
How to force slideToggle to open or close all...
kicken replied to joetaylor's topic in Javascript Help
Use a class to indicate the state of the toggle. Based on whether that class exists or not you can determine whether you want to slideUp or slideDown. var toggle_switch = $(this); if (toggle_switch.is('.expanded')){ $(collapse_content_selector).slideUp(150, function(){ toggle_switch.text('[x] Expand All').removeClass('expanded'); }); } else { $(collapse_content_selector).slideDown(150, function(){ toggle_switch.text('[x] Collapse All').addClass('expanded'); }); } -
Unless the two lists are going to be showing the same poems, then you'd probably want two queries anyway. Your top-rated poem may not part of the top 12 newest poems, and would be excluded by that query. So do another second query that will grab the top rated poems and read those results into another array. Note that it's generally easier to keep things confined to one array rather than make separate arrays for each column like you are currently doing. What you'd do is create a multi-dimensional array where the first level represents each row, and the second level each column. It's easily done like so: $newestPoems = array(); while ($row=mysql_fetch_assoc($query)){ $newestPoems[] = $row; } var_dump($newestPoems); Also, take notice of the big warning on the top of the mysql_query manual page. You need to stop using the mysql_* functions and move to PDO or mysqli_*