Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I work for a webhosting company, and we have an online administration tool that we use to manage things. We've recently added radio bubbles to indicate whether or not a website is or is not hosted with us. However, we already have at least 200 websites, and don't want to manually fill in the radio bubbles for each. I have a script that does a dig on the website to see whether or not it's hosted with us, or if we just manage it. The script assigns sites hosted with us a value of 10, and external sites a value of 20.
How do I make the script fill in the radio bubbles in the mysql database by reading the value 10 or 20? What queries would I use, and how would I fit it into my script?
All you need to do, is find out what happens when you click on a radio button.
I assume you're using a kind of web interface (ie access via a browser) to change the contents of the
database.
The web interface will translate your activation of the radio button to a value it can store in the
database itself.
So, a reasonable alternative would be to:
-Open the database on the command line (not via a browser)
-Have a look in the database where the value for "is hosted with us" is stored. It's probably stored as a
boolean (true/false value).
To accomplish this, try:
mysql -Ddatabase_name
=> you'll need to provide username/password.
=> replace "database_name" with the actual name of the database
Once you've entered the mysql client (called "mysql") and opened the database you're using, you can have a
look around by issuing standard SQL commands (like "select" statements).
To know which tables exist, use
mysql> show tables;
("mysql>" just indicates you need to type it in when you've entered the mysql program, in other words at mysql's command prompt).
To see which columns (fields) are stored in a specific table, type in:
mysql> describe table_name;
(replacing "table_name" with the actual name of the table of course).
Most likely, you will have a table that holds one record for each site. Each such record will have it's own value in the field (column) that indicates if the site is hosted by you or not.
For updating existing records (sites already in the database, you simply want to change their "is hosted by you" value), use the "update" command.
For entering new sites (records) into the database, each with it's own "is hosted by you" value, use the "insert" command (you'll need to supply values for each field in the table).
Once you've mastered that, you can do it in a script. The Mysql client offers the possibility of sending SQL
commands to it's standard input directly, for instance:
echo "show table;" | mysql -Ddatabase_name -uUser_name -pPassword
All you need to do then is replace "show table;" with the actual SQL commands (insert or update) and repeat the
above command in a loop (ie in a shell script) for all sites.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.