FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


a site where i can learn mysql syntax





Philip
is there some one here that know a site where i can learn mysql syntax ???
i frustated since i want to update a table like this

table a
nim name
1 Rud
2 Dem
3 Kil

table b
nim real-name
1 contain form tablea.name
2
3
Esch
Here's a tutorial that might help you: http://www.freewebmasterhelp.com/tutorials/phpmysql

If that's too long, here's a brief crash course on most of the things you'll want to do with tables (this is all with PHP, by the way, and I'm assuming you have an existing connecton to your database):

CREATING TABLES:
Code:
$result = mysql_query("create table mytable (id bigint not null default '0' auto_increment, somecolumn varchar(100) not null default 'Somevalue', index(id), primary key(id))");


That will create a table named mytable with two columns: 'id', your primary key (used for doing row-specific operations later on), and 'somecolumn', a text column that can store 100 characters per record. You can check if $result === TRUE to see if the query was successful (i.e. that your table was created). (Note: the triple-equals sign checks truth or falsehood exclusively, by the way; it's more predictable than ==.)

INSERTING DATA:
Code:
$result = mysql_query("INSERT INTO mytable (somecolumn) values ('Hello there')");


This inserts data into our existing table; each column you specify in the first set of parentheses has a corresponding value in the second set of parentheses (ex: "insert into sometable (first, second, third) values ('1', '2', '3')" would insert '1' into the column named first, '2' into second, etc.). Once again, you can check the $result to see if your query succeeded; if it failed, you can print out mysql_error() to find out exactly why it failed.

RETRIEVING DATA:
Code:
$result = mysql_query("SELECT * FROM mytable WHERE id=2");

while($row = mysql_fetch_array($result))
{
  print $row["somecolumn"]."<br>\n";
}


This will get the record with id=2, if it exists, and display the value of column 'somecolumn'; the while loop is unnecessary here, since we're only getting one record, but it illustrates how you deal with queries that return multiple records. Once again, $result will be FALSE if the query failed.

UPDATING DATA:
Code:
$result = mysql_query("UPDATE mytable SET somecolumn='New value' WHERE id=2");


This sets record with id=2's value for somecolumn to 'New value'; once again, you can check $result to see if this worked. You can omit the "WHERE id=2" to change every record in your table, or change it to check on some other criteria -- if the query matches multiple records, multiple records will be changed.

DELETING DATA:
Code:
$result = mysql_query("DELETE FROM mytable WHERE id=2");


Deletes the record from mytable with id=2; if you leave off the "WHERE id=2", every record will be deleted from your table.

DELETING A TABLE:
Code:
$result = mysql_query("DROP TABLE mytable");


Drops a table, which means that the table and all its data is deleted.

---

That concludes my crash course on SQL with PHP; hopefully you found it helpful. Of course, there's a lot more to SQL than that; I recommend finding a nice, long tutorial to go over the stickier points.
Philip
no no, i meant with out using php, but purely sql syntax. Embarassed
anyway thanks for that reply too, since it seem there;s no one care about this topic that i made Smile
mariohs
i learned through this...
SQLCourse - Interactive Online SQL Training for Beginners
and
SQLCourse2 - Advanced Online SQL Training

both are very good and they are interactive, you learn a lot...
Esch
Ah, sorry that I misinterpreted your question.

In any case, the SQL syntax for each of my examples is the first argument to each call to mysql_query(). For example, for my "insert" example, the PHP code is $result = mysql_query("INSERT INTO mytable (somecolumn) values ('Hello there')"); -- the corresponding SQL code (that you could enter into the mysql prompt, for instance) is simply "INSERT INTO mytable (somecolumn) values ('Hello there')". The mysql_query() command is just a thin wrapper for executing SQL statements, essentially.

I hope that's some help.
muggle
You can write your own SQL execute form in PHP. Implementation is relatively simple; the solution can be embedded into all your projects and can serve as query development/debugging/testing tool as long as a simple database management utility.
Philip
mariohs wrote:
i learned through this...
SQLCourse - Interactive Online SQL Training for Beginners
and
SQLCourse2 - Advanced Online SQL Training

both are very good and they are interactive, you learn a lot...

thanks for that link Smile

@muggle:
sorry but i completly dont understand what were u writing ... --"
if i write php, how can i embeded the php into my project ?
Related topics
Languages
Site that you have to pay but Beleive me its worth it..
How To : Improve Your PHP Programming
SQL Basics
Need some php/mysql dlls
Need ideas for my site
Noob attempting to learn MYSQL
mysql syntax error I can't find why
mysql syntax problem
Where is best place to learn a new language for free?
i want to learn php how should i start
PHP as site template?
where to learn english
Newbie PHP/MySQL question
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.