Best way to use a custom table in a relationship (in ExpressionEngine)? - mysql

So, I’m a bit on how to use a separate table in a relationship, or something like that…
I have a table with around 5000 hotels called exp_h_hotels.
On my website, I use the pages module to create a static subpage for each part of the country. I want to list all hotels that belong to a specific region.
I have understood that I can’t do something like this (using ExpressionEngine tags with the query module):
{exp:query sql="SELECT * FROM exp_h_hotels WHERE h_regionname ='{regionname}'"}
{hotel_name}
{/exp:query}
Anyone knows the best way to go forward with this?
I have looked into using the ExpressionEngine API to insert the data into a channel – however, I get the feeling that it wouldn’t be optimal to flood the channel entries table with 5000 posts with 14-20 fields with data each.

There's no reason why this shouldn't work as you expect, so long as your exp:query tag is inside your channel:entries tag:
{exp:channel:entries channel="pages" limit="1"}
<h1>Hotels in {regionname}</h1>
<ul>
{exp:query sql="SELECT * FROM exp_h_hotels WHERE h_regionname ='{regionname}'"}
<li>{hotel_name}</li>
{/exp:query}
</ul>
{/exp:channel:entries}
However, for the long-term, importing your hotels into a new channel in EE is a much better plan. You could export from your database to CSV (using phpMyAdmin perhaps) and then import into EE using DataGrab. Nothing wrong with adding 5000 new entries to EE.

Related

Wix import new products via CSV file

Good day,
I've tried to import new products to my WIX website via a CSV file that I downloaded, but when I add a new product to this file I need to insert the handleId code, how do I get this code if the new product?
I was just recently wondering this as well and upon having a look at the wix-import-template, I noticed that all handleIDs of the products were simply Product_1, Product_2 and so on and so forth... (all varients of a product have to have the exact same handle as the product they are a part of so:
Product_1,Product,otherAttributes...
Product_2,Product,otherAttributes...
Product_2,Variant,otherAttributes...
etc...
Therefore, if you are using code, you can simply use a for-loop and insert the i-value into the string (if you only have products and no variants, will have to adjust it otherwise)
Wish you a nice day and I hope this helps!
Greetings, Thomas

Is there a way to automatically create categories from a list of items?

I want to add some recipes to a part of my Mediawiki site and have each ingredient create a relevant category.
This is easy to do by hand, but subject to human error - each ingredient has to be entered twice.
for example
* [[category:apples]] apples
* [[category:bananas]] bananas
* [[category:cherries]] cherries
This works, but I feel there should be a way to automate it however I'm not really sure of what the best way forward would be. Is there already an extension to do this (I've searched on all the terms I can think of), should I be writing a script ? Is there some other method to solve this that I should be looking at ?
You could use a template, lets call it Template:Ingredient,
<includeonly>* [[Category:{{{1}}}]] {{{1}}}</includeonly>
Then call it in your page with:
{{Ingredient|apples}}
This will both display the ingredient name and add the page to the category.

Retrieve Assortments (Dutch: "Assortimenten") on Exact Online

For a CSV dump of articles with stock and price information from Exact Online, I need to restrict the list of articles the CSV to articles in an Assortment (Dutch: "Assortiment").
The REST-APIs do not seem to offer this information. It is possible to retrieve Item information, but the assortment is nowhere to be found:
select * from exactonlinerest..items
It seems weird that it is missing from the APIs. Assortments are used often on Exact Online.
An alternative might be to maintain a separate table in addition to Exact Online for assortimenten (assortments).
Or is there a better approach?
You can use the XML API better:
select * from itemcategories
But note that the fields have a totally different naming style, since the XML APIs have typically very long column names. For item code, it would be ITEM_CODE_ATTR.
The GUIDs are only present in some weird text format {GUID}, so remember to remove the { and } first.

Find, isolate, reconstruct en replace string in database

I have a very practical question. I have got about 400 articles in my database and in those articles i have links to other articles. During conversion the links were broke. We inserted new menu-link items manually in our CMS. I want to make a script that looks for an (article)id and replace the menu-item id within the internal link for a new menu-item id.
For example:
this is the old internal link in table twsf_content, column introtext:
index.php?option=com_content&view=article&id=140&Itemid=613“v.d.Hermels Hoeve”</a>
this must be the new link in table twsf_content:
index.php?option=com_content&view=article&id=140&Itemid=397“v.d.Hermels Hoeve”</a>
the only thing that changed is the Itemid (397 in stead of 613).
We can find article&id (in this case 140) in another table (twsf_menu, column link) and determine what Itemid must be: 397 (column Id) in stead of 613.
There can be more links in one article.
In short: we want to find all links in all articles and replace the Itemid for the new Itemid.
Can somebody give me the code to do this?
Thanks in advance!
Extract the stuff to a CSV file, work on that with sed and awk and load it back to the database would be my approach. MySQL isn't good in recursively working with regex and this looks like one-off job.

Pass in user-specified parameters to query a database and return data

I am extremely new to Ruby on Rails, having only a couple days of experience. So far, I have created a new app, and loaded data into the database called name which is comprised of date:string, value:decimal, and unique_id:integer. So now, I can go to "(my local port)/name" and view the table successfully.
What I would like to do is this:
In a new html page, have a SIMILE Timeplot (http://www.simile-widgets.org/timeplot/) with an HTML drop-down list below it in order to select a unique_id and another drop-down box to select a year.
From there, I would like to search through the database and display all of the data on the Timeplot that matches the unique_id and that is in the specified year.
I believe I must make an HTTP GET request for a date_to, date_from, and unique_id, but I do not know how to implement this (admittedly I have been searching the web for ages, but could not figure out the solution).
Any help would be greatly appreciated! Thank you.
Edit: Even just advice on what component to tackle first
First you need to create a route for your search such as this:
match "name/search" to: "name#search" as: "name_search", via: :get
Then if you are using AJAX, and using jQuery you make an HTTP request like this:
$.get("/name/search", {
unique_id: <your_unique_id>,
date_from: <your_date_from>,
date_to: <your_date_to> },
function(result) {
// You do whatever you want with the result here
}
}
P.S:
The Javascript code might not be 100% correct, since I rarely use it.