• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(RESOLVED)Get Data From View to Another View?

Is there any way to pass some data from a view file back to another controller through a href link or some other method to generate another view with only that data?

I have a view file that generates a table of all race finishes for one racing participant by date of all races they participated in, but i also want to be able to allow the user to click on a particular race date link that will take them to another view file that shows an html table of the complete race results for all participants in that race on that date. The html table of complete race results data is already available to the first view file as it is brought in as part of the original query, but how can i get that same data passed on to generate another view if the user clicks on the date link? The data being passed would be a fully coded html table ready to dump directly into another view file.

I hope that makes some sense but have supplied a picture of the first generated table in the view file so you can visually see what i am trying to explain: When a user clicks on the date link in the picture, i want to be able to dump the html table of all participants in that race into a new view file for them to review.

I would recommend passing the racedate ID and then build the HTML on the other side, how are you getting the racedata from a website or a database? if its a database surely it makes sense to create a view that builds up the html for a race day.

If you really wanted to pass the HTML to another controller method, you could POST the html through a form and then display it by echoing the post data. the race date table would have multiple forms with a submit button for each race date. the html would be a hidden field in each form and when submitted will post the relevant html to the controller. not sure on the performance hit on this method.. I will think of some more.

I understand what you are suggesting, but i really have no need to build-up the html table because i literally stored the whole race-result html table in the database as a blob and brought it in along with the data used to create the above pictured table with individual competitor's race result lines.

I've debated about just putting the html tables for each race date below the pictured table, but would really like to have the complete race results on a separate view the user can choose to view or not, rather than forcing all of them on the user on the same page, creating information overload.

I know i could probably do it by creating another function in the controller to call when somebody clicks on the link, but it seems silly to have to query the database again for the same data i already have available but can't figure out any good way to pass it on, so to speak.

Any other suggestions?

so I can think of a solution, how are you generating the race-result html table? could you not store individual blocks of html for each race result?

if you are just building it from data in a database table, I think it might be better to create a view for the individual race data, and then another view for race data list. and then when the user views a page, the table can be built by retrieving the database data and building the html content in the view. this means you could create many views for the same data.

if you got the race results html table from an external source then I might understand your approach,[strike] but if not then surely you would have to build the html from a database data anyway. it seems silly to have to pass around blocks of html. It seems like your precompiling the data and then passing it around, why not just compile it at the other end and pass ids around?[/strike] (I talk some rubbish sometimes)

Quote:if you got the race results html table from an external source then I might understand your approach

You hit the nail on the head, and that's why i'm doing things this way.

Thanks for your thoughts and suggestions anyway.

sorry I was probably being a little patronising, without intending to be.

four approaches I can think of if they help:

1) use some form of regular expression when getting the web content to extract the individual data and then save it in a database, then you can apply your own template to the data (i used this approach ages ago when extracting data from weather buoys from a html source, it meant I could send out text messages and display html. I had a background process that would parse out the data every half hour and insert it into the database), if the website html changes then you only need change the code to parse it out in one place.

2) pattern match out each block of html, and assign it to an race id in the database.. when you click on the race link the id is passed and then you can extract out the html block.

3) when the user clicks on the race link, an id is passed. the whole block of html is retrieved from the database and the individual race data is extracted out using a regular expression. Probably the least efficient, but I don't reckon it would take too long to parse the data.

4) passing blocks of HTML. I think in your case passing blocks of html around is wrong.. If using a href you will have to pass it through the url.... you could do this by base64 encoding the html, but I am unsure of the limit of characters you can send. you could post blocks of html through multiple forms and POST the data, but I think that is the most long-winded way to do it.

hope this helps

Gtech, thanks for your help. I opted to use your suggestion of passing the event_id in a url segment to a new controller and querying the database again using the id.

For anybody stumbling across this thread i used:
<a href="'. site_url('scoring/single_raceresults/'.$results[$i]['event_id']) .'">'
to create the date link on the html page to call the new controller, single_raceresults, and put the event_id in the url, then used:
$race_event_id = $this->uri->segment(3, 0);
in the controller to get the id for use in querying the database.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.