toibs Posted February 25, 2009 Share Posted February 25, 2009 Hi Guys, New to the board, so Hi to all. Also new to php/mysql programming, so please bear with the newbie!! I have a query: $result = mysql_query( "SELECT owner_id, serial_number, date_of_manufacture, notes, location, country FROM ($table) ORDER BY serial_number ASC" ) that outputs a string from an sql database as follows: user ID Serial number 500 25250-157742 Blahh blahh blahh Sydney AU 354 50120-083831 Blahh blahh blahh Minnesota US 466 50120-084131 Blahh blahh blahh Victoria AU 530 50120-085891 Blahh blahh blahh Cali US I also have another database with a bunch of usernames and data. The username/data corresponds to the first field (the numeric) as above. User table ID Name Email 500 Joe bloggs joe@bloggs.com 354 Bill Bailey bill@bailey.com 466 Dave Pike dave@pike.com 530 Hugh Jarrs hugh@jarrs.com I want to be able to pull the username itself from a field in a second table, and replace the number in the output with the username contained in the corresponding cell. So the end output would be something like: Joe bloggs 25250-157742 Blahh blahh blahh Sydney AU Bill Bailey 50120-083831 Blahh2 blahh2 blahh2 Minnesota US Dave pike 50120-084131 Blahh3 blahh3 blahh3 Victoria AU Hugh Jarrs 50120-085891 Blahh 4 blahh 4 blahh4CA US This is for the output only - i dont want to overwrite the info in the cells itself. Has anyone any advice on how to do this?? Also - since i'm new to this, is there anywhere/anything i can get that will allow me to easilly find out that variables/commands are available that will do what i'm after??? half the problem is that i know what i want to do, however i dont know what it's likely to be called, or how to locate one!! Thanks again Paul Quote Link to comment https://forums.phpfreaks.com/topic/146791-replacing-contents-of-display-with-contents-of-another-cell/ Share on other sites More sharing options...
corbin Posted February 25, 2009 Share Posted February 25, 2009 "Also - since i'm new to this, is there anywhere/anything i can get that will allow me to easilly find out that variables/commands are available that will do what i'm after??? half the problem is that i know what i want to do, however i dont know what it's likely to be called, or how to locate one!!" Read as much as you can. Also, sometimes googling random things will eventually lead you to something useful. Anyway, look into JOIN. It would go something like: SELECT table1.*, table2.user_name FROM table1 JOIN table2 ON table2.user_id = table1.user_id; Except you would want to change column/table names of course. Quote Link to comment https://forums.phpfreaks.com/topic/146791-replacing-contents-of-display-with-contents-of-another-cell/#findComment-770714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.