Which is best - PHP + Mysql query OR Javascript + JSON - to replace wrote numbers by names?

Go To StackoverFlow.com

0

I'm getting grouped ids numbers with GROUP_CONCAT in MYSQL, so I get something like :

row 1: 3,4,11,2
row 2: 5,11
row 3: 5,11

So if I want to replace that ids to their names, which is the best way?

PHP + MySQL

Explode string (3,4,11,2) > Do individual consults in MySQL calling the name of each given id

OR

Jscript + JSON

Explode string (3,4,11,2) > rewrite to something that I could find with javascript like: <span class="replaceThis">3</span> <span class="replaceThis">4</span> <span class="replaceThis">11</span> <span class="replaceThis">12</span>

Create a JSON file (using PHP+Mysql) with all my id and tags like:

data: {id: 1, name:'dog'},{id: 2, name:'cat'},{id: 3, name:'dog'}

And made javascript find all <span class="replaceThis"> into the page and for each one replace the innerHTML by name.

Well, PHP + MySql is my first solution, but I don't think it would have a good performance making a lot of individual queries in MYSQL. I think Javascript + Json would be better but it looks more complex to me. I don't really know how I could do this.

It is just for show on page, it wont be used as variable.

2012-04-04 19:13
by Leo


0

I'm getting grouped ids numbers with GROUP_CONCAT in MYSQL [..]

Then just join with the table that has the names and GROUP_CONCAT those names instead of the ids (or do both GROUP_CONCAT if you want). Then just use the result in PHP.

2012-04-04 19:16
by Mosty Mostacho
You are right! But if I needed to use this replace function on other cases and I really needed to build a function for this, which solutions is the best - Leo 2012-04-04 19:33
Ads