Solved

php and mysql help what the best why to do this.....

Posted on 2014-01-27
5
487 Views
Last Modified: 2014-01-27
Hello i have this code

<?php



$host = "localhost";
$user = "123";
$pass = "123";


$r = mysql_connect($host, $user, $pass);

if (!$r) {
    echo "Could not connect to server\n";
    trigger_error(mysql_error(), E_USER_ERROR);
} else {
    echo "Connection established <br>";
}

@mysql_select_db("patient_regester") or die( "Unable to select database");
$query="Select * FROM kfhh Order by Room_id";
$result=mysql_query($query);
$num=mysql_numrows($result);





echo mysql_get_server_info() . "<br>";





?>

<br><table width='50%' border='1'>

  <tr align='center'>
    <td>Room Number</td>
    <td>Occupancy Status</td>
    <td>Last Name</td>
    <td>First Name</td>
    <td>LOC</td>
    <td>Visitors</td>
  </tr>

<?php

$i=0;
$n=1;





while ($i < $num) {


$name_Occupancy="Occupancy".$n;


$Room=mysql_result($result,$i,"Room_id");
$Occupancy=mysql_result($result,$i,"Occupancy");
$Last_name=mysql_result($result,$i,"Last_name");
$First_Name=mysql_result($result,$i,"First_Name");
$LOC=mysql_result($result,$i,"LOC");
$Visitors=mysql_result($result,$i,"Visitors");





?>
 <form >


  <tr>
    <td><?php echo $Room ?></td>


<td> <?php echo $Occupancy ?> </td>

    <td> <?php echo $Last_name ?> </td>
    <td> <?php echo $First_Name ?></td>
    <td> <?php echo $LOC ?></td>
    <td> <?php echo $Visitors ?></td>
  </tr>

<?php


$i++;
$n++;

}
mysql_close();

?>

</table>

Open in new window


What displays is this



Would it be easier to have a "edit" button next to each Room number. When the user clicks the edit it will let them edit just that row.

Or have the Occupancy Status, LOC, and Visitors and drop down box and the last and first name boxes be input fields.

Then have one button for save.

This info will be changed a lot thought the day so i want to make it very easy to use.
0
Comment
Question by:armasmike
5 Comments
 
LVL 3

Expert Comment

by:Computer Guy
Comment Utility
There are a couple of questions to ask, will the same person who is using this software be the one editing it?

You have two ways to make this happen.

YOUR WAY: Have the Occupancy Status, LOC, and Visitors and drop down box and the last and first name boxes be input fields.

MY WAY: I would create 2 pages: Edit and View

I know you mention the dropdown box, personally I would use a checkbox, that way with a simple click, you can make the change, though you can still get away with the dropdowns.

On the view page, have a link or button for updating

On the edit page, have a link or button for saving, and recirecting to the view page.
0
 
LVL 42

Expert Comment

by:Chris Stanyon
Comment Utility
Modern approach would be to have an edit link / button for each row, and on click opens up the record in a popup dialog box (or even in-line - replacing the text with form inputs / drop downs). When clicking on save, either in the dialog popup or inline, you simply use AJAX to post the info back to the database - everything stays in one page and is more intuitive and responsive.

The idea of posting back and forward between pages is old-school, and having all the options in form fields right away just looks ugly :)
0
 
LVL 42

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 250 total points
Comment Utility
Having said all that, your code will need a major overhaul - you need to get away from using the mysql library ASAP - it's deprecated so you'll need to switch to mysqi or PDO
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
Comment Utility
This article shows a general design pattern for PHP / MySQL table maintenance scripts.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12335-PHP-and-MySQLi-Table-Maintenance.html

This article will help you make the required move away from the MySQL extension.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

And this article will help you avoid some of the less-well-done programming practices.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12293-AntiPHPatterns-and-AntiPHPractices.html
0
 

Author Closing Comment

by:armasmike
Comment Utility
Thank you both Chris Stanyon i like your way of doing it on all one page and Ray Paseur thank you for the links to mysqli
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now