开发者

Having problems reading from a DB

开发者 https://www.devze.com 2023-02-03 05:29 出处:网络
I am programming an assignment and I need to figure out how t开发者_如何学编程o read a database file that Is created using a PHP script I have coded. I am new to the Android platform and have spent ho

I am programming an assignment and I need to figure out how t开发者_如何学编程o read a database file that Is created using a PHP script I have coded. I am new to the Android platform and have spent hours in the past week following tutorials but am still struggling. I need to read from the database and display in a UI on the screen. I’m sure it can’t be too difficult but I’m slipping up somewhere! Any help would be truly appreciated.

Current PHP Script-

<html>
<body>

<?php
//Connect to college database
$studentnum = "SY090627";
$con = mysql_connect("localhost","******","*******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("computin_mobile", $con);
//Select all needed student data
//Must include custext from student table to retrive students college username
$result = mysql_query("SELECT * FROM students, time WHERE (time.CusText5='$studentnum' AND students.StuRef ='$studentnum') ORDER BY time.DayNum ASC, time.StartTime");



$newLine = "\n";

try
{
  //create the database
  $database = new SQLiteDatabase('myDatabase.sqlite', 0666, $error);
}
catch(Exception $e)
{
  die($error);
}

//add Lesson table to database
$query = 'CREATE TABLE Lessons ' .
         '(Day TEXT, StartTime TEXT, EndTime TEXT, Teacher TEXT, Description TEXT, Room TEXT)';

if(!$database->queryExec($query, $error))
{
  die($error);
}
while($row = mysql_fetch_array($result))
  {
//insert data into database
$dayr = $row['Day'];
$query =
  'INSERT INTO Lessons (Day, StartTime, EndTime, Teacher, Description, Room) ' .
  'VALUES ("'.$row['Day'].'", "'.$row['StartTime'].'", "'.$row['EndTime'].'", "'.$row['Teacher'].'", "'.$row['Description'].'", "'.$row['Room'].'")';

if(!$database->queryExec($query, $error))
{
  die($error);
}
  }
//read data from database
$query = "SELECT * FROM Lessons";
if($result = $database->query($query, SQLITE_BOTH, $error))
{
  while($row = $result->fetch())
  {
    print("Day: {$row['Day']} <br />" .
          "Start Time: {$row['StartTime']} <br />".
          "End Time: {$row['EndTime']} <br />".
          "Teacher: {$row['Teacher']} <br />".
          "Description {$row['Description']} <br />".
          "Room: {$row['Room']} <br /><br />");

  }
}
else
{
  die($error);
}
?> 

</body>
</html> 


Step1: Create the mysql to xml using php
For that refer see these url this, this and this.
Step2: Once , you had created the XML file, then parse that xml file using SAX parser, For these Refer see this url

0

精彩评论

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