-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
Is compressed code considered "source code" for licensing purposes?
kicken replied to jhsachs's topic in Javascript Help
I'd say the clause "redistribute the source code." is probably just from someone using a generic license intended to be used with compiled software. In terms of non compiled software such as JS, the intent would probably be more along the lines of you can use it, but you can't offer up the JS code alone, such as say in a "free scripts" type of site. Only the author could really give you a definite answer as to what they intend though. Only an attorney could tell you what your legally allowed to do with the stated license terms. -
Without seeing the code behind it, can't really say much about why you see what you do. If you php script doesn't hold the socket open, probably it's being closed before the handshake can be sent. Such as if your doing like $client = socket_accept($server); socket_close($client); //or just ending script the socket will open then close immediately, without giving a chance for anything to be sent.
-
I take it that means there is HTML above this block of PHP code? You can't call session_start after you have sent output (which includes anything, even blank space) which is outside of <?php ?> tags. Reason is session-start() has to send headers for the cookie, and sending output causes the headers to be sent which means you can't send any new headers after that point. You need to move your processing code to be at the top of the script, before any other output. see also, the sticky on header errors
-
Your error is not because your calling nameGen from within nameGen. That is perfectly legal (but you need to be careful not to cause an endless loop). Your problem is because your declaring the function nameGen inside of a for loop, so on the first iteration of that loop it declares the function. On the second iteration it attempts to declare it again, but it's already been declared so you receive that error. Move the function declaration out of the for loop, then just call it from inside the loop.
-
Do one query that returns the data you need, then group it in php for display. ex a query like select * from customers inner join orders on customers.customerNumber=orders.customerNumber order by customers.customerNumber then process it like: $customers=array(); while ($row=/*fetch row*/){ $custNo = $row['customerNumber']; if (!isset($customers[$custNo])){ $customers[$custNo]=array( 'name' => $row['customerName'], /* .. other customer info fields */ 'orders' => array() ); } $customers[$custNo]['orders'][] = $row; } print_r($customers);
-
Don't know if they are using this, but this is how one would change the url without reloading the page: MDN: Manipulating the browser history
-
You want: $qry = "SELECT LAST_INSERT_ID() as newId"; $res = mysql_query($qry); $row = mysql_fetch_assoc($res); //now $row['newId'] holds your value
-
Assuming your server is properly configured to execute PHP files (rather than serve them as is), none of your actual PHP code (including PHP comments) will be visible to the end user.
-
You can try doing a HEAD request with get_headers() and then find the Content-Length: header. If that fails you can fall back to a file_get_contents/strlen() combo to get the size.
-
Are there any client side Socket libraries for Javascript?
kicken replied to FalseProphet's topic in Javascript Help
Not quite like what you'd get in say PHP or another language, but they are closer than anything else one could do with just Javascript. I'm not sure what kind of abilities Flash has for sockets, never used it. Websockets need a special type of server to listen but there are projects out there that you can use to 'websock-ify' a protocol so that you can connect to it via a websocket through a proxy program. -
Are there any client side Socket libraries for Javascript?
kicken replied to FalseProphet's topic in Javascript Help
Socket.IO There's a new spec for Websockets, but support for it is a bit lacking right now. The Socket.IO library above provides compatibility and work arounds for browsers that do not support WebSockets natively. -
Another option is to use a case clause to convert the days to a number. Still not great, ideally you would store the day as a number, then convert it to a textual date for display, rather than the other way around (assuming you can't use an actual datetime value for some reason) SELECT day, end_time, CASE 'Tuesday' WHEN 'Sunday' THEN 0 WHEN 'Monday' THEN 1 WHEN 'Tuesday' THEN 2 WHEN 'Wednesday' THEN 3 WHEN 'Thursday' THEN 4 WHEN 'Friday' THEN 5 WHEN 'Saturday' THEN 6 END as dayNum FROM blah ORDER BY dayNum, end_time
-
I'm assuming $APIcall is the URL that you need to access and then get the results? Use file_get_contents() to access the URL and download the results (regardless of if it is text or xml). If it is an XML response, then do further processing with simplexml_load_string().
-
while($zip_entry = zip_read($zip) && $i<500 ){ That does not do what you expect. The condition is run such as $zip_entry = (zip_read($zip) && $i<500), in other words $zip_entry will be assigned the result of the && condition, which is going to be either bool(true) or bool(false). You need to put parenthesis around the assignment to make sure it is run correctly. while(($zip_entry = zip_read($zip)) && $i<500 ){
-
Aside from an error which should be shown provided your error_reporting and display_errors settings are correct, the only other real explanations would be - One of the files is calling exit; or die; and killing the process - One of the files is throwing an exception which is being caught somewhere but not reported.
-
while($query_row = mysql_fetch_assoc($query_run) && $counter <= 2) That does not do what your expecting. $query_row is going to be assigned the results of the && operation, not the return value of mysql_fetch_assoc(). So $query_row is going to be either bool(true) or bool(false), not an array with the row content. To fix it, put parenthesis around the assignment: while(($query_row = mysql_fetch_assoc($query_run)) && $counter <= 2)
-
Is there a way to not print Headers and Footers?
kicken replied to Matt Ridge's topic in PHP Coding Help
You could have your script generate a PDF and then print that rather than printing a traditional web page. I don't believe the headers/footers are added in that case. -
I like the Proggy Clean set of fonts. Particularly the ones with the bold punctuation marks.
-
You can do a refresh header too: header('Refresh: 10; url=http://url/'); Pretty much the same as the meta tag. Latest IE, Chrome, and Firefox all support it.
-
I don't know about better, but this is the way I code things like the example given: $numbers = array(); function draw() { return rand(1,59); } while (count($numbers) < 6){ do { $new = draw(); } while (in_array($new, $numbers)); $numbers[] = $new; } var_dump($numbers); @UrbanDweller functions don't care where they are called from, they still work the same. when you call a function the code jumps there, runs through the function, then jumps back to where it was called from at the end/return of the function.
-
When you open the file in mode 'r', the only thing you can do is read from it. When you need to write to it (such as with fputcsv) you need to use a writable mode such as 'a' or 'w'. So in your page, when you reading the file for display, fopen in 'r' mode, read the file, and close it. When your adding data with fputcsv, fopen in 'a' mode, write the data, then close it. Also, you have a $ on your fputcsv function that should not be there.
-
mysql_query returns a result resource, not the actual result. To get the field value you need to call mysql_fetch_array() and then pull the column out of that array. $res = mysql_query('SELECT IDCOL FROM prods ORDER BY IDCOL DESC LIMIT 1'); $row = mysql_fetch_array($res); $newid = $row['IDCOL'];
-
Do one loop across the $sums array, storing the key and value in separate variables. Then for each of those elements loop through the items array searching for an item with an order index that matches the current sum's key. When you find one, compare the price indexes and show an error if necessary. If you don't find one, show an error. <?php function check_items($sums,$items){ //$orderNum will be the key, ex '23' //$sumInfo will be the array values foreach ($sums as $orderNum=>$sumInfo){ //Find an item with ['order']=$orderNum; $found=false; foreach ($items as $itemName=>$itemInfo){ if ($itemInfo['order'] == $orderNum){ $isGreater = $itemInfo['price'] > $sumInfo['collected']['price']; $found=true; } } if (!$found || !$isGreater){ //error } } }
-
Post name 'notes' is skewed during actual post
kicken replied to n1concepts's topic in PHP Coding Help
I'd guess your problem isn't that your $_POST['notes']/$post_data['notes'] is wrong, but rather that your just not displaying it right when you output it. ¬ is the entity name for the character your seeing (see http://www.w3.org/TR/html4/sgml/entities.html#h-24.2.1) When you output your imploded string, your generating the output something like 'last_name=kicken¬es=bleh', your browser is likely interpreting that ¬ sequence as the entity name. You need to run your string through htmlentities() first so the & gets output as & (the entity for &) and the browser displays it correctly. Tip, use your browser's View-Source function, you'll see what you expect, rather than the funky character. -
Use count_chars and array_diff <?php $a = 'abcDEF'; $b = 'EcFabD'; $aChars=count_chars($a, 1); $bChars=count_chars($b, 1); if ($aChars==$bChars){ echo "Strings match"; } else { echo "No match"; } [edit] No need for the array stuff aparently