How to customize a dynamic website in PHP and JS? - javascript

I am working on a website to analyse energy data that I get from several remote meters. I'm using JS, PHP and mySQL. I developed the website with one client's data (specific type and numbers of remote meters). This is the first website I did, I have a lot to learn.
There are the steps:
Login form // same for everyone
PHP check login // same for everyone
Index page // same for everyone
Javascript with AJAX function to post data (range of date) to a php file (calculation.php) to calculate stuff // JS file is the same for everyone
PHP file gets the data from mySQL and does many calculation about energy stuff, then echoes it
The JS file gets the data (via AJAX) and then displays graphs via google Chart library
The problem is that the PHP file that gets the AJAX POST (end of step 4 and step 5) won't do the same calculation for every client. So I don't know what to do, I'm a bit lost.
I thought at:
Putting a condition in the PHP file for every client, like "if
client_id=X" // this seems too bad with dozens of clients
Writing a different PHP file for every client. Writing the name of
this PHP file in the mysql table "clients". Doing an intermediate php
file called by AJAX that will check the client_id against the
database then "include" the specific PHP file into the temporary one.
Writing the PHP PDO request in a string type into the table
"clients" then query it from the PHP file "calculation.php". The PHP file will do the correct command.
These solutions don't seem good to me (maybe the third?). Do you have any idea? Thank you in advance.
EDIT Example of php code
first client:
$reponse1 = $bdd->prepare("SELECT DATE_FORMAT(Date, '%H:%i') AS timekey, AVG(Value) FROM meter1 WHERE Date>='$from' AND Date<='$to' GROUP BY timekey");
$reponse1->execute();
$myArrayLP24temp1['Hour']= $reponse1->fetchAll(PDO::FETCH_COLUMN, 0);
$reponse1->execute();
$myArrayLP24temp1['Value']= $reponse1->fetchAll(PDO::FETCH_COLUMN, 1);
$reponse2 = $bdd->prepare("SELECT DATE_FORMAT(Date, '%H:%i')AS timekey, AVG(Value) FROM meter2 WHERE Date>='$from' AND Date<='$to' GROUP BY timekey");
$reponse2->execute();
$myArrayLP24temp2['Value']= $reponse2->fetchAll(PDO::FETCH_COLUMN, 1);
for ($ii=0; $ii<24*4; ++$ii){
$meter1NoRound=$myArrayLP24temp1['Value'][$ii]*4;
$meter2NoRound=$myArrayLP24temp2['Value'][$ii]*4;
$meter1=round($meter1NoRound,1);
$meter2=round($meter2NoRound,1);
$myArrayLP24['rows'][]= array('c' => array( array('v'=>$myArrayLP24temp1['Hour'][$ii]), array('v'=>($meter1)), array('v'=>($meter2))));
second client:
$reponse1 = $bdd->prepare("SELECT DATE_FORMAT(Date, '%H:%i') AS timekey, AVG(Value) FROM meter1 WHERE Date>='$from' AND Date<='$to' GROUP BY timekey");
$reponse1->execute();
$myArrayLP24temp1['Hour']= $reponse1->fetchAll(PDO::FETCH_COLUMN, 0);
$reponse1->execute();
$myArrayLP24temp1['Value']= $reponse1->fetchAll(PDO::FETCH_COLUMN, 1);
for ($ii=0; $ii<24*4; ++$ii){
$meter1NoRound=$myArrayLP24temp1['Value'][$ii]*4;
$meter1=round($meter1NoRound,1);
$myArrayLP24['rows'][]= array('c' => array( array('v'=>$myArrayLP24temp1['Hour'][$ii]), array('v'=>($meter1))));
The examples above show two differents code. The first one is for a client with two meters, the second one for a client with one meter. It can be up to 10 meters, and sometimes there will be sub meters that I will have to add up sometimes not. So the code is different for every client (except for clients with the exact same configuration, but that won't happen very often).

Why not storing the variable values in data base ?
Then, when client comes you have all the require infos to make your calculation.
Think simple and standardize the more you can.
Never forget that a good developer is a lazy person ;-)
EDIT
When you're saying :
"The problem is that the PHP file that gets the AJAX POST (end of step 4 and step 5) won't do the same calculation for every client."
What do you mean ?
The calculation formula is different for each client ?
The values to use in the formula are different for each client ?
The way i understood your question is in the first case.
Whatever, for both cases, store what you need in DB and use it as it comes with the client.
May be i didn't understand well what you need. If it is, please, send a piece of code to illustrate your problem.

Related

How to transfer array values in JS to html before the file switches using Ajax

This is the HTML code in file 1, which is calling the function. It is linked to javascript
<form id='next' action='file2.html'>
<button id="nextTwo" onclick="nextTwo()">next2</button>
</form>
This is the JS code that receives the function.
function nextTwo(){
document.getElementById('question').innerHTML=question
}
It is searching for the id before the file changes to where the id is.
Every time I press the button that calls the function it gives me:
"TypeError: Cannot set properties of null (setting 'innerHTML')"
This is because it is searching for the id of "question" in file 1, but the id is in file 2. It tries to find the id in file 1, then it switches to file 2, where the id of "question" is.
How do I make it so that is switches to file 2 first, then searches for the id.
Maybe an if statement with a condition, if the file is switched, although I don't know the how to write that.
Thanks for your help.
This is my Js code, how do I place the arrays value into the file 2 using ajax?
let ants;
let question;
let squestion;
function check() //CHECK
{
switch(1){ //different header number is fine but do '' BUT input box will still be there
case 0:
ants = ['calculations']
question=["Element Symbol that has the atomic number of... ","atomic mass of (round to nearest whole number)..."]
squestion=["1. 50","2. 2","3. 20","4. K"]
case 1:
ants = ["0 (all atoms have a charge of 0)","11","11","4","9","Be","8","8","8"]
question=["Sodium has 11 protons and an mass of 23. What is the...","An atom has an atomic# of 4 and 5 neutrons What is the...", "Oxygen has 8 electrons and a mass of 16"]
squestion=["charge","atomic#","#of electrons", "#of protons","Mass","element symbol", "#of protons", "atomic#", "#of neutrons"]
// ants = ["Sn ","He ","Ca ","39 ", "32 ","Sn ","He ","Ca",]
// question=["Element Symbol that has the atomic number of... ","atomic mass of (round to nearest whole number)..."]
// squestion=["1. 50","2. 2","3. 20","4. K"]
break;
case 2:
ants = ["Carbon", "Chlorine", "Bromine",'Br',"Li","Sc","2","8","8" ]
question=["Carbon", "Chlorine", "Bromine", "Helium",'Br',"Li","Sc" ]
squestion=[]
}
There is a better way to go about this.
By design, forms do not communicate two-way. They take the data entered by the user and carry it over to the processing file (defined by the action= parameter on the form tag). The user is navigated away from the first webpage, and the view changes to that processing file - and it isn't supposed to go back to the first file again. Forms are very basic, primitive constructs.
This is why forms have been almost entirely replaced by AJAX. AJAX is a very simple JavaScript construct (made even simpler via jQuery - TANGENT: although jQuery is no longer recommended because modern JavaScript has made the process much easier - but the jQuery $.ajax() method still works fine and there is tons of info about how to use it).
AJAX allows you to send data from a web page to a back-end (server-side) file that receives any data you send it (optional), does something (optional), and returns new data (optional). The page the user is on need not change, blink or flash. New data received from the server-side file can be received and actively used before returning control to the user... So this sounds like exactly what you need it to do.
The back-end (AJAX) processing file is written in a server-side language (PHP, NodeJS, ASP.Net, Python, etc - PHP is a very popular one for AJAX), but you did not specify which one you wish to use, which is likely why no one responded to your question sooner.
Here are some references that might help. I chose jQuery examples because the AJAX code block $.ajax( //code goes here ).done() is very simple. To do AJAX in pure JavaScript, look for information regarding the Fetch API (newest), and XmlHTTPRequest (older).
Simple jQuery example
Ajax explained with jQuery
Another simple example with explanation
Here is a pure javascript video tutorial (5 mins)
After reviewing the examples, you can construct a basic AJAX test on your side and, if you have any trouble with it, ask another question specifying which language you are trying to do this with, and showing your code so far.

Show same content at same time in different browser

I am developing a numbers game where users will buy numbers and after 2 days winners will be drawn.
I am using PHP for the backend and jQuery for the frontend.
My problem is when drawing occurred user on different browser can't see same numbers, these draw numbers are being generated by PHP.
I was thinking maybe I can build these game by PHP and Javascript but it looks not easy. Can you guys please suggest some alternative? How can I improve this code to show the same number on the different browser?
I have the idea that it is not possible to generate a random number for each request. Maybe I can save the number in the database and then get this number in PHP such that the number will be unique for each request.
The actual issue is to create the same content for each user in different browsers. Any help would be really appreciated.
Javascript:
var myTimer = setInterval(checkDrawDate, 1000);
function checkDrawDate() {
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
var x = new Date(dateTime);
var y = new Date("{{$drawDate}}"); //this is laravel variable which contain drawdate e.g. 2017-07-05
if(x >= y){
drawNumber();
}
}
function drawNumber(){
$.get("{{ route('ajaxcomparepowerball') }}",{'gameId': gameid}, function(res){
$('#mybets').html(res.html);
});
}
PHP:
public function ajaxDrawNumber(Request $req){
return rand(0,49);
}
A Cron Job will be needed to implement this functionality. As you are drawing a number on particular time (after $drawDate in your case). So the cron job will execute once in day, check whether $drawDate for each game is today or passed. If condition true, $drawDate <= now, call a function to generate random draw number rand(0,49) and save it to database corresponding to gameid of matched games(having $drawDate <= now).
By doing this, a lot Javascript work will be reduced. In JS, then need to hit an ajax request with gameid to fetch record having draw number for particular game from database. If record not found, it means random number not drawn yet.
I think you are using Laravel, so to schedule tasks in laravel visit here.
Here some possible solutions.
If you need the same data modified for users in real time I think the best option is WebRTC, quick start here. And here a simple example sending strings in real time between clients.
If you also need interaction server to client you could use server-sent events.
You could perform a bidirectional communication between browser and a server using WebSockets. You can send and receive event-driven responses. Using a database you could communicate two clients.
The easiest is using a database to store the information and perform ajax to send data to the server (and database) and server-sent events to send data to the clients.
Basic Server-sent event example:
Javacript:
var evtSource = new EventSource("myserver.php");
evtSource.onmessage = function(e) {
// listening for new messages here
alert(e.data)// e.data is mynumber
}
Php (myserver.php)
<?php
header('Cache-Control: no-cache');
header("Content-Type: text/event-stream\n\n");
while (1) {
//perform a query in your database with your driver
$result = mysql_query("SELECT mynumber FROM mytable WHERE user = 1");
$row = mysql_fetch_assoc($result);
echo $row['mynumber'];//<-- sending mynumber to client
ob_end_flush();
flush();
sleep(1);// <-- this is every second, but you could fire this with ajax or some other event.
}
This code send a number from server to a client that is listening. If a user made a change, one possibility is that client send an ajax to update some value in the database. So, at the same time, the ajax server could send this as an update to clients listening. In that way the whole process is completed.
I think all you need is this. Call a function in every, say 5 seconds or less and fetch data from server and update it in the page.
window.setInterval(function(){
updateNumber();
}, 5000);// set for every five seconds
function updateNumber(){
//ajax code to fetch live data and append the data in the numbers container
}
And dont forget to cross check the data before saving the numbers in the server.
Hope it helps.!!!
To save and maintain users state, key value store like Aerospike can be used. It is very easy to save and retrieve data in key value store. In above case we just have to generate a unique key using gameId, userId and date. And save user's data against the unique key.
To get started with Aerospike php client following is Aerospike php client
If data is present against the unique id for that particular user just return it, else create the new random number save it against the unique key and return it. Please be careful while creating unique key. Instead of using server side date-time please send date in ajax call request so there will not be any issue with time zone. It will be always user's timezone and there will not be any issue if server is in different timezone and user is in different timezone.
function drawNumber(){
$.get("{{ route('ajaxcomparepowerball') }}",{'gameId': gameid,'date':user-timezone-date}, function(res){
$('#mybets').html(res.html);
});
}
Here "user-timezone-date" should be fix date format like 'MM-dd-yy' which will indicate the same day. hours or seconds should not be included while generating unique key otherwise at the time of retrieving the user's state; generating particular unique will be changed every hour or every second and whole purpose of of doing this will be shattered.
I am new to StackOverFlow so I am not able to comment on the answers. In case of corn job as well we have to be careful with time-zones if server and users are in different time zones. Otherwise user's will see different random number before user's day is complete. Please improve answer by commenting on it and suggestions are always welcome.

How to pass data between Django module/app functions without using database in asynchronous web service

I've got a web service under development that uses Django and Django Channels to send data across websockets to a remote application. The arrangement is asynchronous and I pass information between the 2 by sending JSON formatted commands across websockets and then receive replies back on the same websocket.
The problem I'm having is figuring out how to get the replies back to a Javascript call from a Django template that invokes a Python function to initiate the JSON websocket question. Since the command question & data reply happen in different Django areas and the originating Javascript/Python functions call does not have a blocking statement, the Q&A are basically disconnected and I can't figure out how to get the results back to the browser.
Right now, my idea is to use Django global variables or store the results in the Django models. I can get either to work, but I beleive the Django global variables would not scale beyond multiple workers from runserver or if the system was eventually spread across multiple servers.
But since the reply data is for different purposes (for example, list of users waiting in a remote lobby, current debugging levels in remote system, etc), the database option seems unworkable because the reply data is varying structure. That, plus the replies are temporal and don't need to be permanently stored in the database.
Here's some code showing the flow. I'm open to different implementation recommendations or a direct answer to the question of how to share information between the 2 Django functions.
In the template, for testing, I just have a button defined like this:
<button id="request_lobby">Request Lobby</button>
With a Javascript function. This function is incomplete as I've yet to do anything about the response (because I can't figure out how to connect it):
$("#request_lobby").click(function(){
$.ajax({
type: "POST",
url: "{% url 'test_panel_function' %}",
data: { csrfmiddlewaretoken: '{{ csrf_token }}', button:"request_lobby" },
success: function(response){
}
});
});
This is the Django/Python function in views.py . The return channel for the remote application is pre-stored in the database as srv.server_channel when the websocket is initially connected (not shown):
#login_required
def test_panel_function(request):
button = request.POST.get('button', '')
if button == "request_lobby" :
srv = Server.objects.get(server_key="1234567890")
json_res = []
json_res.append({"COMMAND": "REQUESTLOBBY"})
message = ({
"text": json.dumps(json_res)
})
Channel(srv.server_channel).send(message)
return HttpResponse(button)
Later, the remote application sends the reply back on the websocket and it's received by a Django Channels demultiplexer in routing.py :
class RemoteDemultiplexer(WebsocketDemultiplexer):
mapping = {
"gLOBBY" : "gLOBBY.receive",
}
http_user = True
slight_ordering = True
channel_routing = [
route_class(RemoteDemultiplexer, path=r"^/server/(?P<server_key>[a-zA-Z0-9]+)$"),
route("gLOBBY.receive" , command_LOBBY),
]
And the consumer.py :
#channel_session
def command_LOBBY(message):
skey = message.channel_session["server_key"]
for x in range(int(message.content['LOBBY'])):
logger.info("USERNAME: " + message.content[str(x)]["USERNAME"])
logger.info("LOBBY_ID: " + message.content[str(x)]["LOBBY_ID"])
logger.info("OWNER_ID: " + message.content[str(x)]["IPADDRESS"])
logger.info("DATETIME: " + message.content[str(x)]["DATETIME"])
So I need to figure out how to get the reply data in command_LOBBY to the Javascript/Python function call in test_panel_function
Current ideas, both of which seem bad and why I think I need to ask this question for SO:
1) Use Django global variables:
Define in globals.py:
global_async_result = {}
And include in all relevant Django modules:
from test.globals import global_async_result
In order to make this work, when I originate the initial command in test_panel_function to send to the remote application (the REQUESTLOBBY), I'll include a randomized key in the JSON message which would be round-tripped back to command_LOBBY and then global_async_result dictionary would be indexed with the randomized key.
In test_panel_function , I would wait in a loop checking a flag for the results to be ready in global_async_result and then retrieve them from the randomized key and delete the entry in global_async_result.
Then the reply can be given back to the Javascript in the Django template.
That all makes sense to me, but uses global variables (bad), and seems that it wouldn't scale as the web service is spread across servers.
2) Store replies in Django mySQL model.py table
I could create a table in models.py to hold the replies temporarily. Since Django doesn't allow for dynamic or temporary table creations on the fly, this would have to be a pre-defined table.
Also, because the websocket replies would be different formats for different questions, I could not know in advance all the fields ever needed and even if so, most fields would not be used for differing replies.
My workable idea here is to create the reply tables using a field for the randomized key (which is still routed back round-trip through the websocket) and another large field to just store the JSON reply entirely.
Then in test_panel_function which is blocking in a loop waiting for the results, pull the JSON from the table, delete the row, and decode. Then the reply can be given back to the Javascript in the Django template.
3) Use Django signals
Django has a signals capability, but the response function doesn't seem to be able to be embedded (like inside test_panel_function) and there seems to be no wait() function available for an arbitrary function to just wait for the signal. If this were available, it would be very helpful

PHP retrieve new images from database

Apologies for the NOOB question but I’m still learning.
Firstly I’m not asking for someone to program the following problem for me or to give me the code. I’m merely looking for a bit of help with the logic and a bit of advice.
What I am trying to do
This is just an example, what I am trying to do is different but will use the same logic: I am trying to display a movie poster on my website, the user can than rate that movie between 0 - 5 stars, his/her rating will be recorded in a database, along with other users’ ratings. When he/she has finished his/her rating, a new movie poster needs to be displayed where he/she can again rate the poster and so it goes on until he/she is tired of rating movies.
The Logic
I AM ASSUMING I will need to use PHP here to store and retrieve the data
A Table will be created which contains different images and ratings corresponding to that movie’s rating, along with the number of users who rated the movie to calculate the average for the total rating
The Problem
How do I get the image to change once the user rated the image?
Is it possible to change an image src onclick with PHP like it is with Javascript?
If so how do I do it? Is it possible that I will need to use a combination of PHP and Javascript here?
Any help or advice will be greatly appreciated. Thank you in advance.
You definitely need to use both javascript and PHP to accomplish this.
I would approach it like this:
a) Use jQuery javascript library to make the javascript easier.
b) Write some javascript which responds to the user selecting a rating. You'd probably need to bind to the onClick event of your rating buttons.
c) When a rating button is clicked, the javascript functions should use jQuery.ajax to send the selected rating to the server via an HTTP POST. The data sent to the server would probably need to contain an ID to identify the movie, an ID to represent the user (so you can stop people voting more than once for the same movie), and the rating they chose.
d) On the server-side, you can write a PHP script to handle the vote submissions. It would check for the movie, and user ids, (stored in PHP's $_POST variable), and then save the rating to some database. It could then also send a response back to the client which would contain the next movie id, and the next poster. I would recommend you use json_encode to store this info in a way that's easy for the javascript to interpret.
e) Finally, back on the client side, your javascript code can react to the data sent back by PHP, by putting up a message like 'thank you for your vote', then changing the movie details on screen to replace them with the new one.
Your client-side code would look something a bit like this:
<img id="movie-poster" src="movie poster src" />
<ul>
<li class="rating-button">1</li>
<li class="rating-button">2</li>
<li class="rating-button">3</li>
<li class="rating-button">4</li>
<li class="rating-button">5</li>
</ul>
<script>
var currentUserId;
var currentMovieId;
$('.rating-button').on('click',function() {
$.ajax({
url: "URL of PHP script here",
type: 'post',
data: {'movieId':currentMovieId, 'userId':currentUserId, 'rating':$(this).text()},
dataType: 'json',
success: function(response) {
// this runs after your PHP script has responded
// update your page with the new movie here
alert('thanks for voting');
currentMovieId = response.newMovieId;
$('#movie-poster').attr('src',response.newMoviePosterSrc);
}
});
}
</script>
Your PHP script would look something a bit like this (you'll have to figure out all the database and user authentication bits yourself)
<?php
$user_id = $_POST['userId'];
$movie_id = $_POST['movieId'];
$rating = $_POST['rating'];
// check that the user is allowed to vote - possibly examine cookie for this
// check that rating is between 0 and 5
// check that the movie exists
// store results of vote in database
// load up another random movie from the database and send it back (in JSON format)
// assume details of new movie are in $new_movie =
header('Content-type: application/json');
echo json_encode(array('newMovieId'=> new movie id here, 'newMoviePosterSrc' => URL of new poster here));
exit;
You should also add some error handling to that code. EG, messages to display if there's a connection problem, or the movie ID isn't recognised or something.
This page has more info on how to select a random row from your database - IE to select at random the next poster to show:
How to randomly select rows in SQL?
Hopefully that should be enough to get you started.

how to resolve VERY LARGE URL problem for hyperlink...with jQuery or Javascript calling any perl,php etc. script on back

I have built UI, its like a search engine for BioProcess/Disease--> Genes. e.g., User can query: "Stem Cells" or "brain tumor"and in result it will give 50 to 5000 GeneIDs (essentially those are Numbers representing a uniqe Gene at NCBI database) .
Its free, you can try at : http://proteogenomics.musc.edu/genemesh/
Now, the problem is I am liking those GeneIDs to a NCBI site at once. For upto 200 or 400 GeneIDs I can get result fine. But for more than 500 GeneIDs I can get "URI TOO LARGE" error or somehow NCBI website can not accept huge query. I am trying to resolve this problem.
Can Javascript, OnClick write a file in UNIX /tmp file? or is there any better solution to this?
Any help/guidelines are great at this point...
thank you so much in advance,
Saurin
URL too LONG:
http://view.ncbi.nlm.nih.gov/gene/30980,31208,31442,31789,32083,32855,33156,33392,33498,34309,35197,35974,36057,38545,38701,42945,43162,43256,43288,43739,44900,45339,45775,3772082,260437,393632,406845,379537,379620,399306,100037057,100037058,100037249,10,40,43,60,104,133,174,182,185,186,187,197,207,208,210,238,240,269,284,285,317,324,328,332,335,351,355,356,358,361,366,379,387,388,396,429,462,466,472,482,558,567,573,575,576,577,581,595,596,598,604,648,650,664,672,673,675,706,712,754,761,768,771,800,836,841,842,847,857,860,875,885,889,890,891,902,960,970,978,983,999,1000,1018,1019,1021,1025,1026,1027,1029,1030,1031,1051,1082,1111,1116,1124,1131,1152,1231,1234,1272,1282,1284,1285,1286,1287,1288,1316,1432,1457,1459,1462,1464,1471,1474,1485,1490,1493,1499,1508,1512,1520,1543,1545,1571,1594,1600,1605,1612,1620,1622,1630,1633,1638,1641,1643,1649,1728,1755,1756,1803,1809,1814,1839,1854,1869,1909,1910,1942,1950,1956,1969,2012,2013,2014,2019,2020,2022,2034,2035,2044,2045,2046,2048,2050,2051,2052,2064,2066,2067,2068,2071,2100,2149,2166,2173,2246,2247,2250,2251,2254,2260,2263,2264,2272,2289,2290,2305,2308,2309,2321,2335,2475,2542,2547,2574,2579,2621,2627,2670,2734,2735,2736,2737,2738,2740,2849,2890,2896,2901,2908,2925,2932,2936,2939,2944,2947,2950,2952,2956,3073,3074,3082,3090,3091,3104,3105,3106,3115,3122,3123,3146,3161,3162,3181,3191,3215,3240,3265,3309,3315,3324,3371,3373,3383,3384,3397,3398,3417,3479,3480,3481,3482,3485,3486,3487,3491,3553,3558,3561,3565,3566,3569,3574,3575,3596,3597,3598,3603,3611,3621,3630,3632,3645,3672,3685,3688,3717,3732,3738,3741,3766,3785,3791,3814,3815,3845,3897,3910,3912,3913,3915,3918,3925,3945,3956,3958,3981,3987,4035,4087,4088,4089,4133,4137,4145,4147,4152,4155,4172,4175,4192,4193,4194,4241,4255,4267,4288,4292,4303,4312,4313,4314,4316,4318,4320,4321,4323,4327,4350,4436,4440,4524,4548,4549,4552,4574,4601,4609,4654,4684,4691,4735,4745,4763,4771,4790,4804,4807,4808,4829,4830,4843,4851,4856,4893,4907,4914,4915,4916,4950,4978,4982,5015,5028,5030,5054,5080,5111,5118,5154,5155,5156,5159,5178,5241,5243,5266,5274,5276,5290,5294,5295,5328,5329,5334,5340,5395,5444,5468,5536,5538,5563,5566,5578,5579,5580,5581,5583,5584,5591,5594,5595,5599,5602,5629,5653,5663,5702,5708,5713,5725,5727,5728,5730,5743,5745,5747,5764,5781,5803,5805,5834,5835,5879,5880,5881,5888,5894,5898,5899,5900,5915,5921,5925,5934,5970,5978,5981,5992,6048,6091,6118,6165,6195,6275,6278,6284,6347,6382,6387,6416,6464,6469,6490,6502,6506,6507,6513,6598,6606,6608,6622,6647,6648,6649,6657,6659,6660,6662,6663,6664,6667,6670,6678,6695,6697,6714,6717,6770,6772,6774,6790,6853,6855,6863,6892,6900,6948,7012,7013,7015,7018,7020,7025,7040,7042,7054,7057,7076,7078,7105,7124,7153,7157,7161,7168,7175,7185,7186,7248,7249,7258,7262,7276,7277,7283,7298,7422,7428,7431,7442,7447,7468,7474,7490,7508,7515,7517,7518,7520,7525,7545,7799,7849,7852,7980,8028,8038,8061,8089,8140,8190,8301,8372,8484,8507,8577,8605,8650,8678,8682,8692,8718,8737,8741,8742,8743,8745,8754,8771,8772,8788,8795,8797,8811,8828,8829,8841,8842,8848,8851,8862,8871,8877,8928,8930,9077,9100,9113,9141,9148,9156,9173,9211,9212,9232,9334,9353,9423,9429,9444,9445,9447,9459,9507,9518,9535,9545,9588,9681,9806,9833,9844,9961,10036,10135,10209,10215,10313,10362,10371,10381,10401,10472,10512,10530,10572,10620,10630,10642,10743,10763,10776,10855,10893,10991,11009,11010,11013,11065,11093,11095,11096,11141,11156,11162,11186,11191,11200,11235,11284,22865,22933,22943,23136,23152,23162,23209,23261,23308,23336,23435,23469,23627,23654,23705,25776,25792,25855,26013,26038,26050,26136,26256,26471,26524,27122,28514,29103,29108,29126,29997,29998,30001,50618,50859,50943,51050,51147,51199,51213,51230,51305,51330,51335,51438,51637,51668,51747,51763,53358,53615,53616,54106,54828,55210,55294,55553,55717,55752,55760,55859,56647,56920,57124,57142,57447,57448,57670,60672,63827,64101,64386,64710,64805,65065,79659,79682,79944,80309,80332,80381,80781,81557,83483,83605,83667,83858,84148,84189,84280,84504,84525,84631,84654,84707,84708,91419,92140,112755,114798,116448,116986,121227,129787,139065,140885,146691,146956,160728,162979,163732,200895,253260,253738,259266,284217,284459,286527,338030,342945,375790,399473,406907,406991,407043,646555,728239,100133941,403412,396562,396783,751862,100125840,100125841,282862,100008679,11539,11545,11601,11622,11629,11651,11731,11783,11789,11799,11829,11920,11932,12028,12035,12140,12151,12211,12307,12308,12344,12389,12390,12505,12519,12554,12575,12578,12606,12767,12945,13003,13051,13176,13193,13197,13555,13730,13731,13732,13846,13866,14080,14102,14164,14254,14360,14397,14580,14609,14632,14633,14634,14714,14751,14825,14829,14910,15160,15218,15251,15413,15442,15529,15901,16153,16483,16542,16653,16765,16847,17125,17196,17246,17390,17395,17869,17920,18008,18015,18016,18040,18071,18072,18125,18128,18133,18208,18386,18507,18591,18595,18616,18708,18787,18792,18793,18996,18997,19090,19118,19122,19206,19211,19227,19247,19373,19377,19531,19557,19645,19650,19651,20423,20511,20713,20720,20848,20849,20852,20981,21333,21367,21375,21687,21826,21846,21948,22059,22339,22596,22612,23796,26362,26413,26417,26434,30878,30957,50490,50913,50914,54725,55992,56458,56717,60609,64930,66395,66471,67903,71722,74318,75409,76965,79401,81897,83485,107831,110105,110122,111364,111519,170756,192198,210933,211323,216225,218397,230775,232286,239250,245446,245450,269608,386750,24248,24329,24338,24387,24392,24464,24482,24498,24615,24835,24842,24929,25026,25112,25124,25125,25163,25240,25264,25265,25404,25408,25425,25445,25491,25496,25550,25589,25617,25621,25647,25712,29290,29386,29527,29543,29597,29665,50557,50577,50658,50689,54250,54251,59086,64157,64803,65054,81649,81651,81686,83425,83476,83497,83785,84114,84353,84357,84394,84577,84578,89804,89805,89807,114122,114851,116554,116590,116996,117273,170568,192248,292994,297893,306464,308435,338474,360457,362317,369119,2828259,155871,156110,908122,4981003,4981004,4981005,4981006,4981007,4981008,4981009,4981010,4981011,4981012,4981013,4981014,4981015,4981016,4981017,4981018,4981019,4981020,4981021,4981022,4981023,4981024,4981025,4981026,4981027,4981028,4981029,4981030,4981031,4981032,4981033,4981034,4981035,4981036,4981037,4981038,4981039,4981040,4981041,4981042,4981043,4981045,4981046,4981047,4981048,4981049,4981050,4981051,4981052,4981053,4981054,4981055,4981056,4981057,4981058,4981059,4981060,4981061,4981062,4981063,4981064,4981065,4981066,4981067,4981068,4981069,4981070,4981071,4981072,4981073,4981074,4981075,4981076,4981077,4981078,4981079,4981080,4981081,4981082,4981083,4981084,4981085,4981086,4981087,4981088,4981089,4981090,4981091,4981092,4981093,4981094,4981095,4981096,4981097,4981098,4981099,4981100,4981101,4981102,4981103,4981104,4981105,4981106,4981107,4981108,4981109,4981110,4981111,4981112,4981113,4981115,4981116,4981117,4981118,4981119,4981120,4981121,4981125,4981126,4981128,4981129,4981130,4981131,4981132,4981133,4981134,4981135,4981136,4981137,4981138,4981139,4981140,4981141,4981142,4981143,4981144,4981145,4981146,4981147,4981148,4981149,4981150,4981151,4981152,4981153,4981154,4981155,4981157,4981158,4981159,4981160,4981161,4981162,4981163,4981164,4981165,4981166,4981167,4981168,4981169,4981170,4981171,4981172,4981173,4981174,4981175,4981176,4981177,4981178,4981179,4981180,4981181,4981182,4981183,4981184,4981185,4981186,4981187,4981188,4981189,4981190,4981191,4981192,4981193,4981194,4981195,4981196,4981197,4981198,4981199,4981200,4981201,4981202,4981203,4981204,4981205,4981206,4981207,4981208,4981209,4981210,4981211,4981212,4981213,4981214,4981215,4981216,4981217,4981218,4981219,4981220,4981221,4981222,4981223,4981224,4981225,4981226,4981227,4981228,4981229,4981230,4981231,4981232,4981233,4981234,4981235,4981236,4981237,4981238,4981239,4981240,4981241,4981242,4981243,4981244,4981245,4981246,4981247,4981248,4981249,4981250,4981251,4981252,4981253,4981254,4981255,4981256,4981257,4981258,4981259,4981260,4981261,4981262,4981263,4981264,4981265,4981266,4981267,4981268,4981269,4981270,4981271,944996,946069
You could write them to a cookie, sort of the equivalent of a tmp file. A much better solution would be to POST your data instead of using a GET.
There's some information about URL lengths here: http://www.boutell.com/newfaq/misc/urllength.html
Basically, storing large data in a URL is not advisable.
You might want to consider putting the values into a HIDDEN input control and then having the link post that data to your server.
Basically, instead of doing this:
Link Here
Try doing this:
<FORM action="http://view.ncbi.nlm.nih.gov/gene/" method="post">
<input type="hidden" id="genes" name="genes">1,2,3,4,5</input>
<input type="submit" value="Submit" />
</FORM>
If you cannot use a cookie, the url is too long. Write the data to a temp table in a database. Once the data is saved out, send back an ID, pass that via the URL. You can do this via a web service call without too much of an issue.
Also, put a timestamp on the table, prune out old data after a set period of time.
Maybe instead of retrieving all the results at once, you could do an AJAX retrieval of the NCBI information for each GeneID when the user clicks on it, adding the results in to the page.

Categories

Resources