LINQ - SQL Display data in html table - sql

I would like to perform a select statement using a DataContext from the code behind page and then display the results in an HTML table.
Best ways to do this?

The best way to do this as always depends. One of the fastest and easiest way would be to directly bind the data to a DataGrid.

If you really need to create html table you can use a literal in frontend and add the literal text from back end
eg <asp:Literal ID="ltrUser" runat="server"></asp:Literal>
In backend code
if (!IsPostBack)
{
var data = datasource;
ltrUser.Text = "<table><tr><td>";
ltrUser.Text += "<h1>"+ data.name + "</h1>";
ltrUser.Text += "</td></tr></table>";
}

Related

How to insert value to muliple column from textarea use PHP?

I want to insert value to multiple database from Textarea, example i enter value to textarea and submit :
1|Vo Huu Nhan 1
2|Vo huu Nhan 2
3|Vo Huu Nhan 3
After submit i want insert value before "|" to column tap and value after "|" to column player
My code :
<form action="Post.php" method="POST">
<textarea name="tapphim"></textarea>
<input type="submit" value="submit"/></form>
Please help me create Post.php file right way
Firstly which programming language are you using?
For all programming languages, the concept is similar.
Take the input text from the textarea , then explode the '|' out of it ....then it becomes an array .
After that insert the first value of the array into the tap column then the other one into the players column.
The expression might look like this:
array[0] into tap column,
array[1] into players column
But i will like to know the programming language you want to use in achieving this
I hope it enlightens you.
Since you are using php
`if(isset($_POST['tapphim']) && !empty($_POST['tapphim'])
{
$textAreaInput = explode("|", $_POST['tapphim']);
$tapValue = $textAreaInput[0];
$playerName = $textAreaInput[1];
$sql = mysqli_query($con,"insert into
playersTble(tap,players)
values('$textAreaInput','$playerName");
if($sql){
echo "data saved!";
}
}`
i Hope this solves your problem.
Make sure you read about sanitizing input in PHP
Try this,
if(isset($_POST['tapphim'])){
$lineSplit=explode("\n", $_POST['tapphim']);
foreach ($lineSplit as $line) {
$splitArr=explode("|", $line);
$fieldOne=$splitArr[0];
$fieldTwo=$splitArr[1];
// insert to db
}
}
You may want to use htmlspecialchars($_POST['tapphim']) or mysql_real_escape_string($_POST['tapphim']) to clear post variables from dangerous characters for security reasons especially if you don't use PDO connection to connect your database.

Populate the data in its own field

How can the data be populated in its own field? See the field called 'vSoup Text'.
SELECT [iFormID]
,[iPracID]
,[iPatID]
,[vFormName]
,[vSoapText]
,[tHTML]
,[iUserID]
,[dDATE] FROM CustomForm where iPatID = 40 and vFormName = 'Diabetes Screening'
I need to break the data when you see '/br'
The only way that I've found to do this is by using a function. You could use SSIS, but the way that I've used is using a function.
https://sqlperformance.com/2012/07/t-sql-queries/split-strings

can there be a tooltip with data from the database

I need to know can there be a tooltip populated with data from database to be displayed in the tooltip.
something like the tooltip should contain
name stauts
abc active
xyz active
pqr active
name and status are retrived from db
I need this tooltip onmouseover, am using CJSON decoded to render the content
i did go google but hardly did find that i would throughly understand and implement.
can anyone out there has any ideas for what am looking.
There is a extension named yii-bootstrap, which described clearly here.
For using tooltip easily in this extension, just look here.
I use cluetip for this. Its not related to Yii but will give you some idea :
JS
function renderInfoTips(opts){
var elements=$('#'+opts.form).get(0).elements;
for(i=0; i<opts.tips.length;i++){
$(elements[opts.tips[i].field]).parent().prepend(opts.tips[i].tip);
}
var clue_opts={arrows:true,splitTitle: '|',closePosition: 'title',sticky:true,dropShadow:false,mouseOutClose:true,
onShow:function(ct, ci){
if(!$.browser.webkit) $(ct).css('top',$(ct).position().top- 30+'px');
}
}
$('#'+opts.form).find(".infotip").cluetip(clue_opts);
}
PHP
function setInfoTipsJavascript($form_id,infotips){
if (count($this->infotips) <1 ) return '';
//get all tip names
$names_csv=join(',',array_keys(infotips));
//get tips details from db
$query="select name, description from infotips where FIND_IN_SET(name ,'$names_csv')";
//run the query, in Yii you have to use InfoTipsModel , I have skipped that portion
//$infotipS , lets say this is query object
$tips=array();
while($tip=$infotipS->Assoc()){
$this->infotips[$tip['name']]['tip']="<a href='javascript:void(0)' class='infotip' title='|{$tip['description']}'> </a>";
$tips[]=$this->infotips[$tip['name']];
}
$tips=json_encode($tips);
$script="\nrenderInfoTips({\"form\":'{$form_id}', \"tips\":{$tips}});\n\n";
echo $script;
}
I am sharing this hoping this will give u some idea. Its obvious you have to : create infotips table, a model for that, and create a widget etc to fetch infotips related to your form fields . As someone suggested, if you are using Bootstrap, you have better way to do that.

dojo query for multiple values with setQuery

I'm having trouble getting the syntax right for a setQuery method call for multiple values, i.e.
setQuery({x : 1}) or setQuery({x : 2})
combined. Or do I need to use filter?
In case you are using Dojo Store API I think one way to query using function is described here
You can modify it like this
store.query(function(item){
return item.x == 1 || item.x == 2;
});
That will depend on the store you are using.
In order to do that easier, you should use dojox.data.AndOrReadStore
Dojo tool kit, and or read store
using that store you can use setQuery as:
yourgrid.setQuery({complexQuery:"x:1 OR x:2"});

Does CDbcommand method queryAll() in yii return indexed entries only?

I am trying to retrieve data from a simple mySql table tbl_u_type which has just two columns, 'tid' and 'type'.
I want to use a direct SQL query instead of the Model logic. I used:
$command = Yii::app()->db->createCommand();
$userArray = $command->select('type')->from('tbl_u_type')->queryAll();
return $userArray;
But in the dropdown list it automatically shows an index number along with the required entry. Is there any way I can avoid the index number?
To make an array of data usable in a dropdown, use the CHtml::listData() method. If I understand the question right, this should get you going. Something like this:
$command = Yii::app()->db->createCommand();
$userArray = $command->select('tid, type')->from('tbl_u_type')->queryAll();
echo CHtml::dropdownlist('my_dropdown','',CHtml::listData($userArray,'tid','type'));
You can also do this with the Model if you have one set up for the tbl_u_type table:
$users = UType::model()->findall();
echo CHtml::dropdownlist('my_dropdown','',CHtml::listData($users ,'tid','type'));
I hope that gets you on the right track. I didn't test my code here, as usual, so watch out for that. ;) Good luck!