0

This probably doesn't belong on this forum but I'm not sure where to ask this as I don't know what programming language this should go under. There doesn't seem to be a general forum here. I'm still working on the site that I've been asking questions about. I've got sql databases figured out enough using php code and forms/tables. I would like to customize these forms and tables though to make things simpler and more condensed and again, I'm not expecting you to do all my work for me by supplying me with code, but I would like to know what you would suggest I learn first. If its javascript maybe you could give me a few keywords to look into or suggest websites to learn from.

The php/html forms are pretty basic and I have them working quite good. What I would like to do, though, is edit records in a table view (or multi-record view as some programs would call it). Each record would have text boxes, radio buttons and checkboxes and they would all show up in a table view something like this:

Customer1 Description1 o o o o o o [] [] [] x
Customer2 Description2 o o o o o o [] [] [] x
Customer3 Description3 o o o o o o [] [] [] x
Customer4 Description4 o o o o o o [] [] [] x

(the o's represent radio buttons and the [] represent checkboxes and the x's represent delete buttons).

Now I would like to change the radio buttons and checkboxes right in the table without going to another form. If php code would work (and be simpler since I have learned a bit about it already), the records wouldn't have to update in the database immediately - I could have a submit button which would submit all changes at once if necessary. I imagine whatever code I would use, I would need to use arrays of some kind which I am not very familiar with (although I have worked some with them in other programs).

So, is something like this even possible and if so, what programming language would you suggest I learn to make it possible. I don't want to spend hours or days learning a language that I would later find out I had no use for, nor do I want to spend a lot of time figuring out how to edit in tables if that isn't even possible to do.

5
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by diafol
0

ditto. improve your current programming skills. then you can start venturing into php/oop (object-oriented programming) which is a really great skill to know. It has made my current skills even more powerful

0

If your key requirement at this point is to make dynamic changes to a form to build or modify it right on the screen, then you probably need to use Javascript. You could also do a version of this in PHP but it wouldn't be dynamic. You would have to design it so that the user picks the options they want then send it to the server. This is a pretty specialized requirement so I don't think that you want to use this as your criteria for deciding on a language to learn (unless you plan to specialize in building fancy GUI applications).

PHP is a very good all-purpose web programming language with a large user community and lots of free stuff available. Since it is server-based, you have to use Javascript with it if you want the fancy GUI features. Libraries like JQuery make that pretty easy but they may not have the specific capabilities that you need for your current requirement. Learning a language and becoming competent at it is a pretty significant investment of time. You need to consider what kind of programming your are going to be doing and what the key requirements are for it to make the right language choice.

0

Thanks a lot! That is sort of what I was expecting. I took a look at Javascript in w3schools.com and it looks like it may be easier than I thought. I have worked with oop in other database programs so it shouldn't be too big of a switch.

amie, did you mean phpacademy.org with the video tutuorials?

Also, once I get to know these languages better, will it be possible to work in tables instead of single record forms?

0

> Now I would like to change the radio buttons and checkboxes right in the table without going to another form. If php code would work (and be simpler since I have learned a bit about it already), the records wouldn't have to update in the database immediately - I could have a submit button which would submit all changes at once if necessary.

You seem to be looking at a particular issue as chrishea states. This just needs php, pure and simple - no need for anything else. It that's what you need - post your code for this and we'll give you a hand.

WRT languages, good advice already given.

0

Okay, if you're willing to hold my hand through this, here is the code I am using to view my database:

<html>
<head>
<title></title>

    <script type="text/javascript" language="javascript">

    function redirect()
    {
        // you can also pass the complete URL of location
        // e.g.: http://www.google.com/ or
        // http://programming.top54u.com/Default.aspx
        
        location.replace("viewTableiPad.php");
    }

    </script>

<link rel="stylesheet" href="ip.css" />
</head>
<body>
        
</body>
</html>

<?php
$con = mysql_connect("***","***","***");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("rkaydco1_ip", $con);
$search=$_POST['search']; 
$sort=$_REQUEST['id'];
$unentered="Entered, Status";

if($search<>""){
$srch="%".$search."%"; 
$data = "select * from IP WHERE Customer LIKE '$srch'";
  $query = mysql_query($data) or die("Couldn't execute query. ". mysql_error()); 
  $data2 = mysql_fetch_array($query); 
}else{
if($sort=="Date") {$data = "SELECT * FROM IP WHERE Status<>\"Finished\" ORDER BY ".$sort." DESC";} 
else {
$data = "SELECT * FROM IP WHERE Status<>\"Finished\" ORDER BY ".$sort; }
}
  $result = mysql_query($data) or die("Couldn't execute query. ". mysql_error()); 
echo "<table border='1' rules='rows'>
<tr>
<th><a href=\"viewTable.php?id=".WO."\" target=\"main\">WO</a></th>
<th><a href=\"viewTable.php?id=".Customer."\" target=\"main\">Customer</a></th>
<th><a href=\"viewTable.php?id=".Status."\" target=\"main\">Status</a></th>
<th><a href=\"viewTable.php?id=".$unentered."\" target=\"main\">Entered</a></th>
<th><a href=\"viewTable.php?id=".Description."\" target=\"main\">Description</a></th>
<th><a href=\"viewTable.php?id=".Date."\" target=\"main\">Date</a></th>
</tr>";
$cnt=0;
while($row = mysql_fetch_array($result))
  {
  $d=$row['Date'];
  $cnt=$cnt+1;
  if (is_int($cnt/2))
  {
    $bg="#333333";
  }else
  { $bg="black";}
  echo "<tr bgcolor=\"".$bg."\">";
  echo "<td>" . "<a href=\"form1.php?id=".$row['WO']."\" target\"_new\">".$row['WO'] . "</a></td>";
  echo "<td>" . "   ".$row['Customer'] . "</td>";
  echo "<td>" . "   ".$row['Status'] . "</td>";
  
echo "<td align=\"center\">" . "   ".$row['Entered'] . "</td>";
  echo "<td>" . "   ".$row['Description'] . "</td>";
  echo "<td>" . "   ".substr($d,0,10) . "</td>";
  echo "</tr>";}
echo "</table>";
mysql_close($con);
?>

Now, the line in red is what holds the value of the radio buttons. There are about 23 radio buttons. A dropdown list would also work in this instance and for the sake of room, may be better.

The line in green is a checkbox and I would probably use another checkbox if I got this working. Also I would like to be able to delete one or multiple records. One at a time would be good.

If I would be able to edit records in the table view I wouldn't need the link "<a href=\"form1.php?id=".$row."\" target\"_new\">" in the one cell since that is a link to bring me to an edit form.

So if I would edit multiple records in my table, would I need to submit each record (each line in the table having its own submit button) or would there be just one submit button that would submit all changes at once?

0

Ah, I see, I didn't realise you meant 'interactive'. I thought you have a big form holding data for many users and wanted to update the DB with one SQL statement. Well, I think you do actually.

OK, here's the thing,

You can have form controls for all the records. A delete flag (checkbox) can be set for each row.
A single submit button is possible. Saving each record individually may be wasteful. I'll give you a generic example of a multiple delete:

echo "...

<input type=\"checkbox\" id=\"delete_{$row['id']}\" name=\"delete[]\" value=\"{$row['id']}\" />

...";

This can be used for multiple deletes. You use the $_POST, which will be an array, you can target each one:

if(isset($_POST['delete'])){
  $delete_array = (array)$_POST['delete'];
  $deletelist = implode(",",$delete_array);
  $q = mysql_query("DELETE FROM table1 WHERE id IN ($deletelist)";
}

NOTE this is not tested. If there are mistakes, they're minor ones and a bit of tweaking should get it to work if you plan going down this route. In addition, it would be safer to sanitize any form-passed data, even if you think it's safe.

Edited by diafol: n/a

0

Thanks a lot! That is sort of what I was expecting. I took a look at Javascript in w3schools.com and it looks like it may be easier than I thought. I have worked with oop in other database programs so it shouldn't be too big of a switch.

amie, did you mean phpacademy.org with the video tutuorials?

Also, once I get to know these languages better, will it be possible to work in tables instead of single record forms?

yup..its easier to understand since they use video tutorials..you can view them at youtube also..just search for phpacademy..

0

Ardav, you said I can have form controls for all records and a single submit button. How would a person do this? Place the table commands within <form></form> tags with a submit button before the </form> tag? Also, would all the records be updated or only the ones that have changed? It probably wouldn't matter to me if all were updated since there wouldn't be that many. What SQL command would I use to update the array of records? Would it be similar to the select command I used at first but with the update command instead?

0

>Place the table commands within <form></form> tags with a submit button before the </form> tag? Yes.
If you only want to update the 'dirty' records, you may need a little javascript, just to set a flag for that record id.
You can certainly update unchanged records, but that to most people would seem wasteful - in fact, it goes against the grain to do so, but your choice.

Here's a jquery link on how to capture a radiobutton or checkbox change:

http://www.techiegyan.com/2008/07/09/using-jquery-check-boxes-and-radio-buttons/

Just to give you an idea of how simple it could be. You could have a hidden field which gets updated with items to a list of 'dirty' record id values. You could create this reasonably easily. Well easy-ish.

Edited by diafol: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.