Im trying to dynmically generate a table that has a radio button per row whose value is set to the ID field of a SQL table. Im not sure how I can reference this value using CGI radio_group. In my research radio_group uses an associate array, however if I convert the SQL query to an associative array the values wont match up since there are more than 2 tables in the query. If possible I'd like to avoid a second SQL call:
use CGI;
use DateTime::Format::MySQL;
$epoch = DateTime->now(time_zone=>"America/New_York");
$fmtnow = DateTime::Format::MySQL->format_datetime($epoch);
$iasql = qq { select * from alert where endtime > '$fmtnow'};
$iaqry = $iadb->prepare($iasql);
$iaqry->execute() || die "Fail $DBI::errstr"
print $query->start_table({-border=>1, -cellpadding =>1});
while(#iarows = $iaqry->fetchrow_array()) {
print $query->Tr(print $query->td([print $query->radio_group('iaselect',\#iarows[0]),'#iarows[1]','#iarows[2]','#iarows[3]','#iarows[4]','#iarows[5]']));
}
print $query->end_table();
Yeah I think Im gonna nix the the CGI radio button method for this part and just have it print print "<input type="radio">;, it works that way. I was only attempting to use this method because I hadn't realized there are start_div and end_div methods. Prior to finding those I thought this was my only way of achieving the radio buttons inside of the q->div() container.
I excluded the Div portion of the code because it didn't seem relevent.
Related
I found this in the guide, but have no idea how to implement the same
yii\db\Query::count(); returns the result of a COUNT query. Other
similar methods include sum($q), average($q), max($q), min($q), which
support the so-called aggregational data query. $q parameter is mandatory
for these methods and can be either the column name or expression.
Say for example I have a table name 'billing' with columns:
name amount
charge1 110.00
charge2 510.00
Total - 620.00
How I implement using
yii\db\Query::sum('amount');
I have also tried like
$command = Yii::$app->db->createCommand("SELECT sum(amount) FROM billing");
yii\db\Query::sum($command);
but page generates error.
Thanks.
The first part of code you tried appears to be attempting to use Query Builder. In this case, you must create an instance of a query, set the target table, and then compute the sum:
Via Query Builder
(http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html):
$query = (new \yii\db\Query())->from('billing');
$sum = $query->sum('amount');
echo $sum;
The second part of code you tried appears to be attempting to use Data Access Objects. In this case, you can write raw SQL to query the database, but must use queryOne(), queryAll(), queryColumn(), or queryScalar() to execute the query. queryScalar() is appropriate for an aggregate query such as this one.
Via Data Access Objects
(http://www.yiiframework.com/doc-2.0/guide-db-dao.html):
$command = Yii::$app->db->createCommand("SELECT sum(amount) FROM billing");
$sum = $command->queryScalar();
echo $sum;
Within a model the sum could also be fetched with:
$this->find()->where(...)->sum('column');
You can directly use yii query concept in Search Model
$this->find()->from('billing')->where(['column'=>value])->sum('amount');
OR
$this->find()->where(['column'=>value])->sum('amount');
Outside the Model (Billing is model name)
Billing::find()->where(['column'=>value])->sum('amount');
i hope your model name is Billing
inside Billing model use
$this->find()->sum('amount');
in other models
Billing::find()->sum('amount');
OK, in good old fashioned PHP MVC, I might use a model to hit the DB, send info to my PHP controller that I pass on to the View. In the View, I might take that info (say i ajax'ed my controller for the info) and create a table or ul to display the data returned.
I've had trouble finding any modern (ver 6.1 is what i'm on) tutorial to show me how to preform this action in typo3.
Can anyone just "steer" me in the right direction? Perhaps provide an example via answer, or some links to further information that may compare it down to "old fashioned MVC"?
Extension has been suggested, but I'd like to know the very base process of what I'm asking before I try writing some extension, unless the extension is the only way. Although, my table is now on the SAME DB my typo3 is on, so shouldn't there be some command to just simply call my table and get the rows? Maybe send them to a ###sub-part###?
You can use a typoscript cObj content and the select option together with the function render_obj when your table name is like the typo3 nameing convention. The select pulls the record from the table and pass it to the render_obj function. It's a function that can apply to all cObj and iterate over the entire selection. stdWrap works only on the entire cObj. When you need to work through each record you need the render_obj function. For example:
10 = CONTENT
10 {
select {
pidInList = 1
where = colpos=1
orderBy = sorting
}
table = tt_content
renderObj.stdWrap.wrap = <li>|</li>
renderObj.stdWrap.required = 1
}
10.stdWrap.wrap = <ul>|</ul>
This gives you an unorderd list from the tt_content table with pid=1 and the content from the far left column.
I have a text field with data, something like:
[{"id":10001,"timeStarted":1355729600733,"projectId":10002,"issueId":"29732,","userName":"tester","assignee":"test","status":"STARTED","shared":True,"name":"Session 4","projectName":"IDS","assigneeDisplayName":"First1 Last1"},
{"id":10002,"timeStarted":1358354188010,"projectId":10002,"issueId":"","userName":"tester","assignee":"test","status":"CREATED","shared":True,"name":"asdf98798","projectName":"IDS","assigneeDisplayName":"First Last"}]
but with much more rows, it may be 30-40, and may be 2 more different statuses (total 4).
Is it possible to extract some data from here having read-only access to DB and only using MySQL query?
For example to count number of items with status "Stated" and with status "created".
Additional conditions may apply, e.g. where id is in definite interval.
Assuming you're using PHP, first you're better off with correcting those unrecognized booleans. You have True where it should have been true (alternatively TRUE for PHP) for it to evaluate the data right.
$jsStr = preg_replace_callback(
'~(?<=[,{[])(".+?"\s*:\s*)(true|false)(?=\s*[,}\]])~i',
create_function('$m','return $m[1].strtolower($m[2]);'),
$jsStr);
Then to be able to process it you want to use the json_decode() function.
$parsed = json_decode($jsStr);
// see the result if you like:
// print_r($parsed);
Ultimately if you want to extract some specific information on the client side (using Javascript) you can use the Array filter() function or a loop if you're not using jQuery. Otherwise you can use the jQuery filter() function with necessary conditions.
If you want to do this in PHP, after the string is parsed into JSON you can use the solutions that apply to Javascript.
In my HTML code I have
<option name="PRODUCTS" value="3">Products</option>
I need get both the name and value values in my server side Perl function through my Perl CGI param.
I can only get the value, is there a way to get the name also?
<option name="PRODUCTS" value="3">Products</option>
An <option> element does not have a name attribute, so this is invalid HTML and the browser will ignore it (except that it might make it available to JavaScript).
When the form is submitted, the browser will send to the server the name of the select coupled with the value of the selected option. This is the only information that the server will receive.
If you want to get 'PRODUCTS' then you will need to either:
Include it in the value: value="3-PRODUCTS" and then my ($number, $word) = split '-', $value
Look up the word that 3 is related to on the server (e.g. in a hash embedded in the script, or with a database query).
CGI::param() with no parameters returns all the names. Then CGI::param($name) will return all the values for a given name.
for my $name (CGI::param()) {
for my $val (CGI::param($name)) {
print "name: $name, value: $val\n";
}
}
Update: sorry, misread "option" as "input". option's name attribute isn't sent to the server at all, so there's no way to tell what it was without also having the html itself. You could add javascript to set a hidden input field to the option's name when it's chosen, though. What does populateCatArray do?
I would use the Vars method if there is some doubts on what is getting passed, especially if you have thee same 'name' used multiple times or a js its producing elements that don't exist on the page normally.
use CGI;
use Data::Dumper
my $q = new CGI;
print
$q->header({ type=>'text/plain' }),
Dumper($q->Vars);
i have one doubt.I already stored some data in database.my constraints is how to list out all the data inside drop down list box using html.
I am using servlet.the form designs using Html.MY constraints is if i run the html form the form designed displayed
It contained one dropdownlist.
My constraints is i want to diaplay all the records in the dropdown list.My servlet program do action based on the selction of drop down list.
If you have php , you can following this things.
Using PHP could achieve this one.
require 'DB.php' ;
$db = DB::connect("argument"); // Connect the data base
print '<select name="option" >';
$q = $db->query( "SELECT * FROM dishes "); // execute the require query
while ($row = $q->fetchRow()) { // Fetch each row valeus.
{
print " <option> " ;
print $row[0]; // put into select option
print "</option>" ;
}
print "</select> ";
Your question is very vague and unclear. However, here are the steps you would need to do. You should be able to search for how to do each of these if you're not sure. All this is done in server-side code.
Connect to the database.
Fetch the data from the database, usually as an array of rows.
Output the start of the dropdown: <select name="records">
Loop through each element in the array. For each one, output the element: <option>NAME</option>
Close the drop down tag: </select>