SQL return displaying incorrectly - sql

I have a table which displays data from a SQL table onto my site, the issue I am having is depending on the alpha data being displayed the placement of the word moves, i.e. when displaying the word GOOD it displays in the position I want but when it displays the word FAIR it then shift to the left.
Any advice on how to stop this from happening ?

If you're using a while loop to get results from your data table,you can use php to create a new element for displaying your data like so:
$open = mysqli_query($connection, $query)
while($row = mysqli_fetch_assoc($open)) {
$DataName = $row['NameOfData']
echo "<h3>$DataName</h3>"}
Replace NameOfData with the row you're trying to get. Look up "PHP Mysql row outputting" for more information

Related

C# stumped with screen scraping issue on aspx page

I'm having some trouble scraping some HTML that I'm getting from a postback on a site. It is an aspx page that I am trying to get the generated HTML from.
I have looked at the cookie data and session data and forum data being sent with Chrome developer tools and I still cannot get the page to respond with the search results despite mimicking almost all of it in my code.
There are 3 dropdowns on the page, 2 of which are pre-populated when you first visit the page. After choosing values for the first 2 (it does a postback every time you select on those two), it will populate values for the 3rd drop down. Once selecting a value in the 3rd drop down, you hit the search button and the results come back in a table below that.
After hitting the search button and getting the results on the screen, I went into developer tools and grabbed all of the values that looked relevant (especially all form values) and captured them in my code, but still no luck. Even captured the big viewstate exactly.
Here is a code sample of many code samples that I've tried. Admittedly, I'm not very familiar with some of these classes and I've been trying different code snippets.
I'm not sure if I'm doing it wrong in my code or if I'm just missing form data or cookies to make it execute the POST and return the correct data. My code currently returns HTML from the page back to the responseInString variable, but the HTML looks like it's the first version of the page (as if you visited it for the first time) with no drop down boxes selected and the 3rd is not populated with any values. So I don't know if my code is actually hitting the code-behind and doing the form POST to make it return data.
Any help would be greatly appreciated. Thank you!
using (var wb = new WebClient())
{
var data = new NameValueCollection();
data["_EVENTTARGET"] = "";
data["_EVENTARGUMENT"] = "";
data["_LASTFOCUS"] = "";
data["_VIEWSTATE"] = "(giant viewstate)";
data["__VIEWSTATEGENERATOR"] = "D86C5D2F";
//3 more form input/select fields after this with values corresponding to the drop downs.
wb.Headers.Add(HttpRequestHeader.Cookie,
".ASPXANONYMOUS=(long string);" +
"ASP.NET_SessionId=(Redacted);" +
" _gid=GA1.2.1071490528.1676265043;" +
"LoginToken=(Redacted);" +
"LoginUserID=(Redacted);" +
"_ga=GA1.1.1195633641.1675746985;" +
"_ga_38VTY8CNGZ=GS1.1.1676265043.7.1.1676265065.0.0.0");
wb.Headers.Add("Sec-Fetch-Dest", "document");
wb.Headers.Add("Sec-Fetch-Mode", "navigate");
wb.Headers.Add("Sec-Fetch-Site", "same-origin");
wb.Headers.Add("Sec-Fetch-User", "?1");
wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
var response = wb.UploadValues("(the web page url)", "POST", data);
string responseInString = Encoding.UTF8.GetString(response);
return responseInString;
}

XPath selector returns empty list

I'm trying to scrape data from store: https://www.tibia.com/charactertrade/?subtopic=currentcharactertrades&page=details&auctionid=12140&source=overview
There is no problem with getting data from 1st and 2nd table, but when I goes down, xpath returns only empty lists.
even tried to save response in file:
scrapy fetch --nolog "https://www.tibia.com/charactertrade/?subtopic=currentcharactertrades&page=details&auctionid=3475&source=overview" > response.html
for table with skills everything works good
sword = response.xpath('//div [#class="AuctionHeader"]/a/text()').get()
but when it comes to getting for example gold value, I get only empty list:
gold = response.xpath('/html/body/div[3]/div[1]/div[2]/div/div[2]/div/div[1]/div[2]/div[5]/div/div/div[3]/div[2]/div[2]/table/tbody/tr/td/div/table/tbody/tr[2]/td/div[2]/div/table/tbody/tr[3]/td/div/text()').get()
In chrome/firefox both selectors works smooth, but in scrapy only 1st one
I know there might be some problems with data updated by javascript, but it doesn't look like this case
Doesn't look like it's a javascript problem. Think you're not getting your XPATH selectors correct. It's best to be as specific as possible and not to use multiple nodes down. Here we can select the attribute TableContent to get the tables you want. There you can select each individual table that you require if needed.
Code Example
table = response.xpath('//table[#class="TableContent"]')[3]
gold_title = table.xpath('tr/td/span/text()')[2].get()
gold_value = table.xpath('tr/td/div/text()')[2].get()
output
'Gold: '
'31,030'
Explanation
Using the class attribute TableContent, you can select which table you want. Here I've selected the table with the gold values. I've then selected each row and the specific element which has the gold value. The values are hidden behind span and div elements. get() returns a string, getall() returns a list.

Confirmation Draw has completed

I have created a custom button that will allow users to select with columns to output to CSV so the button is not created as part of the table initialization. I have a modal that pops up with checkboxes created off the column headers for selection. It is worth noting I have regex search on each column header. The issue is I am using server side processing and as a result the only exported rows are those visible. As a work around I have set it up to get the page.info().recordsDisplay and set the length of the page to that and draw. The modal pops up and says it is loading data from server once table is fully populated the HTML of the modal will change to the checkboxes for export. Once exported the table is reverted back to the default length. What I need to do is capture when the rows are fully rendered so I can do the HTML switch. Right now I am setting a timeout. The data can take a while to populate as there are some 13k rows if now search is applied. What is the best way to do this and is there a more efficient way?
var tableHeaders = [];
var table = $('#example').DataTable().columns().every( function () {
tableHeaders.push( $(this.header()).text() );
});
var pageLength = table.page.info().length;
table.context['0']._iDisplayLength = table.page.info().recordsDisplay;
table.draw();
There could be an issue with server-side processing parameters start/length that define the portion of data being requested from the server upon each draw.
If your source data has huge number of rows, chances are they're not sent all at once to make use of server-side processing. So, you can try to manipulate those parameters.
Alternatively, you may try to make use of draw event fired upon each redraw.

Flex 4: Binding Label To Dataprovider (SQLite)

Let me start off by saying this is my first Flex project, so I've been reading a lot, learning a lot, but am still struggling to make this work.
I am trying to display records from an SQLite database within my Flex mobile application. I have the input form saving data correctly to the database, and I have a datagrid that is outputting the records (so I can confirm everything looks good). However, my problem is making the data readable.
I want the user to be able to select an identifier from either a drop down or a list (even if it's just a 1 column datagrid), and have the labels to the right update to reflect that information.
My thought was to have the datagrid setup as such:
<mx:DataGrid x="10" y="10" width="100" height="500" id="SiteSelector" dataProvider="{siteData}" includeIn="SiteDetails" change="SiteChoice(event)">
<mx:columns>
<mx:DataGridColumn headerText="Site Name" dataField="SiteName" />
</mx:columns>
</mx:DataGrid>
The datagrid shows the Site Name without issue from the database. The change function:
private function SiteChoice(event:ListEvent):void
{
var statement:SQLStatement = new SQLStatement();
statement.sqlConnection = connection;
statement.text = "SELECT * FROM SITES WHERE SITE_ID = ?"
statement.parameters[0] = SiteSelector.selectedItem.SITE_ID;
statement.execute();
siteDetails.source = statement.getResult().data;
}
I also have declared:
[Bindable] private var siteDetails:ArrayCollection = new ArrayCollection();
My question is, how do I get a label to reflect specific column data from the table? I believe I plug it with the siteDetails as the data provider, but how do I specify that I want, say for instance, the address or site contact to appear in a label?
<s:Label text="{siteDetails}" id="ExternalIPLBL"/>
I've been searching Google and the Adobe Developer Connection/livedocs/cookbooks pretty heavily over the last week and still have yet to come up with a working solution.
Try this:
first, you can display a field form an arraycollectiokn like this
siteDetails.getItemAt(0).Street}
The dynamic is the getItemAt(0) Value. Register an clickhandler to the datagrid and debug the event. Somewhere there, the selectedIndex is a part of that event.
By the way, id should start with small letters ->ExternalIPLBL
Set an Breakpoint in the eventhandler, try to find out, where your data are (selectedIndex) and set the label text in the eventhandler:
ExternalIPLBL.text = event.selectedIndex[Street].
BR
Frank

Problem retrieving values from Zend_Form_SubForms - no values returned

I have a Zend_Form that has 4 or more subforms.
/**
Code Snippet
**/
$bigForm = new Zend_Form();
$littleForm1 = new Form_LittleForm1();
$littleForm1->setMethod('post');
$littleForm2 = new Form_LittleForm2();
$littleForm2->setMethod('post');
$bigForm->addSubForm($littleForm1,'littleForm1',0);
$bigForm->addSubForm($littleForm2,'littleForm2',0);
On clicking the 'submit' button, I'm trying to print out the values entered into the forms, like so:
/**
Code snippet, currently not validating, just printing
**/
if($this->_request->getPost()){
$formData = array();
foreach($bigForm->getSubForms() as $subForm){
$formData = array_merge($formData, $subForm->getValues());
}
/* Testing */
echo "<pre>";
print_r($formData);
echo "</pre>";
}
The end result is that - all the elements in the form do get printed, but the values entered before posting the form don't get printed.
Any thoughts are appreciated...I have run around circles working on this!
Thanks in advance!
This is what I did -
$bigForm->addElements($littleForm1->getElements());
Then, iterated over the form elements like so:
$displayGroup1 = array();
foreach($bigForm->getElements() as $name=>$value){
array_push($displayGroup1, $name);
}
Then, add a displayGroup to $bigForm:
$bigForm->addDisplayGroup($displayGroup1, 'test',array('legend'=>'Test'));
And repeat for multiple display groups.
I'm sure there is a better way to do it, but I'm currently unable to find one out.
This is currently one way I can think of to retrieve all the form values via $_POST, if a form is made up of one or more subforms.
If any one knows of a better solution, please post it!
A Zend_Form does not automatically retrieve values from the $_POST variable. Use:
$bigform->populate($_POST)
Or alternatively:
$bigform->populate($this->_request->getPost())
Another thing to keep in mind is that if the sub forms contain elements with the same name they will clash. To check this use the option View => Page Source in your browser and look at the HTML that is generated. When you see two <input> elements with the same name attribute, then this is the problem.
The Zend solution for this is to give the sub form elements different names using setElementsBelongTo:
$littleForm1->setElementsBelongTo('littleForm1');
$littleForm2->setElementsBelongTo('littleForm2');
Furthermore you should leave out these calls as they serve no purpose (but you should set them for the $bigForm):
$littleForm->setMethod('post');