I am developing an accounting software as project. I want to count sets of variables in URL query string. eg
http://localhost/xampp/khata2/test/tableaddrow_nw.php?accname1=1&DrAmount1=1&CrAmount1=1&accname2=2+was2&DrAmount2=2&CrAmount2=2&accname3=3+was3&DrAmount3=3&CrAmount3=3&accname4=4+was4&DrAmount4=4&CrAmount4=4&accname5=5+was5&DrAmount5=5&CrAmount5=5&accname6=6+was6&DrAmount6=6&CrAmount6=6
There is a set of kind of rows in a query string accname1,DrAmount1,CrAmount1 .... accname6,DrAmount6,CrAmount6 so on which is generated dynamicaly as user inputs data in rows.
how can i find out ho many rows are (set of data) are in query string ?
Any help is appreciated.
$rows = explode("&", $_SERVER['QUERY_STRING']);
This will give you an array of:
accname1=1
DrAmount1=1
CrAmount1=1
So you could get the total as count($rows).
Is this what you meant?
Related
I have a column of text data in a csv file that looks something like this for each row:
{variable_1=result1, variable2=null, variable_three=result_3, variable_4=[{var4.1=result4.1, var4.2=result4.2, var4.3=result4.3}], variable_5=null}
I am trying to write some formulas to ultimately have the data look like this in Excel:
raw data
variable_1
variable2
variable_three
var4.1
var4.2
var4.3
variable_5
{variable_1=result1, variable2=null, variable_three=result_3, variable_4=[{var4.1=result4.1, var4.2=result4.2, var4.3=result4.3}], variable_5=null}
result1
null
result_3
result4.1
result4.2
result4.3
null
The variable names will be the same for each run of the query that fetches this, but the results will vary in character length--which is why I formatted my example the way I did. There is multiple rows of this too.
What's the best way to go about this??
Edit: There are approx 30 variables in my actual data
I have a 2 column data in the following format where Name is a string and Location is an array seperated with commas
Name------Location
John---------A,B,C,D
Paul----------E,F,G,H
I want to convert it to the following format
Name--------Location
John-----------A
John-----------B
John-----------C
John-----------D
Paul------------E
Paul------------F
Can someone suggested how can I achieve this ?
Thanks in advance.
There are many ways to accomplish this. One option is to use Split, along the following lines:
Location = "A,B,C,D"
LocationList = Split(Location, ",")
That will populate LocationList with an array of individual locations. You can then loop through the individual locations and generate your output.
I'm selecting some Strings from my SQLite DB and store them in an Array. Now I want to plot the values with the framework "Razorflow". I think it is only possible if the values of the array are floats, am I wrong?
In my DB I'm storing temperature and humidity of 12 different sensor nodes, in this form:
id|temperature|humidity|...|...
1 | 22.50C| 47.50%|...|...
..
I heared something about the floatval()-function, I also heared that this function is not made for objects like Arrays. Is there a simple solution? I'm very new to PHP :-D
Depends on how you're getting the values back from the database.
id|temperature|humidity|...|...
Sounds like a string to me, so i would first explode it into an array and then iterate the array casting floatval into every element.
What you do after that process depends on you.
EDIT:
If your query is:
$humi = $database->query((SELECT humidity FROM Measurement WHERE topic_hum='WSN9/humi'
You will get back only 1 column (humidity) and 0 or more rows depending on your database. Let's say it's only 1 for now:
$resul = mysql_query($humi,$link);
$rows = mysql_fetch_array($resul);
$myarray = explode("|", $rows["humidity"]);
This should give us an array called myarray containing X elements each with a "single" string part value. So we can iterate over it and parse it. There is also the shorthand "array_map" to iterate over an array using a callback function over each element and returning the value as an array:
$myparsedarray = array_map('floatval', $myarray)
Now you have an array with only float values (and errors maybe, check your data!)
I want to create a static chart of values pulled out of a MySQL database.
The chart format would be (x axis : dd/mm/yy hh:mm:ss (corresponding to timestamp of mysql database)) and y-axis would be a double value. I am able to successfully retrieve these values from MySql database.I want help plotting them by ZingChart
Nikita.
Once you've retrieved your values from your MySQL database, you'll want to convert the MySQL date values in to Unix time in milliseconds. I've populated a $date array with the MySQL date values, and iterated over the array, calling strtotime to first convert to Unix time, and multiplying by 1000 to convert to milliseconds. In order to be able to directly modify array elements within the loop, I've also preceded $value with to assign by reference.
foreach ($date as &$value){
$value = strtotime( $value ) * 1000;
}
So now that the values in the $date array have been converted to the proper format, it's time to create a JavaScript array from the PHP array. This can be done using join():
var dateValues = [<?php echo join($date, ',') ?>];
The resulting array looks like this:
var dateValues = [1356994800000,1357081200000,1357167600000, ... ];
To use this array in ZingChart, use the dateValues variable with "values" in the scale-x object. To convert the Unix time values back to dates in ZingChart, add the "transform" object, and set it to "type":"date".
"scale-x":{
"values": dateValues,
"transform":{
"type":"date",
"item":{
"visible":false
}
}
},
...
That takes care of the scale. To get your other values in the chart, you do pretty much the same thing. Convert the PHP arrays into JavaScript arrays, and use the array variable in your chart JSON.
With the PHP $series array:
var seriesValues = [<?php echo join($series, ',') ?>];
In your chart JSON:
"series":[
{
"values":seriesValues
}
]
I've compiled all of this in to a Github Gist for you. Let me know if you have any questions!
Check out our demos repo on GitHub. We have a tutorial specifically about connecting to a MySQL database with PHP.
There's a step-by-step walkthrough on our site, too.
If you share your JSON or more details about it, I can help you with putting your chart together.
I'm on the ZingChart team. Please let me know if you have other questions.
I need to import certain information from an Excel file into an Access DB and in order to do this, I am using DAO.
The user gets the excel source file from a system, he does not need to directly interact with it. This source file has 10 columns and I would need to retrieve only certain records from it.
I am using this to retrieve all the records:
Set destinationFile = CurrentDb
Set dbtmp = OpenDatabase(sourceFile, False, True, "Excel 8.0;")
DoEvents
Set rs = dbtmp.OpenRecordset("SELECT * FROM [EEX_Avail_Cap_ALL_DEU_D1_S_Y1$A1:J65536]")
My problem comes when I want to retrieve only certain records using a WHERE clause. The name of the field where I want to apply the clause is 'Date (UCT)' (remember that the user gets this source file from another system) and I can not get the WHERE clause to work on it. If I apply the WHERE clause on another field, whose name does not have ( ) or spaces, then it works. Example:
Set rs = dbtmp.OpenRecordset("SELECT * FROM [EEX_Avail_Cap_ALL_DEU_D1_S_Y1$A1:J65536] WHERE Other = 12925")
The previous instruction will retrieve only the number of records where the field Other has the value 12925.
Could anyone please tell me how can I achieve the same result but with a field name that has spaces and parenthesis i.e. 'Date (UCT)' ?
Thank you very much.
Octavio
Try enclosing the field name in square brackets:
SELECT * FROM [EEX_Avail_Cap_ALL_DEU_D1_S_Y1$A1:J65536] WHERE [Date (UCT)] = 12925
or if it's a date we are looking for:
SELECT * FROM [EEX_Avail_Cap_ALL_DEU_D1_S_Y1$A1:J65536] WHERE [Date (UCT)] = #02/14/13#;
To use date literal you must enclose it in # characters and write the date in MM/DD/YY format regardless of any regional settings on your machine