开发者

Creating link to database

I am currently making a project on Universal Identification Number(not such a big one, but like that kind of....upto college level)..I want to create a page with tabs to the respective databases.... like If I press key 'A' for a tab then all the names starting with letter 'A' should appear... Plz help me !!!!

Regar开发者_Python百科ds !!


Not entirely understanding your question, but if I was to create a tab for different names, and/or situations, I'd use a switch statement with cases that allows you to change the order_by in your sql query.


I think this is kinda what you want to display all names starting with an A passed on with a get request:

<?php
//connect to mysql database (if you don't know search google)
if(isset($_GET['namestartingwith'])){
  $namebegin = $_GET['namestartingwith'];
  $query = mysql_query("SELECT * FROM database WHERE name LIKE \"$namebegin%\"");
  while(mysql_fetch_array($query) = $data){
   echo $data['name'];//name being the name op your column with the name data
  }
}
?>

This should do the trick for php+mysql


In Java+MySQL, after downloading and instating the requisite jars:

public static Connection dbConnect() throws SQLException, ClassNotFoundException {
   String DB_URL;
   Class.forName("com.mysql.jdbc.Driver");
   DB_URL = "jdbc:mysql://your_db_url?autoReconnect=true"; 
   Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PWD);
   return conn;
   }

In the calling program,

public static Object dbExecute() throws SQLException, ClassNotFoundException {
    Statement stmt;
    Connection conn = dbConnect();
    stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("your_sql_statement");
    Object result = null;
    while (rs.next()) {
        result = rs.getObject("field_you_want_to_retrieve");
    }
    rs.close();
    stmt.close();
    conn.close();
    return result;
}


I think you need to take this from the start. Are you using PHP or Java? Are you using MySQL or Oracle for your database? Maybe set yourself a simpler goal, build a PHP page (or Java servlet) that fetches data from your database and displays it in a table in the web browser. When you get this working, you can build on it.

When you get to a question that you can't answer, then submit that question to Stackoverflow. Explain what you have working, what you are trying to do and where the expected result deviates from the actual result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜