Add, Edit, Delete & Sorting Table Version 2 - TIAMOT

Posted 3 months ago at 8:19 pm. 69 comments

Yes that’s right. It’s finally here version 2 of the script that seems to have gotten exceptionally popular.

Well actually it’s version 2.1 as I noticed an error just a few minutes ago but nevermind. ;) I have improved a lot of stuff in the code. It is now neater than ever and exceptionally easy to use all you need to do is configure a few things and you’re off.

I hope you like it. There are instructions in the zip file and you can read this read me underneath the download at the bottom of this post.

I’d also like to say a huge thanks to everyone who commented on the last version. You all helped me a lot by making me think of new features and easier ways to implement different parts of the script.

I am still providing support for the old version of the script so don’t worry, but I highly recommend you download this version if you were having problems running or using the older version. Again though any problems just leave a comment and I’ll get back to you as soon as I can.

Oh and I have had a few questions about donations so, here we go. I provide all help and scripts for free, however it takes a lot of my time & server costs so any donations would be welcome of any amount although they are not required.

Oh and the poll I had up before asking about the donation cloud. For those who said ‘what’s that?’ a donation cloud is a cloud of links, like a tag cloud that will automatically link to your site after you donate. The more you donate the bigger the link you get. Please vote on my new poll though, I think it would be interesting to see which OS you use the most. ;)

By the way the name does actually stand for something and as it says in the readme is a play on the mythical dragon Tiamat’s name. It stands for: The Integrated AJAX and MYSQL Ordering Table.

The demo is back up and can be accessed as before through the coding examples link at the top of the page or here

You can view the video tutorial for… Sorry the video tutorial is not available at the moment.

Click here to read TIAMOT’s Readme file.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • StumbleUpon
  • Google
  • Furl
  • del.icio.us
  • Facebook

69 Replies

  1. hi, where can i found the file to download?

  2. Just above ^^ where it has a little picture with TIAMOT - Add, Edit, Remove and Sort Version 2 (30.6 KB, 0 hits) written next to it.

  3. Andre Been Gravatar May 28th 2008

    Thank you for your hard work.
    I seem to have stumbled in to a slite problem. After editing the changes in tiamot.php and activating it on a server all i get is an empty page.

    Please advise

  4. There are instructions on how to use TIAMOT in a readme text file in the zip, just in case you missed it.

    You will need to make a new php file then attach it to the file like so:

    <?php include('path/to/tiamot.php'); ?>

    above everything in the page, even the doctype.

    Then you can use the four functions anywhere in the page to get the table, the tamot_header() function must be called in the head or it won’t work.

    You page should basically look something like this:

    <?php include('path/to/tiamot.php'); ?>
    <html doctype etc etc>
    <head>
    <title>Page Title</title>
    <?php tiamot_header(); ?>
    </head>
    <body>
    <?php tiamot_status(); ?> <!--- outputs the status field --->
    <?php tiamot_table(); ?> <!--- outputs the table --->
    <?php tiamot_insert(); ?> <!--- outputs the input fields -->
    </body>
    </html>

    There should be a video tutorial up but I’ve been having problems with my host allowing me to upload it for some reason. I’m going to try again tonight.

    Oh and if that doesn’t help just give me another quick shout. ;)

  5. Andre Been Gravatar May 28th 2008

    Hello Veneficus Unus

    thanx for the very fast reply.
    It’s working a little bit now.

    I have the table and the rows onscreen.

    i have the add values boxes
    iclusif a del

    but nothing else goes.
    No editing or deleting or inserting

    greetings from the netherlands

    Andre

  6. Hmm,

    Please check these few things:

    1. You extracted all the files from the zip into the same folder.
    2. You have included < ?php tiamot_header(); ?> in between the head tags of the page.
    3. When you are viewing the page in a browser, view the source of the page to look for a MySQL error. (They are hidden in the source code for semantic reasons)
    4. They are the only things I can think of at the minute. Please also check your server runs PHP 5 and I am not able to test the code on PHP 4, so I don’t know if it works on PHP 4 or not.

      If you do have a MySQL error in the source code and you need help with that or you have anymore problems please just shout again. Also any more info you could provide would be great. Screenshots, error messages anything you think might help.

  7. Just downloaded, unzipped and the readme text file doesn’t mention having to include the script and functions. I followed your instructions above and I get a blank page. If I view the source, there are no errors.

    I suppose it could be because I am running PHP v4.4.7?

  8. Andre Been Gravatar May 29th 2008

    Hello Veneficus Unus

    Thanks again for your fast reaction.

    I see in the ff errorconsole the following
    utility is not defined FormaValidation.js
    and for this one:
    utility.dom.attachEvent2(window, ‘onload’, UNI_form_attach);

    second error:
    $ not defined:
    $(document).ready(function() {

    and third
    ajaxdelete is not define

    this onde is after testing del function on screen

    greetings

    Andre

  9. @Hosea: I think something strange has been going on with my host recently. I have just checked the file on the server and it is an old zip I used, I checked my FTP log and it says I uploaded the new version.

    I’ve just uploaded the new version again. Please try and download it again and see if that helps.

    EDIT: I’ve just tested it on a PHP 4 server and all of the code seems to work fine, so it would seem you can use PHP 4 or 5 to run the code.

    @Andre Been: That would indicate that the javascript files are not being found. Please make sure that the javascript files are in the same location as tiamot.php and the other file.

  10. Andre Been Gravatar May 29th 2008

    I had all the files in the same directory but still.
    the error is:
    $ is not defined
    then he gives the place in the file:
    http:/www.???/htdocs/admin/javaprobeer/tiamot_js.js row 7

    If he can’t find the js file how does he know on what row the error occured

  11. hi, missing “mysql.class.php” into this zip file…

    and this zip doesnt have all files??

  12. @Andre Been: Sorry I didn’t make what I meant clear. The $ is not defined error is given when the jQuery javascript file cannot be found, the $ is the standard syntax for running jQuery commands if the jQuery file is missing then you end up with that error.

    @hi: Sorry about all the problems with the file. I have contacted my host and they had a few problems which caused some files to be overwritten by server back-ups that is why the file was missing. Hopefully all will be sorted soon.

  13. Andre Been Gravatar May 30th 2008

    Hello here i am again,

    I have done everything to get it working but i still have some errors. I had an error with formvalidation.js. after i put this file with all yours in the same directory. It was ok.
    But jquery.jeditable.mini.js and jquery.tablesorter.js
    still give errors

    I almost give up. I think i could use your work verry good but i dont know what to do now.

    sorry for bordering you

    greetings Andre

  14. Andre Been Gravatar May 30th 2008

    eureca

    It works. After i changed the kocation of the js files into a special script directory and made in the tiamot.php the changes to the new location it works.
    I have only one question left.
    After deleting it gives an ok for deleting row but after refresh it still appears.

  15. @Andre Been: Still not sure what was causing your problems as I’ve tried & tried to replicated them but haven’t been able to. Glad you managed to fix them though.

    As for the row not being deleted properly. I had this problem during development of the script and it generally turned out to be something wrong with the MySQL query however it is generated dynamically by the PHP to match the row you are deleting and has been tested extensively. It’s kinda odd that it gives the OK though.

    The only thing I can suggest is to check that “T” and “I” are set correctly in the top of tiamot.php.

    Don’t worry about asking all these questions, that what I’m here for. It’s just a little annoying when my server keeps overwriting files and stuff, lol.

  16. Andre Been Gravatar May 30th 2008

    hello
    I looked but what is the exact meaning of (I) Name of the previous tables Primary ID

    What do you mean by previous.

    the msql is working normaly because i can edit and insert.

    Andre

  17. Hey Andre,

    It just means the name of the Primary ID field in the table you have entered just before it.

    However if the edit & insert work it would suggest that the primary ID is already set correctly.

    I’m not sure what would cause the delete to stop working, the problem is that you said before the status message comes back saying it has deleted successfully. Since the row returns on refresh I can only think that the status message isn’t telling the truth.

    You could try this. If you can find the MySQL query for the delete, it should look like this:

    $db->query("DELETE FROM " . $db_info['T'] . " WHERE " . $db_info['I'] . " = '" . $id . "'") or $fail = true;

    change it to this:

    $db->query("DELETE FROM " . $db_info['T'] . " WHERE " . $db_info['I'] . " = '" . $id . "'") or $db->raise_error();

    then when you delete a row quickly highlight the status message that appears and view the selection source. You have to using Firefox to do that though. There should be a bit of code in between html comment tags, if you paste it here I’ll try my best to help you.

    I have been trying to find a better way to do debugging like this but so far I’ve come up blank.

    Sorry about all the problems your having, I error checked it as much as possible but obviously I didn’t check it enough. :(

  18. Andre Been Gravatar May 30th 2008

    hello
    This is all he say’s

    Row 12122 was deleted successfully

    andre

  19. Even after changing the code? :S

    It should have given you some sort of error. With-out any error codes I can’t do anything to help you… It’s kinda like being a cook without any ingredients, I can tell you the recipe, but I can’t help you make it…

    I’m sorry. If you can find an error code or message I’ll be glad to help you more. :(

  20. Filipe Gravatar Jun 4th 2008

    Hi, i try your TIAMOT v2.1, it seems work fine, but i have some PHP warnings at first time and next times page load:
    ….
    Notice: Undefined index: action in /HOST_DIR/web/tiamot.php on line 195

    Notice: Undefined index: value in /HOST_DIR/web/tiamot.php on line 195

    Notice: Undefined variable: data in /HOST_DIR/web/tiamot.php on line 87
    ….

    But actions, add, edit and delete work also.

  21. Hey there Filipe,

    The warnings are nothing to worry about, I will fix them in the next version. Until then to stop them from appearing just put this bit of code at the top of tiamot.php:

    error_reporting(0);

    It is generally not advisable to turn off error reporting completely so you could change 0 to E_ERROR and it will only report real errors.

    That should stop the warnings from appearing and making you page look horrible until I can fix them. Sorry about that & thanks for using my code. ;)

  22. Andre Been Gravatar Jun 5th 2008

    hello Venevics,

    I am still trying to get the deletefunction to work.
    I found that if i click on the delete ref that the id field is empty. so when he comes into the switch strtolower ($post['action']) case delete
    the =’”.$id.”‘ is empty

    second question how dificult is it to make it possible to select multiple tabels

    greetings
    Andre

  23. Hey Andre,

    I’ll start with your second question. I haven’t a clue, lol. Since the code is developed only to access one table it’s likely to be very difficult. You might be able to run copies of the same script on the page at the same time but I’ve never tried it.

    As for your first question I am still a bit confused as to what’s going on. The only reason the ID would be missing is if it wasn’t sent in the first place. Try holding your cursor over the del links and make sure the status bar of your browser says this:

    javascript: ajaxDelete(id number here);

    if there is no number between the ajaxDelete() then there is a problem with the database getting the id’s for your database table.

    Other than that I’m still stumped. Sorry. :(

  24. Antal Mihaly Gravatar Jun 6th 2008

    Hello Veneficus!

    I have the exact same problem as Andre Been. The table shows up with the correct data. If I hover over the ‘Del’ entries, in the FF status bar it shows the correct
    stuff (example: javascript: ajaxDelete(3); ), when I click it, it removes the correct line from the table, but it never reaches to ‘case “delete” :’ (tested with an echo “I was here”;) part in tiamot.php, so the delete query doesn’t execute. Naturally when I refresh the page, the deleted row reappears.

    Cheers,
    Mihaly

  25. Hey Antal,

    It was a good thought to try and debug the code like that but unfortunately even if the code was working you wouldn’t have gotten any output. It is made so that stray echo’s won’t interrupt the working of the script.

    I have figured out what was wrong thanks to what you said though. It turns out I had made a stupid mistake in the coding. I have updated the files inside the zip but it’s only one line so to save you from downloading the code again here is what to do.

    Find line 233 in tiamot.php it should say this:

    233
    
    case "delete" :

    and replace it with the following:

    233
    234
    
    case "delete" :
        $id = $_POST['id'];

    I have tested it and it works. If you are wondering why I couldn’t find the error, it was because the line that works for the add part worked for my delete because of the way I had named my database tables. It’s kind of a one in a million chance but I changed the table I was connecting to which had different field names and it did exactly what you described.

    Sorry about that, it should work for you now. Remember if you don’t want to do the edit yourself I have updated the download. ;)
    Sorry about all the trouble, and I hope you enjoy the script now. :)

  26. Great work!!!
    Thank you so much for sharing your script!
    This was exactly what I needed …

    regards,

  27. No problem Alex. Glad you like the script. :)

  28. Karol Gravatar Jun 9th 2008

    Hi,
    I have a few problems with this script. Fisrt is that after Adding or deleteing rows I got msg like : “Sorry, row (right id) could not be deleted.” or “Sorry, your new row could not be added.” but after refreshing (F5) I see added rows and don’t see deleted rows. Also I have a strage problem with edit, i click on text, textfield is bringing on and I edit text, click save and I see in current cell a copy of entire table. Any sollution?
    Regards.

  29. Hi Karol,

    The ‘Sorry…’ errors are generally triggered by the MySQL query returning false, so it’s very unusual for it to have actually inserted the rows and deleted the correct rows. The only thing I can suggest is to make sure all of your database connection info is correct.

    Your other problem is very odd. I have never come across it, the editing is done by a jQuery plugin and I have never seen that happen before.

    Could you give me a bit more information such as:

    • What browser/s you see the problems in.
    • What version of PHP & MySQL you are running.
    • Are you using any other javascript on the same page as the tiamot script

    Another thing that I always suggest is to start from scratch on a brand new file and see if everything works.

    If you can try all that and get back to me I’ll try and help you some more.

  30. J.Halmu Gravatar Jun 11th 2008

    Working, very thanks! This rules!

  31. No problem. ;)

  32. subhashini Gravatar Jun 16th 2008

    HI,

    This was an excellent script and more friendly too. I like to change it into asp. I tried but the script(jquery script) part doesn’t work on this. Please let me know is there any ways to work it on asp.

    Thanks

  33. Hi,

    By all means convert it to ASP. I’m unable to help you with any ASP scripting though since I don’t have a server that can run ASP & I personally don’t like the language, although I can see that it has it’s uses.

    I am not sure why the jQuery would cause any problems though since that is javascript and is ran on the client side. I can only think that the problem may be with a part of the conversion from PHP to ASP. Other than that I am unable to help due to my lack of ASP knowledge.

    Sorry. :(

  34. Hi,

    I love this… thank you so much already. I am only having one problem.

    My page looks OK and the data is behaving normally (adding/deleting rows, editing cells, etc.) but the alternating row colors are missing and the header-click sorting is not there either. I can’t figure out what’s wrong. Maybe there’s a common cause or something you can tell me to look for?

  35. OK, I figured out how to fix the problem I was having. I wanted the insert area ABOVE the table (at the top of the page) so I had it higher in the code. It turns out various problems are caused when you have the tiamot_insert line before the tiamot_table line… so if you need the insert area to show up above the table of data you have to use CSS to position it there. It has to come after the tiamot_table line in the code, though.

    Cheers!

  36. Hmm. Very strange. That shouldn’t happen. I’ll have a look and see if I can see why that is happening.

    Thanks for letting me know and well done for figuring that out. :)

  37. Any chance of paging? It would be handy especially when deadlig with large dataset?

    Anyway, good job!

    Cheers

  38. I’ve been looking for a way to add a paging system into the code but have been unable to solve a problem it causes with the AJAX.

    I may have to alter the code slightly, I will do it as some point by I am currently busy working on two websites so haven’t had a lot of time. :(

    Don’t worry though I’ll get onto it soon. :D

  39. Greetings Veneficus!

    Great job!

    Install instructions were very easy to understand. I had my database added successfully in a matter of minutes!

    Looking forward to your paging system, or even scrolling would work for me, as I have hundreds of records to manage in my database.

    Thanks again!

    Linda

  40. Glad it works for you Linda.

    Hopefully I’ll be getting onto the paging system soon but due to work commitments at the minute I’m unable to start it yet.

    I’ll definitely be adding it soon though so please check back often. :)

    Paul.

  41. Anthony Gravatar Jun 26th 2008

    Nice work duder.

    I’d like to know if it is possible to change one of the add entry form inputs to a textarea for larger entry’s. This would also be the same for that field in the table as well.

  42. Yep, all you would need to do is this. In tiamot.php find the tiamot_insert() function and look for the bit that looks like this:

    foreach($add_list as $key => $field) {
    		  $o .= '<label class="' . $field . '" for="' . $field . '">' . ucwords($key) . ':</label>
    		  		 <input type="text" value="" id="' . $field . '" />'."\n";
    }

    All you need to do is change it to something like this:

    foreach($add_list as $key => $field) {
      if($field == "field_name") {
        $o .= '<label class="' . $field . '" for="' . $field . '">' . ucwords($key) . ':</label>
    		  		 <textarea id="' . $field . '"></textarea>'."\n";
      } else {
        $o .= '<label class="' . $field . '" for="' . $field . '">' . ucwords($key) . ':</label>
    		  		 <input type="text" value="" id="' . $field . '" />'."\n";
      }
    }

    Something like that should do the trick. :)

    The field in the table is generated by a jQuery plugin and should be set to use the correct input depending on the amount of text. Let me know if you have any problems or this doesn’t work and I’ll do my best to help you out. ;)

    TIP: If you end up needing a lot of text areas you may be better off using a switch instead of lots of ifs. Let me know if you need to know how that would look.

  43. Anthony Gravatar Jun 27th 2008

    makes total sense.

    Next thing I am working on is to create a link next to the ‘del’ link that says preview. I have the preview link generated and am working on the function(tiamot_preview()) in tiamot.php and ajaxPreview(id) intiamotjs.js that will generate a preview of the data set associated formatted in a specific way.

    ajaxPreview(id) :

    function ajaxPreview(id) {
    	$('img#loading').show();
    	$.ajax({
    		type: "POST", 
    		url: "tiamot.php",
    		data: "action=preview&amp;id=" + id,
    		success: function(msg) { 
    			if(msg.indexOf("false") == -1) {
    				$('tr.' + id).fadeOut("fast", function() {
    					$(this).remove();
    					$("#tiamot").trigger("update"); 
    					$("#tiamot").trigger("reSort");
    					$('img#loading').hide();
    					$('div#statusMsg').html('Row ' + id + ' preview was generated successfully'); 
    				});
    				t = setTimeout("clearStatusMsg()", 5000);
    			} else {
    				$('div#statusMsg').html('Sorry, row ' + id + ' could not be generated.');
    				$('img#loading').hide(); 
    				t = setTimeout("clearStatusMsg()", 5000);
    			}
    		}
    	});
    }

    tiamot_preview :

    function tiamot_preview() {
    	global $db, $field_list, $edit_list, $db_info;
     
    	$r = $db-&gt;query("SELECT * FROM " . $db_info['T']) or $db-&gt;raise_error();
     
    	$o = "
     
    		  ";
     
    	foreach($field_list as $key =&gt; $field) {		
    		$o .= "" . ucwords($key) . "";
    	}
     
    	$o .= "Delete";
     
    		   	$o .= "Preview
     
     
    		   ";
     
    	while($row = $db-&gt;fetch_array($r)) {
     
    		$o .= "";
     
    		foreach($field_list as $field) {
    			if(!in_array($field, $edit_list)) {
    				$o .= "" . $row[$field] . "";
    			} else {
    				$o .= "" . $row[$field] . "";
    			}
    		}
    			$o .= "<a>Del</a>
    				   ";
    				   $o .= "<a>Preview</a>
    				   ";
    	}
     
    	$o .= "
    		   ";
     
    	echo $o;
    }

    Any ideas sorry for the long post

  44. Hey there,

    I’m not exactly sure what you’re trying to do… Sorry, for a coder I’m a bit crap at conceptualisation.

    I can tell you though that to add a preview button all you need to do is add it as a new table row after the delete button in the tiamot_table() function, which you may have already done.

    The tiamot_* functions are just insertion functions they don’t actually do any work other than allowing the user to place the data in separate places on their page.

    You have the AJAX function just about spot on for anything as it’s nearly the same thing no matter what you are doing.

    To do the preview function itself you would add an action to the switch under the AJAX back end marker inside tiamot.php.

    If you can explain a little more about what you are trying to generate a preview of I will help you as much as I can.

  45. Anthony Gravatar Jun 28th 2008

    The scope of the project is to create a basic article administration module that allows for adding new, editing current and previewing a current as well. So clicking the preview link will generate a formatted preview of the selected row as would been seen on the public site. I will be working on it for the next few hours from what you said I am on the right track.

    The hurdle I am having now is displaying just the selected row as it is now its displaying the entire table.

    I will work at it a bit and give you an update.

  46. Anthony Gravatar Jun 28th 2008

    Above the Delete switch is

    		case "preview" :
    		$id = $_POST['id'];
    			$id = $_POST['id'];
    			$db-&gt;query("SELECT * FROM " . $db_info['T'] . " WHERE promo_id = '" . $id . "'") or $fail = true;
    			if($false == true) {
    				echo "false";
    			} else {
    				echo createPreview($row, $id);
    			}
    		break;

    After the ajax break in tiamot.php

    function createPreview($rows, $id) {
     
    	$o = "
     
    		  ";
     
    	foreach($field_list as $key =&gt; $field) {		
    		$o .= "" . ucwords($key) . "";
    	}
     
    	$o .= "Delete";
     
    		   	$o .= "Preview
     
     
    		   ";
     
    	while($row = $db-&gt;fetch_array($r)) {
     
    		$o .= "";
     
    		foreach($field_list as $field) {
    			if(!in_array($field, $edit_list)) {
    				$o .= "" . $row[$field] . "";
    			} else {
    				$o .= "" . $row[$field] . "";
    			}
    		}
    			$o .= "<a>Del</a>
    				   ";
    				   $o .= "<a>Preview</a>
     
    				   ";
    	}
     
    	$o .= "
    		   ";
     
    	echo $o;
    }

    In tiamot_js.js

    function ajaxPreview(id) {
    	$('img#loading').show();
    	$.ajax({
    		type: "POST", 
    		url: "tiamot.php",
    		data: "action=preview&amp;id=" + id,
    		success: function(msg) { 
    			if(msg.indexOf("false") == -1) {
    			$(this).html(value);
    					$("#tiamot").trigger("update"); 
    					$("#tiamot").trigger("reSort");
    					$('div#statusMsg').html('Row ' + id + ' preview was generated successfully'); 
     
    				t = setTimeout("clearStatusMsg()", 5000);
    			} else {
    				$('div#statusMsg').html('Sorry, row ' + id + ' could not be generated.');
    				$('img#loading').hide(); 
    				t = setTimeout("clearStatusMsg()", 5000);
    			}
    		}
    	});
    }

    Doing this does not return anything when clicking the ‘preview’ link but when click the add button it returns all the rows in the original table. For whatever reason the preview button will not work. Do I need to extend the ajaxPreview like the ajaxAdd in the tiamot,php?

    I’m lost duder.. any help?

  47. Ok, I understand your concept now. In fact I’ve just built the entire thing and tested it. Here’s what you need to do.

    First we need to add the javascript so replace your ajaxPreview() with this one:

    function ajaxPreview(id) {
    	$('img#loading').show();
    	$.ajax({
    		type: "POST", 
    		url: "tiamot.php",
    		data: "action=preview&amp;id=" + id,
    		success: function(msg) { 
    			if(msg.indexOf("false") == -1) {
    				$('img#loading').hide();
    				$('div#statusMsg').html('Row ' + id + ' preview was generated successfully');
    				$('div#preview').html(msg);
    				t = setTimeout("clearStatusMsg()", 5000);
    			} else {
    				$('div#statusMsg').html('Sorry, row ' + id + ' preview could not be generated.');
    				$('img#loading').hide(); 
    				t = setTimeout("clearStatusMsg()", 5000);
    			}
    		}
    	});
    }

    Next we will add the action into the php switch. Replace yours with this:

                    case "preview" :
    			$id = $_POST['id'];
    			 $r = $db-&gt;query("SELECT * FROM " . $db_info['T'] . " WHERE promo_id = '" . $id . "'") or $fail = true;
    			 $row = $db-&gt;fetch_array($r);
    			 if($fail == true) {
    			 	echo "false";
    			 } else {
    			 	echo createPreview($row, $id);
    			 }
    		break;

    Then we create the createPreview() function. This is the bit I can’t really write as I don’t know what your info should look like in it’s preview, however here is the basic code you just need to work your layout around it.

    function createPreview($rows, $id) {
    		global $field_list;
    		$o = '';
    		foreach($rows as $key =&gt; $row) {
    			if(!in_array($key, $field_list)) {
    				continue;
    			} else {
    				$o .= '<strong>'.$key.':</strong> '.$row;
    			}
    		}
    		return $o;
    }

    At the minute it just echo’s out the field names and their value. Now all you need to do is copy the delete row from the end of the createTable() function and paste it straight after, and then the same again in the tiamot_table() function.

    Finally you just need to add the div to put the preview in. Best way to do that is to make another function called tiamot_preview() and should look like this.

    function tiamot_preview() {
    	$o = "";
     
    	echo $o;
    }

    Then call it along with the others on the page you are showing the table on.

    Hopefully that’s everything and it’ll work for you. Remember to customise the createPreview() function to make to info look like you need it to look.

    Any problems just ask. ;)

  48. anthony Gravatar Jun 30th 2008

    Well duder I think I did it as you instructed but i get “Invalid argument supplied for foreach()” within the createPreview() function.

    function createPreview($rows, $id) {
    global $field_list;
    $o = ”;
    foreach($rows as $key => $row) {
    if(!in_array($key, $field_list)) {
    continue;
    } else {
    $o .= ‘‘.$key.’: ‘.$row;
    }
    }

    return $o;
    }

    Any suggestions?

  49. Anthony Gravatar Jun 30th 2008

    Alright I think I have it nailed down to the case statement. But no matter what I try I can’t get it to work. Here are the snippets..

    createPreview()
    global $field_list;
    $o = ”;
    foreach($rows as $key => $row) {
    if(!in_array($key, $field_list)) {
    continue;
    } else {
    $o .= ‘‘.$key.’: ‘.$row;
    }
    }
    return $o;
    }

    case Preview
    case “preview” :
    $id = $_POST['id'];
    $r = $db->query(”SELECT * FROM ” . $db_info['T'] . ” WHERE promo_id = ‘” . $id . “‘”) or $fail = true;
    $row = $db->fetch_array($r);
    if($fail == true) {
    echo “false”;
    } else {
    echo createPreview($row, $id);
    }
    break;

    So, everything else works except the invallid args in the foreach() statement according to the error output….

  50. Anthony Gravatar Jun 30th 2008

    Adding to the above the createPreview function begins like this

    createPreview($rows, $id) in my code, I copied from the wrong place…

  51. Anthony Gravatar Jun 30th 2008

    If I swap out the db->query with the on from tiamot-table it runs without error but returns the top row in the table regardless of selection…

  52. Hi,

    If you continue to get and invalid argument on a foreach it means that the variable entered is not an array. Since it stops happening when you swap the query to a different one it simply means the query is wrong.

    I was just guessing at the query so it may not be right as I don’t have your database but that is where the error is. The best way to debug a quere is to enter it into phpmyadmin or enter a very basic query that you know will work. Try something really simple like this:

    $r = $db->query(”SELECT * FROM ” . $db_info['T']) or $fail = true;
  53. Anthony Gravatar Jun 30th 2008

    AAAHHHHH!!!!

    So as i am echoing some stuff to see whats all going on I decided to echo the entire $POST, and I’m looking through it think man everything looks ok, But its not!!

    It posts id as ‘&id’ and there my friend is the answer! I change the & that I didn’t catch in the js to & and BAM its good to go.

    Thank you for all your help. wonderful stuff buddy.

  54. Ahhh, I get you.

    That would explain why it was acting as if the query was wrong.

    Glad you got it sorted. Enjoy the code. :)

  55. Anthony Gravatar Jul 1st 2008

    Alright buddy last question. Ans thank you for your all star help! How would make the following function to be editable as well? i have tried a number of things and cannot get it to work.

    Again, thank you for all your help!

    function createPreview($rows, $id) {
    		global $field_list, $edit_list;
    		$o = '';
    		foreach($rows as $key =&gt; $row) {
    			if(!in_array($key, $field_list)) {
    				continue;
    			} else {
    				$o .= "";
    				$o .="";
    				if($key == "promo_title") {
        				$o .= ''.$row.'';	  		
      				}
    				$o .= '';
    			}
    		}
    		$o .= "";
    		return $o;
    	}
  56. To make any field on the page editable you just add the class edit to a div placed around the content you want to be editable. So like this:

    <div class="edit">content to edit</div>

    The problem is that it will make a call to the default action in the php file which is set to take a field name & id from the divs id. That’s how it know’s where to put the information in the database. Something like this code might work but I’m not sure:

    function createPreview($rows, $id) {
    	global $field_list, $edit_list;
    	$o = '';
    	foreach($rows as $key => $row) {
    		if(!in_array($key, $field_list)) {
    			continue;
    		} else {
    			$o .= "";
    			$o .="";
    			if($key == "promo_title") {
    				$o .= '<div class="edit" id="'.$key.' '.$id.'">'.$row.'</div>';	  		
    			}
    			$o .= '';
    		}
    	}
    	$o .= "";
    	return $o;
    }

    I’ve used a div but you can use whatever you like. A td, a span, a b, a strong anything that allows a class & id attribute which is most X/HTML tags.

    Hope that helps. ;)

  57. Anthony Gravatar Jul 1st 2008

    This is what I ended up with.