0

I am using flask and mysql I want to get values ​​from different tables of my base in some select if someone knows how I can do them please:

@app.route("/tipo_cuenta")
def tipo_cuenta():
    cur = mysql.connection.cursor()
    cur.execute("SELECT * FROM tipo_cuenta")
    rv = cur.fetchall()
    cur.close()

    return render_template("tipo_cuenta.html", periodo=rv)
<form action="{{ url_for('tipo_cuenta') }}"> 
<div class="form-group">
        <label for="" id="label1">SELECCIONE EL TIPO DE CUENTA</label>
      <select class="form-control" id="tipo_cuenta_idtipo_cuenta" name="tipo_cuenta_idtipo_cuenta" method="POST" action="/">
       {% for tipo_cuenta_idtipo_cuenta in periodo%}
          <option value="{{ tipo_cuenta_idtipo_cuenta[1] }}">{{ tipo_cuenta_idtipo_cuenta[1] }}</option>
        {% endfor %}
    </select>
      </div>

I get the desired combo now I want to get data from the same base but from another table in another select but it doesn't work for me what should I do to make it work

@app.route("/tipo_cuenta") 
def tipo_cuenta(): 
cur = mysql.connection.cursor()
  cur.execute("SELECT * FROM tipo_cuenta") 
  rv = cur.fetchall() 
  cur.close() 
 cur2 = mysql.connection.cursor() 
   cur2.execute("SELECT * FROM cursos") 
   rv2 = cur2.fetchall() 
   cur2.close() 
 cur3 = mysql.connection.cursor() 
   cur3.execute("SELECT * FROM jornada") 
   rv3 = cur3.fetchall() 
   cur3.close() 
 return render_template("tipo_cuenta.html",
 periodo=rv,periodo2=rv2,periodo3=rv3)
nbk
  • 45,398
  • 8
  • 30
  • 47
DIEGO
  • 1
  • Please add the new table to your post and explain exactly what should happen. you actual code shows the data of the second column of your tipo_cuenta table in the option as text also as value for the option. – nbk Aug 07 '19 at 22:24
  • aqui ya optengo los demas valores de las tablas en los combobox `@app.route("/tipo_cuenta") def tipo_cuenta(): cur = mysql.connection.cursor() cur.execute("SELECT * FROM tipo_cuenta") rv = cur.fetchall() cur.close() cur2 = mysql.connection.cursor() cur2.execute("SELECT * FROM cursos") rv2 = cur2.fetchall() cur2.close() cur3 = mysql.connection.cursor() cur3.execute("SELECT * FROM jornada") rv3 = cur3.fetchall() cur3.close() return render_template("tipo_cuenta.html", periodo=rv,periodo2=rv2,periodo3=rv3)` – DIEGO Aug 08 '19 at 13:55
  • now the values ​​that I get I want to save them in another table obtaining the values ​​in a form in html as it would be for me to save – DIEGO Aug 08 '19 at 13:57
  • You didn't understand look at my post in https://stackoverflow.com/a/57209229/5193536 you see a create table and an insert into. This is needed to understand your question and help. – nbk Aug 08 '19 at 15:42
  • I am using python with the flask framework I want to get values ​​in combobox from mysql the combobox I use them in several forms as I get the values ​​from my base in any html form – DIEGO Aug 09 '19 at 20:21

0 Answers0