ajax alert message! returns a field value in ID

hi guys, i am trying get alert message onAfterUpdate and it is working but the field is a foreign key from another table,

1- so say message says: Room {roomno} was udpated. and that is fine, but i have some rooms with BA BC in the other table, so here I’m getting only the id of the roomno, so how to make the message display the primary value of the field instead of the foreign key?

2- if i have multiple records form, and user updates 3 or 4 rooms then he will get 3 repeated messages like Room X was updated, Room Y was updated. Room Z was updated… .all after each other… how i can make one alert message displays something like this:

Rooms x,y and Z were updated. should i use the onAfterUpdateAll??

1- Use sc_lookup.

$myquery = "SELECT roomno, roomName FROM Rooms WHERE roomno = " . {roomno};
	
sc_lookup(rs, $myquery);

if (isset({rs[0][0]}))     // If there are records on array, something was returned from the query
{
    sc_alert({rs[0][0]}." ".{rs[0][1]})); //message concatenating first and second column 
}
else     // record not found
{
	sc_alert("It's a trap!!!!");
}

All this for a message to convert foreign to primary!!! ok will try that indeed :slight_smile:
remains if i can display all rooms numbers that updated in the same message would be great

appreciated Giu, thanks a lot

Well, this is to obtain the value of a field based on a key. Think about it, you have to lookup the foreign table to obtain the value you need.

If you want it more short you can always do:


$myquery = "SELECT roomno, roomName FROM Rooms WHERE roomno = " . {roomno};    
sc_lookup(rs, $myquery);
sc_alert({rs[0][1]}));

If you will need this code in more apps, create a library with a function, and you just have to do something like:
[PSEUDOCODE]
$field = myFunctionReturninRoomName([roomnumber])

that is what wanted Giu for single room message alert
i’m learning every day something new here guys, perhaps someone later can explain how to show the alert to obtain all rooms that updated in multiple records view in one message :smiley: but it is not urgent anyway

thanks a lot dude :slight_smile:

Mike

Without thinking too much. Maybe there are better solutions.

OnApplicationInit:

[message] = "Rooms updated: ";

OnAfterUpdate

[message] = [message] . "{descripcion} with ID {Id}, ";

OnAfterUpdateAll

sc_alert([message]);

Remember to set [message] global as OUT on Application->Variable

In my situation “name” is in the same table. May you need to extract if want to show roomname in final message.

OnAfterUpdate


$myquery = "SELECT roomno, roomName FROM Rooms WHERE roomno = " . {roomno};    
sc_lookup(rs, $myquery);
[message] = [message] . "{rs[0][1]} with ID {roomno}, ";

Captura.JPG

Captura2.JPG

May I jump in?

onLoad: [rooms_updated] = array(); // set [rooms_updated] to OUT

onAfterUpdate: [rooms_updated][] = {roomno};

onAfterUpdateAll:

$query = “SELECT GROUP_CONCAT(roomname SEPARATOR ', ') FROM rooms WHERE roomno IN (”. implode(’,’,[rooms_updated]).")"; // SEPARATOR = comma + blank (it looks nicer)
sc_lookup(upd,$query);
if(count($upd) > 0)
{
$message = 'The following rooms have been updated: '.{upd[0][0]};
sc_alert($message);
}

jsb

[QUOTE=jsbinca;24384]May I jump in?

onLoad: [rooms_updated] = array(); // set [rooms_updated] to OUT

onAfterUpdate: [rooms_updated][] = {roomno};

onAfterUpdateAll:

$query = “SELECT GROUP_CONCAT(roomname SEPARATOR ', ') FROM rooms WHERE roomno IN (”. implode(’,’,[rooms_updated]).")"; // SEPARATOR = comma + blank (it looks nicer)
sc_lookup(upd,$query);
if(count($upd) > 0)
{
$message = 'The following rooms have been updated: '.{upd[0][0]};
sc_alert($message);
}

jsb[/QUOTE]

Very elegant

you are my heros guys, i wasn’t wrong when named each one that i learn from him, jsb, aducom, giu, scott, and some other big names here :slight_smile: you are really making life easier :slight_smile:

now that works jsb explained (thankfully) worked perfectly i can see the message displaying all updated rooms in one message nicely sorted

i will just apply them to other application after finishing from the 0 values issue :frowning:

cheers

Okay guys, this works perfect as stated before, just a little worry if i want to display the other coumn instead of the roomno wanna display the roomdesc in the message, which part should be changed? i tried to change the roomno to roomdesc but didn’t work, also changed the [0][0] to [0][1] with no luck

i have the roomno now in the table as foreign key and i want to display in the alert the associated roomdesc…

the blue arrow instead of the red one… according to jsb neat code above

Untitled.jpg

[QUOTE=itsme3;24531]Okay guys, this works perfect as stated before, just a little worry if i want to display the other coumn instead of the roomno wanna display the roomdesc in the message, which part should be changed? i tried to change the roomno to roomdesc but didn’t work, also changed the [0][0] to [0][1] with no luck

i have the roomno now in the table as foreign key and i want to display in the alert the associated roomdesc…

the blue arrow instead of the red one… according to jsb neat code above

[/QUOTE]

This cant work because query just returns 1 column.
Based on the query of jsbinca, If you want to show roomdesc instead roomname
This change should work using [0][0]

SELECT GROUP_CONCAT(roomname SEPARATOR ', ')
SELECT GROUP_CONCAT(roomdesc SEPARATOR ', ')

i tried, it didn’t, is it because the roomno is not the primary in the small table? i have there “id” which is the primary!

it is just giving blank value:: i tried all possible ways, maybe there is something wrong :frowning:

it just says: "Rooms updated: "

never mind my last reply guys, i just return it back to roomno and id, got rid of that newly roomdesc field, so now it is working as jsb posted

although, i wounder why wasn’t working, 90% because the roomno should be the PK

cheerz

Don’t have sense, you can show whatever field you want, an whatever WHERe clause you want, Pk has nothing to do here. Cab you post your code?

hi Giu,

yes it was exactly as jsb did explain thankfully

onLoad: [rooms_updated] = array(); // set [rooms_updated] to OUT

onAfterUpdate: [rooms_updated][] = {roomno};

onAfterUpdateAll:

$query = "SELECT GROUP_CONCAT(roomname SEPARATOR ', ') FROM rooms WHERE roomno IN (". implode(',',[rooms_updated]).")"; // SEPARATOR = comma + blank (it looks nicer)
sc_lookup(upd,$query);
if(count($upd) > 0)
{
$message = 'The following rooms have been updated: '.{upd[0][0]};
sc_alert($message);
}

then when i added that column, i just changed the roomname to roomdesc but was returnning blank value…

never mind Giu, its not important now, as i said, i returned the small table as it was, so it is working this way now as stated above,

i was just curious why wasnt work, because as you said, doesn’t make sense…

thanks for your care

And changing

$query = “SELECT GROUP_CONCAT(roomname SEPARATOR ', ') FROM rooms WHERE roomno IN (”. implode(’,’,[rooms_updated]).")"; // SEPARATOR = comma + blank (it looks nicer)

for

$query = “SELECT GROUP_CONCAT(roomdesc SEPARATOR ', ') FROM rooms WHERE roomno IN (”. implode(’,’,[rooms_updated]).")"; // SEPARATOR = comma + blank (it looks nicer)

Don’t do the job?

no it didn’t, thats why maybe should be selected or PK was the issue. Now is ok as i returned it back as it was :slight_smile:

No. Query Autopsia:

SELECT GROUP_CONCAT(roomdesc SEPARATOR ', ') 

Return a row with all roomdesc field and concatenate using ", " as separator

FROM rooms 

…from rooms table


WHERE roomno IN (". implode(',',[rooms_updated]).")";

…where field roomnumber value is on array you filled previously.

Primary Key is to define to a table how a record should be unique. It has nothing to do with using fields on a query (well, PK means too to have an INDEX over this field, but this just means more faster query over this field).

Maybe my brain is not wake up yet, but as far as I see, tha change I suggest should work.

You right, we both didn’t wake up yet, world cup syndromes loool, you aright, it seemed to be working, all was fine, maybe i missed some detail that time, anyway as i changed the table and things are fine, i moved on to new challenge now :slight_smile:

hi Giu,

this is still working fine as implode array from roomn0 when are integers, but what if i have the roomno as text “varchar” I get nothing out of the array!?

perhaps is like integer and should be a string!? how i can do this to work while field roomno

WHERE roomno IN (". implode(’,’,[rooms_updated]).")";