LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 01-14-2006, 04:49 PM   #1
spiffytech
Member
 
Registered: Dec 2005
Location: NC, USA
Distribution: (K)ubuntu
Posts: 139

Rep: Reputation: 15
Scripting entries into mysql with logic


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?
 
Old 01-16-2006, 02:55 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.

Post back if you have any problems.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
quick mysql question - logic with COUNT BrianK Programming 3 09-29-2005 04:29 PM
Bash scripting, mysql, and creating tables. hondaman Linux - General 2 09-25-2005 05:17 AM
Shell scripting: Doing MySQL Dump base on date Swakoo Linux - General 2 09-21-2005 10:23 PM
Scripting in Baxh with MySQL merkelt Linux - Newbie 1 11-18-2003 12:03 PM
Blank entries inserted into mysql database sandoz Programming 4 09-22-2003 03:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration