Solved

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

Posted on 2014-01-27
5
493 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
ID: 39812504
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 43

Expert Comment

by:Chris Stanyon
ID: 39812564
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 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 250 total points
ID: 39812569
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 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39812639
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
ID: 39812824
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 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