Question:
SQL Statements? How do i use them?
Chase K. Utley
2009-08-11 13:42:41 UTC
ok here is my problem. Iv learned SQL Statements from a online teaching thing but... i don't how to use them. And what i mean by that is how do i get them showing up on my HTML pages? What are the steps i have to take "in detail". Iv been told that i have to make a php calling code on my html page that refers to the SQL code which is stored in ASP.net or MySQL.com or something like. As you can see i don't know much about it but im trying to make it where i can have a giant database of prices for moped parts and get it to where i can have these prices be able to be updated from a SQL data base. So what i need to know is how to get my data on the html page and how to link all of this crap together.

Any.... information on this subject wold be nice. Thanks.
Four answers:
Jeff
2009-08-11 14:04:22 UTC
If you are using mysql there are 2 ways to run sql statemetns.



1- open cmd and type mysql. Enter username and password and then you can enter sql statements.



2- to run them on you server and output HTML you will need use use a language like PHP. Example




$con = mysql_connect("localhost","username","password");

if(!$con) {

echo "ERROR";

return;

}

mysql_select_db("databasename");

$sql = "SELECT * FROM table name";

$result = mysql_query($sql,$con);

if(!$result ) {

echo "ERROR";

return;

}



while($row = mysql_fetch_array($result))

echo $row['name']."
";



mysql_close($con);

?>



See you use mysql_query to run SQL statements. You need to first connect to the mysql and then select dabase.



Hope That Helps.

Jeff

Liquid Communication Tech
TheMadProfessor
2009-08-13 13:47:29 UTC
To expand on Jeff's reply a bit (as it may be somewhat confusing to a newbie):



A web page usually communicates with a database by using a scripting langauge (PHP in Jeff's example) to generate requests to the server the database resides on, then receives replies which it can process to format the page back to the user.



The first thing it must do is establish a connection to the database (the mysql_connect part of Jeff's example.) Then, after specifying the database to be accessed (mysql_select_db), it requests a query be executed and the resultset be attached to a recordset (mysql_query). Next, it processes the resultset one row at a time (mysql_fetch_array) in whatever manner is desired (in this case, simply echoes it out to display on the web page, but typically some additional formatting or decision processing would be done.) When all the rows are processed, the connection to the server is closed (mysql_close).
US_Programmer
2009-08-11 20:53:26 UTC
You are confused.



SQL is used to "talk to" databases (like SQL Server, Oracle, mySQL, and [yes, I know] Microsoft Access.



Now, if you want to query a database to place dynamic content on your web site, then you need an additional programming language to create the connection to the database you're using and pass your SQL statement to send a "query" and retrieve a "recordset" from which you can parse and display the results on your web page.



Such languages would include PHP, C#, VBScript, etc. These would be used in such web application programming interfaces as ASP, PHP, Coldfusion, ASP.Net, etc
mark e
2009-08-11 20:47:14 UTC
do you have mySql database?

do you have an apache server?

can you write PHP?



write php to connect to the database, use your query, write php to display the results.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...