Re: [PHP] Re: Simple PHP setting arrays with keys question
Dan skrev: Oh yeah, the problem isn't that I'm using - instead of =. Well that was a problem but I fixed that and it's still not working. - Dan Dan [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm having a little problem assigning a value to an array which has a key. It's simple, I just don't know what I'm doing wrong. foreach($Checkout as $value) { $products[] = $value['productName'] - $value['actualValue']; } HELP! either: $products[$value['productName']] = $value['actualValue']; OR $products[] = array( $value['productName'] = $value['actualValue'] ); -- /Thunis I think you ought to know I'm feeling very depressed. --The Hitchikers Guide to the Galaxy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Simple PHP setting arrays with keys question
Jim Lucas wrote: Fredrik Thunberg wrote: Dan skrev: Oh yeah, the problem isn't that I'm using - instead of =. Well that was a problem but I fixed that and it's still not working. - Dan Dan [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm having a little problem assigning a value to an array which has a key. It's simple, I just don't know what I'm doing wrong. foreach($Checkout as $value) { $products[] = $value['productName'] - $value['actualValue']; } HELP! either: $products[$value['productName']] = $value['actualValue']; OR $products[] = array( $value['productName'] = $value['actualValue'] ); But these are not the same... I never said that they we're. Just wanted to show what he could do. :) /T -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A very strange loop!
For exactly the same reason as for( $i = 0; $i 10; $i++) produces 0-9 It loops whule $i is lesser than 'Z' When $i becomes 'Z' it stops and doesn't echo But i guess you're having trouble with (note the '='): for ($i = 'A'; $i = 'Z'; $i++) { echo $i . ' '; } This might produce a wierd result. This is because when $i is 'Z' and $i++ is run $i become 'AA' And: 'AA' 'Z' So it loops until $i becomse 'ZA'. Xell Zhang skrev: Hello all, I met a very strange problem today. Take a look at the codes below: for ($i = 'A'; $i 'Z'; $i++) { echo $i . ' '; } If you think the output is A-Z, please run it on your server and try. Who can tell me why the result is not A-Z? -- /Thunis This must be Thursday, said Arthur musing to himself, sinking low over his beer, I never could get the hang of Thursdays. --The Hitchikers Guide to the Galaxy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A very strange loop!
No, that won't work Either use != 'AA' or for( $i = ord('A'); $i = ord('Z'); $i++) { echo chr( $i ) . ' '; } Jason skrev: Because you need $i= 'Z' to get Z included as well. J At 08:49 09/07/2007, Xell Zhang wrote: Hello all, I met a very strange problem today. Take a look at the codes below: for ($i = 'A'; $i 'Z'; $i++) { echo $i . ' '; } If you think the output is A-Z, please run it on your server and try. Who can tell me why the result is not A-Z? -- Zhang Xiao Junior engineer, Web development Ethos Tech. http://www.ethos.com.cn -- /Thunis Why do you need to think? Can't we just sit and go budumbudumbudum with our lips for a bit? --The Hitchikers Guide to the Galaxy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: spliting the elements in array
Stut skrev: sivasakthi wrote: Thanks for your response.. Actually i have the collections of strings like, $not_quite_an_array = 'squid %tu %tl %mt %A test %st.%hs %a %m %tu %th %Hs %Ss test1 %tv %tr %Hs.%Ss %mt'; from that i need to split name of each line.. $names = array(); foreach (explode(\n, $not_quite_an_array) as $line) { $line = trim($line); if (strlen($line) == 0) continue; $names[] = array_shift(explode(' ', $line, 2)); } -Stut Or: $result = preg_match_all(/\s*([^\s]+)(?:\n|.*)/, $not_quite_an_array, $out); $names = array_pop( $out ); -- /Thunis I think you ought to know I'm feeling very depressed. --The Hitchikers Guide to the Galaxy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Calculation Help
$q = ceil( month / 4 ); -- /Thunis The ships hung in the sky in much the same way that bricks don't. --The Hitchikers Guide to the Galaxy revDAVE skrev: I have segmented a year into four quarters (3 months each) nowdate = the month of the chosen date (ex: 5-30-07 = month 5) Q: What is the best way to calculate which quarter (1-2-3 or 4) the chosen date falls on? Result - Ex: 5-30-07 = month 5 and should fall in quarter 2 -- Thanks - RevDave [EMAIL PROTECTED] [db-lists] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Calculation Help
of course ceil( month / 3 ); -- /Thunis Don't panic. --The Hitchikers Guide to the Galaxy Fredrik Thunberg skrev: $q = ceil( month / 4 ); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] shuffle or mt_rand
snip Just did a quick benchmark for 10.000 hands (making a full deck on your code, 23.5 players): Microtime difference: Ryan's code:15.725826978683 Tijnema's code:0.40006709098816 Unique decks out of 1: Ryan's code:1 Tijnema's code:1 When making a full deck my code is 40 times faster, and a lot less memory intensive. And as you can see, for both all 1 decks are unique, so both are random :) But, also when generating cards for only 4 players, my code is twice as fast as yours, and both generate still 1 random decks: Microtime difference: Ryan's code:0.82403707504272 Tijnema's code:0.40426802635193 Unique decks out of 1: Ryan's code:1 Tijnema's code:1 Tijnema Just a pointer: Just because you get 1 different decks doesn't mean that it is random. Since there are 52! (around 8*10^67) different decks and you choose 1 of theese you would be very lucky to get 2 that are the same. -- /Thunis I refuse to answer that question on the grounds that I don't know the answer. --The Hitchikers Guide to the Galaxy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date
Ron Piggott skrev: How do I break $start_date into 3 variables --- 4 digit year, 2 digit month and 2 digit day? $start_year = ; $start_month = ; $start_day = ; Of course depending on what $start_date looks like, but this should work most of the time: $timestamp = strtotime( $start_date ); $start_year = date( Y, $timestamp ); $start_month = date( m, $timestamp ); $start_day = date( d, $timestamp ); /T -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Limit query results
GROUP BY whatever_id_you_want in the SQL Dan Shirah skrev: Good Morning everyone. In the below code I am pulling records from two tables. the records are tied together by a common key in a 3rd table. Everything works correctly down to the $result. // Connect to the database $connection = mssql_pconnect($host, $user, $pass) or die ('server connection failed'); $database = mssql_select_db($database, $connection) or die ('DB selection failed'); // Query the table and load all of the records into an array. $sql = SELECT support_payment_request.credit_card_id, support_payment_request.status_code, criminal_payment_request.credit_card_id, criminal_payment_request.status_code, credit_card_payment_request.credit_card_id, credit_card_payment_request.date_request_received FROM credit_card_payment_request LEFT OUTER JOIN support_payment_request ON support_payment_request.credit_card_id = credit_card_payment_request.credit_card_id LEFT OUTER JOIN criminal_payment_request ON criminal_payment_request.credit_card_id = credit_card_payment_request.credit_card_id WHERE support_payment_request.status_code = 'P' OR criminal_payment_request.status_code = 'P'; // print_r ($sql); $result = mssql_query($sql) or die(mssql_error()); // print_r ($result); $number_rows= mssql_num_rows($result); ? table width='780' border='1' align='center' cellpadding='2' cellspacing='2' bordercolor='#00' ?php if(!empty($result)) { while ($row= mssql_fetch_array($result)) { $id = $row['credit_card_id']; $dateTime = $row['date_request_received']; //print_r ($id); ? tr td width='88' height='13' align='center' class='tblcell'div align='center'?php echo a href='javascript:editRecord($id)'$id/a ?/div/td td width='224' height='13' align='center' class='tblcell'div align='center'?php echo $dateTime ?/div/td td width='156' height='13' align='center' class='tblcell'div align='center'?php echo To Be Processed ?/div/td td width='156' height='13' align='center' class='tblcell'div align='center'?php echo Payment Type ?/div/td td width='156' height='13' align='center' class='tblcell'div align='center'?php echo Last Processed By ?/div/td /tr ?php } } ? The picture below is what mu output looks like. BUT, what I am trying to do is have only ONE row returned per ID regardless of however many records may be associated with that ID. Below record number 122 has three results, I only want one row for record 122 to be displayed. Any ideas? 2 javascript:editRecord(2) Oct 6 2010 12:00AM To Be Processed Payment Type Last Processed By 46 javascript:editRecord(46) Feb 23 2007 2:27PM To Be Processed Payment Type Last Processed By 66 javascript:editRecord(66) Feb 26 2007 3:16PM To Be Processed Payment Type Last Processed By 68 javascript:editRecord(68) Feb 26 2007 3:39PM To Be Processed Payment Type Last Processed By 76 javascript:editRecord(76) Mar 21 2007 7:36AM To Be Processed Payment Type Last Processed By 77 javascript:editRecord(77) Mar 21 2007 7:40AM To Be Processed Payment Type Last Processed By 78 javascript:editRecord(78) Mar 21 2007 7:40AM To Be Processed Payment Type Last Processed By 79 javascript:editRecord(79) Mar 21 2007 7:41AM To Be Processed Payment Type Last Processed By 122 javascript:editRecord(122) Mar 27 2007 5:29PM To Be Processed Payment Type Last Processed By 122 javascript:editRecord(122) Mar 27 2007 5:29PM To Be Processed Payment Type Last Processed By 122 javascript:editRecord(122) Mar 27 2007 5:29PM To Be Processed Payment Type Last Processed By -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Selecting a special row from the database
Edward Kay skrev: -Original Message- From: Marcelo Wolfgang [mailto:[EMAIL PROTECTED] Sent: 04 May 2007 14:37 To: php-general@lists.php.net Subject: [PHP] Selecting a special row from the database Hi all, I'm building a news display page for a website, and since the user has 2 ways to arrive there, I want to know if this is possible: 1) the user arrive at news.php I will run a query at the db, and get the latest news to be the main one (full display) and display the others news in a list 2) the user arrived from a link to a specific news to news.php?id=10 It should display the news with id = 10 as the main news and get the latest ones to display in a list of other news I've so far was able to add a dinamic WHERE to my query ( if I have or not the id GET parameter ) and if I don't have it, I'm able to display the latest result as the main news, but when I have an id as a GET parameter, I have a where clause in my query and it will return only the main news and not build up the news list what I want is to separate the news that the user want to see ( the id=XX one ) from the others rows, can someone advice me ? Here is the code I have so far, I hope it serve as a better explanation than mine! ? $newsId = $_GET['id']; if (isset($newsID)){ $whereClause = 'WHERE auto_id ='.$newsId; } else { $whereClause = ''; } mysql_connect(localhost,$user,$pass) or die (mysql_error()); mysql_select_db ($db_table); $SQL = SELECT * FROM tb_noticias $whereClause ORDER BY auto_id DESC; $news_Query = mysql_query($SQL); $recordCount = mysql_numrows($news_Query); mysql_close(); ? TIA Marcelo Wolfgang If id is set, query the DB for this news article and put as the first element in an array. Then perform a second query WHERE ID != id and append the results to the array. If id isn't set, just perform the one query without any where clause. If you want to do it all in one query, if id is provided use SELECT... WHERE ID = id UNION (SELECT...WHERE ID != id ORDER BY id DESC) to get the ordering you want. If id isn't set just use SELECT ... ORDER BY id DESC. I'm not sure if there would be much difference in performance as I still think the database would perform two queries internally. Edward Maybe SELECT ..., if (id = my_id,1,0) as foo ... ORDER BY foo DESC; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Split string
Lester Caine skrev: Can someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer. $myString = John Doe; $pos = strpos($myString, ) strpos($myString, ,) ? strpos($myString, ) : strpos($myString, ,); $part1 = substr($myString, 0, $pos); $part2 = substr($myString, $pos); /T -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[Fwd: Re: [PHP] a little math]
Don't know your problem but: if $totalTime is total length in seconds $minutes = floor($totalTime / 60); $seconds = $totalTime % 60; /Fredrik Sebe skrev: maybe someone can figure why sometimes i get negative values for seconds.. $job['finished'] and $job['finished'] are both unix timestamp. i subtract both to get how many seconds some thing took.. well you should be able to read the rest. sometimes it works fine but other times i get negative seconds. $job['run_time'] = ($job['finished'] - $job['started']); $minutes = number_format($job['run_time'] / 60, 0, '', ''); // seconds left after calculating minutes $seconds = (($job['run_time']- 60) * $minutes); $job['runtime'] = $minutes . ' mins ' . $seconds . ' secs'; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] UPDATE and redirect
marcelo Wolfgang skrev: Hi all, I'm new to this list and new to php programming so sorry if I do something wrong here :) Ok, now to my problem. I've created a query to update a mysql db, and it isn't working, and it's not throwing me any errors, so I need some help to figure out what's wrong here. My code follows : ? if($_GET['act'] = 'a'){ $action = 1; } else if ($_GET['act'] = 'd'){ $action = 0; } Don't use =, use == (or in some cases ===). = is for assignment. Also, what if $_GET['act'] is neither 'a' or 'd'? $id = $_GET['id']; Again, what if $_GET['id'] is null? mysql_connect(localhost,,) or die (mysql_error()); mysql_select_db (taiomara_emailList); $email_Query = mysql_query(UPDATE 'tb_emails' SET 'bol_active' = $action WHERE `auto_id` = $id); Use backticks if you think you need them In this case you don't $sql = UPDATE `tb_emails` SET `bol_active` = $action WHERE `auto_id` = $id; echo DEBUG: $sql; $email_Query = mysql_query( $sql ); This is how to get the error: if ( !$email_Query ) echo mysql_error(); mysql_close(); ? The page is executed, but it don't update the table ... I've tried with the '' and without it ( the phpmyadmin page is where I got the idea of using the '' ). Any clues ? Also, how can I make a redirect after the query has run ? header(Location: http://www.foobar.com;); Will work as long as you don't print out any output whatsoever to the browser before this line of code. TIA Marcelo Wolfgang /T -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Setting printf results as a variable
Stephen wrote: Hi list, I'm trying to make a script which requires that I perform a printf() formatting on a string, but instead of outputting the result I need to set the result as a variable to write to a file. Can any one advise me on how to do this? or if it's even possible? Kind regards, Stephen. sprintf... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convert date to reversed date
Reinhart Viane skrev: Is this a good way to convert 01/02/2007 to 20070201 $value='01/02/2007'; list($day, $month, $year) = split('[/.-]', $value); $filename=$year.''.$month.''.$day; It does work but i would like to verify if there are no better, more logical ways to do this. Thanks in advance date(Ymd, strotodate( $value )); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convert date to reversed date
date(Ymd, strotodate( $value )); Of course I mean: date( Ydm, strtodate( $value )); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Forms and destroying values
It doesn't help to reset any values. The form data is being resent by the browser itself, just if the user presses the submit button again with the same data. What you could do is mabye use a session to see if the particular user has sent form data before. /Fredrik Thunberg Beauford skrev: Hi, How do I stop contents of a form from being readded to the database if the user hits the refresh button on their browser. I have tried to unset/destroy the variables in several different ways, but it still does it. After the info is written I unset the variables by using unset($var1, $var2, $etc). I have also tried unset($_POST['var1'], $_POST['var2'], $_POST['etc']). I even got deperate and tried $var = ; or $_POST['var'] = ; What do I need to do to get rid of these values??? Obviously I am missing something. Any help is appreciated. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sort Array not working
Hi sort returns a bool, the sorted array passed by reference. So try: $result = sort( $array ); //Now $array is sorted print_r( $array ); /Fredrik Thunberg Kevin Murphy skrev: I'm having trouble sorting an array. When I do, it empties the array for some reason. Take the following code: $data = bird,dog,cat,dog,,horse,bird,bird,bird,lizard; $array = explode(,,$data);// Create the array $array = array_diff($array, array());// Drop the empty elements $array = array_unique($array);// Drop the duplicate elements $array = array_merge($array);// Reset the array keys print_r ($array); Up to here it works great. The resulting output is: Array ( [0] = bird [1] = dog [2] = cat [3] = horse [4] = lizard ) Then if I do this: $array = sort($array);// Sorts the array print_r ($array); The output is 1. I've tried asort, rsort in the place of sort and get the same results. I've also tried putting the sort in between the first 4 steps and that doesn't work either. Obviously I'm doing something wrong here. I'm using PHP 4.3.4. Any suggestions? --Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EZ array problem - What's wrong with my brain?
Try $try = $var[1.2]; If your array looks like the one below then there is no $var[0] and therefore you get NULL /Thunis Brian Dunning skrev: That seems right to me too - but everything I try returns NULL. I set $try=$var[0], and $try ends up being null; print_r($try) gives blank. I even tried $try=$var[1] and it was the same result. Am I in the Twilight Zone? On Dec 1, 2006, at 12:26 AM, Youri LACAN-BARTLEY wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFb+cnWC9/YPePNU4RAmnzAKDGUlHxZiQvyhLfSiHKXV9sI73fTQCfe/Ub pKYeQqK4FcNhmTdEIm41kic= =PSbi -END PGP SIGNATURE- --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] GD - Problem writing text
Hi all This is my first attempt to wrie to this mailing list, so please bare with me. My problem is as follows I'm trying to generate a dynamic picture with some text on it. The code works fine on one of my servers, but not on the other one. The code I'm using: $im = imagecreatetruecolor (400, 100); $black = imagecolorallocate ($im, 0, 0, 0 ); $white = imagecolorallocate ($im, 255, 255, 255 ); imagerectangle ($im,0, 0,399,99 ,$black); imagefilledrectangle ($im,0, 0,399,99 ,$white); imagettftext ($im, 30, 0, 10, 40 , $black, TTF_DIR. times.ttf, Hello World!); header (Content-type: image/png ); imagepng ($im); Where TTF_DIR is the complete path to the times.ttf-file (which i've chmodded to 777). This is the gd-info from where it works: GD Support enabled GD Version bundled (2.0.28 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.1.3 GIF Read Support enabled GIF Create Support enabled JPG Support enabled PNG Support enabled WBMP Support enabled XBM Support enabled The one things that differs between the servers is: FreeType Linkagewith TTF library is set on the faulty one. Can this be the problem? Cheers /Fredrik Thunberg [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php