PHP - Json Newb... Can't Parse This String
I'm trying the fetch some geocode data from mapquest. Google doesn't like me right now. I keep running into the query_limit. So I want to set a back up that will go into production when I get that error from the big G.
I have my api key and I can put the string in a var. Code: [Select] $geocode = file_get_contents($url) I selected json as the output and when I echo $geocode... here is the first portion of the string....(I want lat & lng) Code: [Select] renderOptions({"results":[{"locations":[{"latLng":{"lng":-112.35984,"lat":34.58752},..... Now for the life of me, I can't do anything with it. I've tried json_decode() with the true argument there and not. Code: [Select] $output = json_decode($geocode, true); $output = json_decode($geocode); vardump($output) is NULL. So, I thought, well maybe I don't need to decode it, but I can't figure out how to parse it. I'm lost. This admittedly is my first attempt as trying to work with a jason object, but jeesh, it doesn't seem like it should be that hard. Can someone start me in the right direction? Similar TutorialsI need parse the JSON string below into an associative array, sort it by the 'age' field and output the sorted array as an HTML table. Here is what I have done so far but it just returns me 'Array': Code: [Select] <?php $json='[{"name": "John","age": 23},{"name": "jim","age": 19},{"name": "jason","age": 34}]'; $array = json_decode( $json, true); function cmp( $a, $b){ if( !isset( $a['age']) && !isset( $b['age'])){ return 0; } if( !isset( $a['age'])){ return -1; } if( !isset( $b['age'])){ return 1; } if( $a['age'] == $b['age']){ return 0; } return (($a['age'] > $b['age']) ? 1 : -1); } usort( $array, 'cmp'); foreach ($array as $key => $value) { echo $key.":".$value."\n"; } ?> Hello Can you please show me how can i parse this JSON in PHP? {"status":"error","error":{"error_code":700,"error_message":"Recognition failed: you didn't send file via POST or file url as `url` param."},"requested_params":{"method":"recognize"}}
I need to setup a condition : If(status="error) than $errorcode=700 errormessage=Recognition failed: you didn't send file via POST or file url as `url` param errorMethod= "recognize" Hello
This may seem like a silly question but if you never ask you never know...
Lets say I json encode a php array. When I echo out the encoded json string into a JS variable it looks something like this in the resultant markup:
var arr = ["cow - Copy (10).jpg","cow - Copy (2).jpg"];So in this instance the string I've echoed out is equivalent to a JS array and I can use it straight away. My questions: 1) Is it valid to do what I've done above? 2) Since I can use the array right away is there any need to JSON.parse? 3) When would you use JSON.parse? Thanks, Drongo Hello, I am a novice with php and know close to nothing about JSON. I am using wordpress and have 2 calendar type plugins I want to work together. With one plugin the user inputs dates that they are booked. The other plugin is a date picker, the cool part is it allows you to black out dates using php before the date picker is built. So what I'm trying to do is get the data from what the user chose as booked, and not let a user on the front end pick any of the booked dates with the date picker. Hope that makes sense. The problem is the formatting of the data with the date booked plugin. This is what is in the field Code: [Select] a:1:{s:9:"calendars";a:1:{i:1;a:4:{s:12:"calendarName";s:21:"Availability Calendar";s:12:"calendarJson";s:59:"{"year2011":{"month12":{"day25":"booked","day6":"booked"}}}";s:11:"dateCreated";i:1324333825;s:12:"dateModified";i:1324333825;}}} I chose 2 dates to be booked in that example: dec 25 2011, and dec 6 2011. I have no idea how I would parse the above data into what I need. I don't really need the data from the other parts of the above code, just the dates. The others are field descriptions and etc. that wordpress uses. Incidentally, this is what the date picker setup would look like in the above senario: Code: [Select] $myCalendar->setSpecificDate(array("2011-12-06","2011-12-25"), 0, ''); Hello.
Server returns this json
{"status":1,"job_status":"READY","iterations":["Contig2","Contig75"],"accessions":["NP_001061702","NP_001068174"]}And i would like to print out in a textarea (using the above jQuery command) $('#info').val()something like this: Contig2 : NP_001061702 Contig75 : NP_001068174 Any idea on how to achieve this? Thanks! Hello.
I am new here.
I have a sligh problem, i saw a few results here which however did not lead to the desired result.
The problem is , i have this Json Response from a API:
Array ( [0] => Array ( [isoid] => 0 [omschrijving] => - leeg - ) [1] => Array ( [isoid] => 64 [omschrijving] => ArchLinux 2013.5 ) [2] => Array ( [isoid] => 75 [omschrijving] => AsteriskNOW 3.0.0 64b ) [3] => Array ( [isoid] => 67 [omschrijving] => CentOS 5.9 32b ) [4] => Array ( [isoid] => 2 [omschrijving] => CentOS 6.3 64b ) [5] => Array ( [isoid] => 96 [omschrijving] => CentOS 7.0 64b ) [6] => Array ( [isoid] => 4 [omschrijving] => Clear OS 5.2 64b ) [7] => Array ( [isoid] => 93 [omschrijving] => CloudLinux 6.4 ) [8] => Array ( [isoid] => 1 [omschrijving] => Debian GNU/Linux 6.0 / Squeeze 64b ) [9] => Array ( [isoid] => 79 [omschrijving] => Debian GNU/Linux 7.0 / Wheezy 32b ) [10] => Array ( [isoid] => 71 [omschrijving] => Debian GNU/Linux 7.0 / Wheezy 64b ) [11] => Array ( [isoid] => 63 [omschrijving] => Fedora 18 64b ) [12] => Array ( [isoid] => 82 [omschrijving] => FreeBSD 10 64b ) [13] => Array ( [isoid] => 77 [omschrijving] => FreeBSD 9.2 64b ) [14] => Array ( [isoid] => 10 [omschrijving] => FreePBX 5.211.65-12 ) [15] => Array ( [isoid] => 76 [omschrijving] => GParted Live CD ) [16] => Array ( [isoid] => 3 [omschrijving] => KVM Virtio drivers voor Windows ) [17] => Array ( [isoid] => 66 [omschrijving] => MailCleaner 2012v6 64b ) [18] => Array ( [isoid] => 68 [omschrijving] => Manjaro KDE 0.8.6 64b ) [19] => Array ( [isoid] => 78 [omschrijving] => Microsoft Windows 7 Pro 64b ) [20] => Array ( [isoid] => 69 [omschrijving] => Microsoft Windows Server 2003 EN ) [21] => Array ( [isoid] => 8 [omschrijving] => Microsoft Windows Server 2008R2 EN ) [22] => Array ( [isoid] => 7 [omschrijving] => Microsoft Windows Server 2008R2 NL ) [23] => Array ( [isoid] => 70 [omschrijving] => Microsoft Windows Server 2012 NL 64b ) [24] => Array ( [isoid] => 84 [omschrijving] => Microsoft Windows Server 2012R2 NL ) [25] => Array ( [isoid] => 83 [omschrijving] => NOC PS 1.0r11 ) [26] => Array ( [isoid] => 11 [omschrijving] => OpenBSD 5.2 ) [27] => Array ( [isoid] => 80 [omschrijving] => OpenBSD 5.4 ) [28] => Array ( [isoid] => 94 [omschrijving] => OpenBSD 5.5 64b ) [29] => Array ( [isoid] => 72 [omschrijving] => OpenSUSE 12.3 64b ) [30] => Array ( [isoid] => 95 [omschrijving] => Slackware 13.37 ) [31] => Array ( [isoid] => 12 [omschrijving] => System Rescue CD ) [32] => Array ( [isoid] => 18 [omschrijving] => Turnkey Appflower ) [33] => Array ( [isoid] => 19 [omschrijving] => Turnkey ASP.net/Apache ) [34] => Array ( [isoid] => 20 [omschrijving] => Turnkey Bugzilla ) [35] => Array ( [isoid] => 21 [omschrijving] => Turnkey CodeIgniter ) [36] => Array ( [isoid] => 22 [omschrijving] => Turnkey Django ) [37] => Array ( [isoid] => 23 [omschrijving] => Turnkey Dokuwiki ) [38] => Array ( [isoid] => 24 [omschrijving] => Turnkey DomainControler ) [39] => Array ( [isoid] => 25 [omschrijving] => Turnkey Drupal7 ) [40] => Array ( [isoid] => 26 [omschrijving] => Turnkey Fileserver ) [41] => Array ( [isoid] => 27 [omschrijving] => Turnkey Gallery ) [42] => Array ( [isoid] => 28 [omschrijving] => Turnkey Gitlab ) [43] => Array ( [isoid] => 15 [omschrijving] => Turnkey Google AppEngine Go ) [44] => Array ( [isoid] => 16 [omschrijving] => Turnkey Google AppEngine Java ) [45] => Array ( [isoid] => 17 [omschrijving] => Turnkey Google AppEngine Python ) [46] => Array ( [isoid] => 29 [omschrijving] => Turnkey IceScrum ) [47] => Array ( [isoid] => 30 [omschrijving] => Turnkey Joomla2.5 ) [48] => Array ( [isoid] => 31 [omschrijving] => Turnkey LAMP ) [49] => Array ( [isoid] => 32 [omschrijving] => Turnkey Lighttpd/PHP/FastCGI ) [50] => Array ( [isoid] => 33 [omschrijving] => Turnkey Magento ) [51] => Array ( [isoid] => 34 [omschrijving] => Turnkey Mediawiki ) [52] => Array ( [isoid] => 35 [omschrijving] => Turnkey MongoDB ) [53] => Array ( [isoid] => 36 [omschrijving] => Turnkey MySQL ) [54] => Array ( [isoid] => 37 [omschrijving] => Turnkey NGINX/PHP/FastCGI ) [55] => Array ( [isoid] => 38 [omschrijving] => Turnkey OpenLDAP ) [56] => Array ( [isoid] => 39 [omschrijving] => Turnkey OpenPhoto ) [57] => Array ( [isoid] => 40 [omschrijving] => Turnkey OSCommerce ) [58] => Array ( [isoid] => 41 [omschrijving] => Turnkey OTRS ) [59] => Array ( [isoid] => 42 [omschrijving] => Turnkey Owncloud ) [60] => Array ( [isoid] => 43 [omschrijving] => Turnkey PHPBB ) [61] => Array ( [isoid] => 44 [omschrijving] => Turnkey PHPList ) [62] => Array ( [isoid] => 45 [omschrijving] => Turnkey PHPNuke ) [63] => Array ( [isoid] => 46 [omschrijving] => Turnkey Postgresql ) [64] => Array ( [isoid] => 47 [omschrijving] => Turnkey Prestashop ) [65] => Array ( [isoid] => 48 [omschrijving] => Turnkey Rails ) [66] => Array ( [isoid] => 49 [omschrijving] => Turnkey Redmine ) [67] => Array ( [isoid] => 50 [omschrijving] => Turnkey SiTracker ) [68] => Array ( [isoid] => 51 [omschrijving] => Turnkey StatusNET ) [69] => Array ( [isoid] => 52 [omschrijving] => Turnkey SugarCRM ) [70] => Array ( [isoid] => 53 [omschrijving] => Turnkey Symfony ) [71] => Array ( [isoid] => 54 [omschrijving] => Turnkey Tomcat ) [72] => Array ( [isoid] => 55 [omschrijving] => Turnkey Tomcat/Apache ) [73] => Array ( [isoid] => 56 [omschrijving] => Turnkey TRAC ) [74] => Array ( [isoid] => 57 [omschrijving] => Turnkey TWiki ) [75] => Array ( [isoid] => 58 [omschrijving] => Turnkey Typo3 ) [76] => Array ( [isoid] => 59 [omschrijving] => Turnkey Wordpress ) [77] => Array ( [isoid] => 60 [omschrijving] => Turnkey Zencart ) [78] => Array ( [isoid] => 13 [omschrijving] => Ubuntu 10.04 32b ) [79] => Array ( [isoid] => 6 [omschrijving] => Ubuntu 10.04 64b ) [80] => Array ( [isoid] => 14 [omschrijving] => Ubuntu 12.04 32b ) [81] => Array ( [isoid] => 61 [omschrijving] => Ubuntu 12.04 64b ) [82] => Array ( [isoid] => 62 [omschrijving] => Ubuntu 12.10 64b ) [83] => Array ( [isoid] => 89 [omschrijving] => Ubuntu 14.04 LTS 64b ) [84] => Array ( [isoid] => 5 [omschrijving] => Windows Password Reset ) [85] => Array ( [isoid] => 81 [omschrijving] => Zen Loadbalancer 3.03 ) [86] => Array ( [isoid] => 74 [omschrijving] => Zentyal 3.2 ) )how would i go to fill it automatically in a option value like <option value='74'>Zentyal 3.2</option>Thank you in advance I got a response from an api in json. How do i echo out the account_name in string. Thanks as usual. The response is below...
{ "status": true, "message": "Account number resolved", "data": { "account_number": "2067483918", "account_name": "BABALOLA MAYOWA ABEL", "bank_id": 18 } } "status": true, "message": "Account number resolved", "data": { "account_number": "2067483918", "account_name": "BABALOLA MAYOWA ABEL", "bank_id": 18 } }
I have the following code and it always says it's a string! How do I make it see it as a json object? Code: [Select] <?php //We'll return a json object from post request if ( !empty( $_POST ) ) { $arr = array ('status'=>1,'message'=>'Some message'); echo json_encode($arr); } else { ?> <input type="button" value="submit" id="submit" /> <script type="text/javascript" src="/scripts/jquery-1.4.2.js"></script> <script> var submit = document.getElementById( "submit" ); submit.onclick = function() { $.post( "test.php", function(data) { /* * This always prints as: * {"status":1,"message":"Some message"} * string * Code: undefined * Message: undefined */ alert( data + "\n" + typeof( data ) + "\nCode: " + data.status + "\nMessage: " + data.message ); } ); } </script> <? } ?> What do I do to make it a json object? Hello to everyone Can someone help me on how to parse this CSV string? I do not know how to parse string using PHP.. #1# "4","+447980123456","+447781484145","","2009-07-08","10:38:15","hello "","" world","Orange" "5","+447980123456","+447781484146","","2009-07-08","10:38:55","hello world","Orange" This string can contain a much bigger data. I would like the result to be Originator : +447781484145, Date : 2009-07-07, Time : 10:38:15, Message : hello world Originator : +447781484146, Date : 2009-07-08, Time : 10:38:55, Message : hello world Please guys if anyone of you knows how to parse this string it will be much appreciated. Im nearing my deadline for my work and this thing is keeping me from finishing it.. Thanks in advance I have a $string with this structure "word-word2 something-SECONDPART". I want to divide it to $string1 and $string2 by separating with the last "-". The point is that "-" exists in the first part, and I just want to make the second string after the last "-" http://paste.ee/p/OhiWv
The above is a link to a readable version of my code. The XMLHTTPREQUEST worked, and the array was pulled down. Was able to print out the undecoded/unparsed array. However, immediately afterwards, all code stops working.
<script> var xhr; if (window.XMLHttpRequest) { // Mozilla, Safari, ... xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE 8 and older xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("POST", "PHPLibrary/selectMemberResults.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send(); xhr.onreadystatechange = display_data; var $phparray function display_data() { if (xhr.readyState == 4) { if (xhr.status == 200) { //alert(xhr.responseText); $phparray = xhr.responseText; document.getElementById("suggestion").innerHTML = $phparray; // // //......................................................? // The above line of code is the last thing to print or // to do anything that returns to the browser.... //.......................................................? // All lines below do nothing............................? // } else { //alert('There was a problem with the request.'); } } } document.write("Length of phparray Array :" + $phparray.length + "<"); var output = JSON.parse($phparray, function (key,val) { if ( typeof val === 'string' ) { // regular expression to remove extra white space if ( val.indexOf('\n') !== -1 ) { var re = /\s\s+/g; return val.replace(re, ' '); } else { return val; } } return val; } ); document.write("Length of Array :" + $output.length + "<"); for (var i=0; i < $output.length; i++) { document.getElementById("suggestion").innerHTML = $output[i].MEMBER_NAME; } </script> I have a list of pictures and I want to control the order. Here is the picture format: $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_1.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_2.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_3.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_4.jpg $pic = http://www.picture.biz/incoming/w_2GTEK13T961240561_5.jpg Notice the order 1.jpg, 2.jpg, etc.. Here is where I'm stuck... // begin stuck :) $orderPic = explode("_", $pic); foreach($orderPic as $rank){ echo "$rank"; // I need $rank to equal 1 then 2 then 3 ... } It would be nice actually if I could start the insert with number 2 because number one is always a screwy picture. I hope this makes sense / Thank for the help! Say you have a string that you know has two, and exactly two, periods in it, like this...
$string = "3.12.8"How can you grab the three different values that are separated by periods (in this case, 3, 12 and ? I was thinking use strpos to find the position of the first period, then could use that info to grab everything up to that position. But then I couldn't figure out how you would find the position of the SECOND period. And even if I could get the exact positions of the two periods, it seems like there should be an easier way to simply retrieve values separated by specific characters. Is there a specific function for this type of thing, or was my initial though correct with having to do it in two parts essentially (find positions of periods, then use that knowledge to get the values)? Thanks! hi all am new to this forum help me to overcome from this error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in D:\wamp\www\quiz1\quiz1.php on line 12 Code: [Select] <?php include("contentdb.php"); $display = mysql_query("SELECT * FROM $table ORDER BY id",$db); if (!$submit) { echo "<form method=post action=$_SERVER['PHP_SELF']>"; echo "<table border=0>"; while ($row = mysql_fetch_array($display)) { $id = $row["id"]; $question = $row["question"]; $opt1 = $row["opt1"]; $opt2 = $row["opt2"]; $opt3 = $row["opt3"]; $answer = $row["answer"]; echo "<tr><td colspan=3><br><b>$question</b></td></tr>"; echo "<tr><td>$opt1 <input type=radio name=q$id value=\"$opt1\"></td><td>$opt2 <input type=radio name=q$id value=\"$opt2\"></td><td>$opt3 <input type=radio name=q$id value=\"$opt3\"></td></tr>"; } echo "</table>"; echo "<input type='submit' value='See how you did' name='submit'>"; echo "</form>"; } elseif ($submit) { $score = 0; $total = mysql_num_rows($display); while ($result = mysql_fetch_array($display)) { $answer = $result["answer"]; $q = $result["q"]; if ($$q == $answer) { $score++; } } echo "<p align=center><b>You scored $score out of $total</b></p>"; echo "<p>"; if ($score == $total) { echo "Congratulations! You got every question right!"; } elseif ($score/$total < 0.34) { echo "Oh dear. Not the best score, but don't worry, it's only a quiz."; } elseif ($score/$total > 0.67) { echo "Well done! You certainly know your stuff."; } else { echo "Not bad - but there were a few that caught you out!"; } echo "</p>"; echo "<p>Here are the answers:"; echo "<table border=0>"; $display = mysql_query("SELECT * FROM $table ORDER BY id",$db); while ($row = mysql_fetch_array($display)) { $question = $row["question"]; $answer = $row["answer"]; $q = $row["q"]; echo "<tr><td><br>$question</td></tr>"; if ($$q == $answer) { echo "<tr><td>»you answered ${$q}, which is correct</td></tr>"; } elseif ($$q == "") { echo "<tr><td>»you didn't select an answer. The answer is $answer</td></tr>"; } else { echo "<tr><td>»you answered ${$q}. The answer is $answer</td></tr>"; } } echo "</table></p>"; } ?> thanks in adavance Hello I have one problem with fwrite() I have one script to get width and height from javascript and echo it with PHP. echo "Screen width is: ". $_GET['width'] ."<br />\n"; echo "Screen height is: ". $_GET['height'] ."<br />\n"; It works but i want to store the result in a file fwrite($info,"Height: $_GET['height'] <br />"); But then I get error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING //////////////////////// it would be even better if I don't have to print the values but directly store them in $iinfo sorry if something similar was soved but those examples were different or i was unable to transform it to solve my problem I need to rewrite this php statement Code: [Select] <img src="<?php bloginfo('template_directory'); ?>/images/mainimage.jpg" title="" alt="" /> When I try to do this Code: [Select] <?php echo '<img src="<?php bloginfo('template_directory'); ?>/images/mainimage.jpg" title="" alt="" />' ; ?>It does not work, because I guess I've open and closed a php code inside php. How do I properly write this statement? Thanks Ben Hey i am doing a login and blog system i have done the login and reg part but i am having troubles with the adding post. Basically at the moment my user can make a post and they can anyone can view it, but i need to the user only be able to create there own prv post and that when anybody else logs in they cant make a post under it. Does anyone have any ideas? this is my code for the posts <?php session_start(); include('db_connect.php'); ?> Welcome to the fear blog <a href="logout.php">log out</a><hr/> <?php $sql = mysql_query("SELECT * FROM posts ORDER BY id "); while($row = mysql_fetch_array($sql)){ $title = $row['title']; $content = $row['content']; $category = $row['category']; ?> <div id="post"> <div id="wrapper"> <div id="title"> <label>Title</label> <?php echo $title; ?> </div> <div id="category"><label>category</label> <?php echo $category; ?> </div> <div id="content"> <label>Content</label><?php echo $content; ?> </div> </div> <?php } ?> <div id="contents"> <form action="post.php" method="post"> <label> Title:</label><input type="text" name="title" /><br/> <label> Category:</label><input type="text" name="category" /><br /> <label> Content:</label><textarea name="content"></textarea><br/> <input type="submit" name="submit" value="Post"/> </form> </div> </div> </div> </div> Hi All, Im modifying someone elses PHP code (survey tool) (and i havent done PHP for years) Basically the code exports to an external csv file to a file called export.csv However everytime i get it to export, it creates copies. ie it will export to export(2).csv and export(3).csv. How can i make it so that it exports and overwritesa/ammed the existing export.csv file? I had a look at the code and i believe this code below is doing the exporting but not sure code doing the export ( i think) Code: [Select] <?php include('classes/main.class.php'); include('classes/special_results.class.php'); $survey = new UCCASS_Special_Results; echo $survey->results_csv(@$_REQUEST['sid'],$_REQUEST['export_type']); ?> The class that it uses to export Code: [Select] <?php //====================================================== // Copyright (C) 2004 John W. Holmes, All Rights Reserved // // This file is part of the Unit Command Climate // Assessment and Survey System (UCCASS) // // UCCASS is free software; you can redistribute it and/or // modify it under the terms of the Affero General Public License as // published by Affero, Inc.; either version 1 of the License, or // (at your option) any later version. // // http://www.affero.org/oagpl.html // // UCCASS is distributed in the hope that it will be // useful, but WITHOUT ANY WARRANTY; without even the implied warranty // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // Affero General Public License for more details. //====================================================== class UCCASS_Special_Results extends UCCASS_Main { function UCCASS_Special_Results() { $this->load_configuration(); //Increase time limit of script to 2 minutes to ensure //very large results can be shown or exported set_time_limit(120); } function results_table($sid) { $sid = (int)$sid; if(!$this->_CheckAccess($sid,RESULTS_PRIV,"results_table.php?sid=$sid")) { switch($this->_getAccessControl($sid)) { case AC_INVITATION: return $this->showInvite('results_table.php',array('sid'=>$sid)); break; case AC_USERNAMEPASSWORD: default: return $this->showLogin('results_table.php',array('sid'=>$sid)); break; } } $data = array(); $qid = array(); $survey = array(); $survey['sid'] = $sid; $query = "SELECT q.qid, q.question, s.name, s.user_text_mode, s.survey_text_mode, s.date_format FROM {$this->CONF['db_tbl_prefix']}questions q, {$this->CONF['db_tbl_prefix']}surveys s WHERE q.sid = $sid and s.sid = q.sid ORDER BY q.page, q.oid"; $rs = $this->db->Execute($query); if($rs === FALSE) { $this->error('Error in query: ' . $this->db->ErrorMsg()); return; } $questions = array(); if($r = $rs->FetchRow($rs)) { $survey_text_mode = $r['survey_text_mode']; $user_text_mode = $r['user_text_mode']; $date_format = $r['date_format']; $survey['name'] = $this->SfStr->getSafeString($r['name'],$survey_text_mode); do{ $data['questions'][] = $this->SfStr->getSafeString($r['question'],$survey_text_mode); $qid[$r['qid']] = $r['qid']; }while($r = $rs->FetchRow($rs)); } else { $this->error('No questions for this survey.'); return; } if(isset($_SESSION['filter_text'][$sid]) && isset($_SESSION['filter'][$sid]) && strlen($_SESSION['filter_text'][$sid])>0) { $this->smarty->assign_by_ref('filter_text',$_SESSION['filter_text'][$sid]); } else { $_SESSION['filter'][$sid] = ''; } $query = "SELECT GREATEST(rt.qid, r.qid) AS qid, GREATEST(rt.sequence, r.sequence) AS seq, GREATEST(rt.entered,r.entered) AS entered, q.question, av.value, rt.answer FROM {$this->CONF['db_tbl_prefix']}questions q LEFT JOIN {$this->CONF['db_tbl_prefix']}results r ON q.qid = r.qid LEFT JOIN {$this->CONF['db_tbl_prefix']}results_text rt ON q.qid = rt.qid LEFT JOIN {$this->CONF['db_tbl_prefix']}answer_values av ON r.avid = av.avid WHERE q.sid = $sid {$_SESSION['filter'][$sid]} ORDER BY seq, q.page, q.oid"; $rs = $this->db->Execute($query); if($rs === FALSE) { $this->error('Error in query: ' . $this->db->ErrorMsg()); return; } $seq = ''; $x = -1; while($r = $rs->FetchRow($rs)) { if(!empty($r['qid'])) { if($seq != $r['seq']) { $x++; $seq = $r['seq']; $answers[$x]['date'] = date($date_format,$r['entered']); } if(isset($answers[$x][$r['qid']])) { $answers[$x][$r['qid']] .= MULTI_ANSWER_SEPERATOR . $this->SfStr->getSafeString($r['value'] . $r['answer'],$user_text_mode); } else { $answers[$x][$r['qid']] = $this->SfStr->getSafeString($r['value'] . $r['answer'],$user_text_mode); } } $last_date = date($date_format,$r['entered']); } $answers[$x]['date'] = $last_date; $xvals = array_keys($answers); foreach($xvals as $x) { foreach($qid as $qid_value) { if(isset($answers[$x][$qid_value])) { $data['answers'][$x][] = $answers[$x][$qid_value]; } else { $data['answers'][$x][] = ' '; } } $data['answers'][$x][] = $answers[$x]['date']; } $this->smarty->assign_by_ref('data',$data); $this->smarty->assign_by_ref('survey',$survey); return $this->smarty->fetch($this->template.'/results_table.tpl'); } function results_csv($sid, $export_type=EXPORT_CSV_TEXT) { $sid = (int)$sid; $retval = ''; if(!$this->_CheckAccess($sid,RESULTS_PRIV,"results_csv.php?sid=$sid")) { switch($this->_getAccessControl($sid)) { case AC_INVITATION: return $this->showInvite('results_csv.php',array('sid'=>$sid)); break; case AC_USERNAMEPASSWORD: default: return $this->showLogin('results_csv.php',array('sid'=>$sid)); break; } } header("Content-Type: text/plain; charset={$this->CONF['charset']}"); header("Content-Disposition: attachment; filename=Export.csv"); $query = "SELECT q.qid, q.question, s.date_format FROM {$this->CONF['db_tbl_prefix']}questions q, {$this->CONF['db_tbl_prefix']}surveys s WHERE q.sid = $sid and s.sid = q.sid ORDER BY q.page, q.oid"; $rs = $this->db->Execute($query); if($rs === FALSE) { $this->error('Error in query: ' . $this->db->ErrorMsg()); return; } $questions = array(); if($r = $rs->FetchRow($rs)) { $date_format = $r['date_format']; do{ $questions[$r['qid']] = $r['question']; }while($r = $rs->FetchRow($rs)); } else { $this->error('No questions for this survey'); return; } if(isset($_SESSION['filter_text'][$sid]) && isset($_SESSION['filter'][$sid]) && strlen($_SESSION['filter_text'][$sid])>0) { $this->smarty->assign_by_ref('filter_text',$_SESSION['filter_text'][$sid]); } else { $_SESSION['filter'][$sid] = ''; } $query = "SELECT GREATEST(rt.qid, r.qid) AS qid, GREATEST(rt.sequence, r.sequence) AS seq, GREATEST(rt.entered, r.entered) AS entered, q.question, av.value, av.numeric_value, rt.answer FROM {$this->CONF['db_tbl_prefix']}questions q LEFT JOIN {$this->CONF['db_tbl_prefix']}results r ON q.qid = r.qid LEFT JOIN {$this->CONF['db_tbl_prefix']}results_text rt ON q.qid = rt.qid LEFT JOIN {$this->CONF['db_tbl_prefix']}answer_values av ON r.avid = av.avid WHERE q.sid = $sid {$_SESSION['filter'][$sid]} ORDER BY seq, q.page, q.oid"; $rs = $this->db->Execute($query); if($rs === FALSE) { $this->error('Error in query: ' . $this->db->ErrorMsg()); return; } $seq = ''; $x = 0; while($r = $rs->FetchRow($rs)) { if(!empty($r['qid'])) { if($seq != $r['seq']) { $x++; $seq = $r['seq']; $answers[$x]['date'] = date($date_format,$r['entered']); } switch($export_type) { case EXPORT_CSV_NUMERIC: if(empty($r['answer'])) { $value = $r['numeric_value']; } else { $value = $r['answer']; } break; case EXPORT_CSV_TEXT: default: if(empty($r['answer'])) { $value = $r['value']; } else { $value = $r['answer']; } break; } if(isset($answers[$x][$r['qid']])) { $answers[$x][$r['qid']] .= MULTI_ANSWER_SEPERATOR . $value; } else { $answers[$x][$r['qid']] = $value; } } $last_date = date($date_format,$r['entered']); } $answers[$x]['date'] = $last_date; $line = ''; foreach($questions as $question) { $line .= "\"" . str_replace('"','""',$question) . "\","; } $retval .= $line . "Datetime\n"; $xvals = array_keys($answers); foreach($xvals as $x) { $line = ''; foreach($questions as $qid=>$question) { if(isset($answers[$x][$qid])) { if(is_numeric($answers[$x][$qid])) { $line .= "{$answers[$x][$qid]},"; } else { $line .= "\"" . str_replace('"','""',$answers[$x][$qid]) . "\","; } } else { $line .= ","; } } $retval .= $line . '"' . $answers[$x]['date'] . "\"\n"; } return $retval; } } ?> Hi - I'm using SESSION variables to keep track of customers who come onto the site to order stuff. For example $_SESSION['customerid'] all the incoming customers. I also use SESSION variables with a different value for the managers to look at and keep track of customer data. eg : $_SESSION['customer']['firstname'] I am expecting many customers and managers to be simultaneously using the site. QUESTION: Do I need to increment the SESSION variable in some way in order to avoid that a session gets overwritten, or will my SESSION variables keep track and keep everything separated by dint of the fact that they contain different values ? so far my testing shows that things are working correctly, but I can only test with 3 / 4 virtual users in different browser windows . Hi - wondering if someone can give a little guidance: Why doesn't this trim the whitespace out of the string postzip? trim(strtoupper(((isset($_POST["postzip"]))?$_POST["postzip"]:""))) Thanks |