Solved

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

Posted on 2014-01-27
5
511 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The viewer will learn how to dynamically set the form action using jQuery.
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 …

691 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