Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8091929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:10:36+00:00 2026-06-05T20:10:36+00:00

I have a php form which saves these values to the database: id rand

  • 0

I have a php form which saves these values to the database:

  • id
  • rand (a randomly generated string)
  • x_val
  • y_val

I am calling these values back from database in a python program using mysqldb:

import MySQLdb

db = MySQLdb.connect("localhost","root","","test" )

cursor = db.cursor()

sql = "SELECT id,rand,x_val,y_val  FROM  table"
 try:
cursor.execute(sql)
results = cursor.fetchall()
results =  {}
for row in results:
  results[row[1]] = [row[0], row[2], row[3]]
  rand = row[1]
  x_val = row[2]
  y_val = row[3]

except:
 print "Error: unable to fecth data"

db.close()

UPDATE: It gives the Error -> Error: unable to fecth data

In this piece (as you can see) i want rand (i.e. row[1]) to serve as the identifier for the row. However, I am not able to find a way about how to use this as an identifier since rand = row[1] is called after the sql variable. In this example, I have used a static ’63kfjf’ rand value, which is just to show you the working. Is there a way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:10:38+00:00Added an answer on June 5, 2026 at 8:10 pm

    After selecting your datas from DB, you can create a dictionnary with “rand” value as key:

    Something like this:

    dicResults =  {}
    for row in results:
        dicResults[row[1]] = [row[0], row[2], row[3]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a PHP form which requires the user to select a postcode
I have a php file that contains a form (which contains 2 input boxes
Language: PHP I have a form which asks users for their educational details, course
I have a form on which I POST the data with PHP. When the
In a php-script i have a form, method is post, action-attribute is empty, which
I have a post html form, and the action is index.php, which is the
I have an html/php form that updates entries on the database server. I need
i have a form which inserts book information into the database. however it is
I have created a custom PHP script which uploads information submitted by a form
I have a php form that has a known number of columns (ex. top

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.