Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

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

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
armasmike
Asked:
armasmike
2 Solutions
 
Computer GuyCommented:
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
 
Chris StanyonCommented:
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
 
Chris StanyonCommented:
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
 
Ray PaseurCommented:
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
 
armasmikeAuthor Commented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now