-2

How do I just display what's in my database in plain HTML or PHP without any GUI interface or layout, just plain database display? Is it possible?

This is my Python code:

import sqlite3
import RPi.GPIO as GPIO
import time
import datetime

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)

dbname='/var/www/ledDB.db'
now = datetime.datetime.now()
timestamp = now.strftime("%Y/%m/%d %H:%M")

pin7 = "INSERT INTO led values('" + "1" + "','" + "Red LED" + "','" + timestamp + "')"

def Blink(numTimes, speed):
    conn = sqlite3.connect(dbname)
    curs = conn.cursor()

    for i in range(numTimes):
        curs.execute(pin7)
        print "Iteration " + str(i + 1)
        GPIO.output(7, True)
        time.sleep(speed)
        GPIO.output(7, False)
        time.sleep(speed)
    print "Done"

    conn.commit()
    conn.close()
    GPIO.cleanup()

print "Blinking LED"

iterations = raw_input("Enter total number of times to blink: ")
speed = raw_input("Enter length of each blink(seconds): ")

Blink(int(iterations), float(speed))

closed as off-topic by lenik, Milliways, Impulss, RPiAwesomeness, Bex Jul 17 '14 at 13:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – lenik, Milliways, Impulss, RPiAwesomeness, Bex
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    You need to get the data out of an sqlite database using Python right? Why are you pasting the database insertion code then? It has nothing to do with your question. – João Pereira Jul 2 '14 at 10:59
  • Just want to show my code and maybe there are some area I should change so that's why I seeking for help from you guys, Hal – user3127380 Jul 2 '14 at 11:53
  • @user3127380 This would fit better on Code Review, a site meant for code review or Stack Overflow, a programming-specific Stack Exchange. This site is specifically meant for Raspberry Pi-related issues (GPIO, PiCam, issues that occur only on the Pi - not on a PC, etc...) – RPiAwesomeness Jul 4 '14 at 14:51
2

Here's a sample script to read an sqlite3 database using Python:

import sqlite3 conn = sqlite3.connect('example.db')

c = conn.cursor()

for row in c.execute('SELECT * FROM led'): print row

Check out the documentation, it's pretty good.

Not the answer you're looking for? Browse other questions tagged or ask your own question.