Jump to content

Convert this file


2old2learn?
 Share

Recommended Posts

Hey;I wish to use a form view of files in a table..so can this file be used to get table info and displayed in the form...here is my " insert " file wishing to convert to "get"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>insert_data.php</title></head><body><?php $con = mysql_connect("localhost","xxxxxxxx","xxxxxxxxx"); if (!$con)   {   die('Could not connect: ' . mysql_error());   } mysql_select_db("xxxxxxxxxx", $con); $sql="INSERT INTO twal ( srnumber, tenant, floor, tower, job_description, employee, labour_cost, material_cost, date_twa_sent_to_tenant, date_twa_approved, date_parts_ordered, supplier, date_job_completed, date_billing_given_to_accounting, employee_comments, managers_comments) VALUES ('$_POST[srnumber]','$_POST[tenant]','$_POST[floor]','$_POST[tower]','$_POST[job_description]','$_POST[employee]','$_POST[labour_cost]','$_POST[material_cost]','$_POST[date_twa_sent_to_tenant]','$_POST[date_twa_approved]','$_POST[date_parts_ordered]','$_POST[supplier]','$_POST[date_job_completed]','$_POST[date_billing_given_to_accounting]','$_POST[employee_comments]','$_POST[managers_comments]')";if (!mysql_query($sql,$con))   {   die('Error: Please check Your data entry ' . mysql_error());   } echo "1 record added"; mysql_close($con); ?> </body></html>

of course " 1 record added " would be changed..to " 1 record found " or something like wise...thanks..If I am right I just switch " insert into " to " get from " am I right also have to change all the " $_POST " to " $_GET " :)

Edited by 2old2learn?
Link to comment
Share on other sites

Look at the SQL tutorial for SELECT. It will explain various options, but you can do this to get all information from all records sorted by your first column:

$sql = 'SELECT * FROM twal ORDER BY srnumber ASC';$records = mysql_query($sql) or exit(mysql_error());while ($row = mysql_fetch_assoc($records)){  echo 'srnumber: ' . $row['srnumber'] . ';tenant: ' . $row['tenant'] . '<br>';}

Using SELECT * gets all fields, but the general rule is that you should only select what you need. Don't select everything if you won't use it:

$sql = 'SELECT srnumber, tenant FROM twal ORDER BY srnumber ASC';$records = mysql_query($sql) or exit(mysql_error());while ($row = mysql_fetch_assoc($records)){  echo 'srnumber: ' . $row['srnumber'] . ';tenant: ' . $row['tenant'] . '<br>';}

Link to comment
Share on other sites

Look at the SQL tutorial for SELECT. It will explain various options, but you can do this to get all information from all records sorted by your first column:
$sql = 'SELECT * FROM twal ORDER BY srnumber ASC';$records = mysql_query($sql) or exit(mysql_error());while ($row = mysql_fetch_assoc($records)){  echo 'srnumber: ' . $row['srnumber'] . ';tenant: ' . $row['tenant'] . '<br>';}

Using SELECT * gets all fields, but the general rule is that you should only select what you need. Don't select everything if you won't use it:

$sql = 'SELECT srnumber, tenant FROM twal ORDER BY srnumber ASC';$records = mysql_query($sql) or exit(mysql_error());while ($row = mysql_fetch_assoc($records)){  echo 'srnumber: ' . $row['srnumber'] . ';tenant: ' . $row['tenant'] . '<br>';}

Thanks..well I will want to display all fields..for managers to review info...for references..so I want to use the same form that I used to insert data...I just renamed the file with the form script..But I would like this also to be one record at a time...not multiply records..thanks..
Link to comment
Share on other sites

If you want to get a specific record you need to use a WHERE clause in the SELECT statement.http://www.w3schools.com/sql/sql_where.asp
I was thinking more in the lines of getting all the fields in any one record called for..and displayed..for management to review it..using the same format of my srequest form..
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...