Jump to content


Adding additional table fields


  • You cannot reply to this topic
5 replies to this topic

#1 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 25 March 2007 - 04:20 AM

If I wanted to add additional table fields when the EtoGal snippet "checks for table and descriptions".

Eg a price field, format (paper, canvas) field, original avaliable field etc

Is it simply a case of adding additional fields after the "descr" row?
// check for table and descriptions
$pics_tbl = $etomite->db.$gtable;
// If gallery table has not been created yet, create it now:
$descvalid = 0; // assume descriptions not supported
$query=mysql_query("DESC $pics_tbl");
if(!$query) {
  $sql="CREATE TABLE $pics_tbl (
          `id` int(10) unsigned NOT NULL auto_increment,
          `gal_id` int(10) unsigned NOT NULL,
          `filename` varchar(50) NOT NULL,
          `title` text NOT NULL,
          `date` datetime NOT NULL,
          `descr` text default NULL,
          PRIMARY KEY  (`id`)
          ) TYPE=MyISAM AUTO_INCREMENT=1 ;";
  $query1=$etomite->dbQuery($sql);
  $descvalid = 1; // they are with this table
}
else {

If so, If I was to check for the existance of additional fields like the //"$descvalid" check would the correct sequencing for checking for these fields be if field a exists (if false, then create a), true, then check field b, if field b exists (false, then create B) if true then c...etc. Or is there a way to check fields a,b,c then create a,b,c (or create a,c) (or create c,B) etc?

When calling it, I'm thinking to simply add to the //edit gallery and its pictures, the additional fields in the middle of this...
   if($_REQUEST['action']=="edit_pics") {    // If "Edit Gallery and its pictures" has been used
      for($i=0;$i<$_REQUEST['number'];$i++) {
        if($_REQUEST['delete'.$i]=="yes") {
          $rs0=$etomite->dbQuery("SELECT id,filename,

[b]***new field here, new field here, new field here,*** [/b]

FROM $pics_tbl WHERE id='" . $_REQUEST['pic_id'.$i] . "'");
          $deletepic=$etomite->fetchRow($rs0);
          if(file_exists($path_to_gal.$deletepic['filename'])) unlink($path_to_gal.$deletepic['filename']);
          if(file_exists($path_to_gal."tn_".$deletepic['filename'])) unlink($path_to_gal . "tn_" . $deletepic['filename']);
          $rs1=$etomite->dbQuery("DELETE FROM $pics_tbl WHERE id='" . $_REQUEST['pic_id'.$i] . "'");
}
        if($_REQUEST['modified'.$i]=="yes") {
          // restructured for clarity and extended MF oct2005
          $updateQueryString= "UPDATE ".$pics_tbl." SET ";
          $updateQueryString.= "title='".addslashes($_REQUEST['title'.$i])."'"; //add title content
          if($keep_date!="yes") $updateQueryString.=",date=NOW()";
          if($descvalid==1) $updateQueryString.=", descr='".addslashes($_REQUEST['descr'.$i])."'"; //MF add descr content

[b]****add new fields here to update something like this*****[/b]
 if($newfield1==1) $updateQueryString.=", newfield1='".addslashes($_REQUEST['newfield1'.$i])."'"; //Add newfield content
 if($newfield2==1) $updateQueryString.=", newfield2='".addslashes($_REQUEST['newfield2'.$i])."'"; //Add newfield content
//etc
          $updateQueryString.=" WHERE id='" .$_REQUEST['pic_id'.$i]."'";
          $rs2=$etomite->dbQuery( $updateQueryString );
        }
      }

Then create the additional forms required to enter and post the info in the forms section.

Also, if my understanding is correct, this can be written as a snippet and called in the EtoGal snippet (with a few changes to the original).

I just want to know if I am on the right track. If this question is beyond the scope of this forum, just reply: "too hard"- go and get paid help! :)

Edited by Cris D., 25 March 2007 - 11:59 AM.


#2 luislacerda

    Etomite Forum Fan

  • Member
  • Pip
  • 87 posts

Posted 25 March 2007 - 02:17 PM

I was about to place the exact same question.
Thanks Cris D. Hopefully we will get some help here.

View PostCris D., on Mar 25 2007, 05:20 AM, said:

If I wanted to add additional table fields when the EtoGal snippet "checks for table and descriptions".
....
I just want to know if I am on the right track. If this question is beyond the scope of this forum, just reply: "too hard"- go and get paid help! :)


#3 Randy

    Likes Etomite Forums!

  • Member
  • PipPip
  • 309 posts

Posted 25 March 2007 - 02:24 PM

Hi Chris,

You're doing a lot of hacking on this code and you've already seen the difficulty it can cause with odd problems and the like.

I would like to suggest you create a separate table for your unique data elements and write your own snippet as you suggest. This will allow you minimize the impact your changes have to the "working" original. This will also allow you to update the EtoGal snippet as changes are made without hunting down your mods, missing a comma, and blowing the entire thing up again.

So...
1. create a new table for your unique stuff
2. create a snippet that has the queries in that you need for your new table
3. gather the output from the EtoGal snippet into your new snippet and manipulate the $output variable as you need to
4. return the output to Eto for rendering

Try this and see what happens. I might suggest you get a fresh copy of the EtoGal snippet so your hacks that are currently causing you difficulty are removed and you start with a known good version ;)

#4 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 25 March 2007 - 03:38 PM

I'd have to agree with Randy on the extra data columns... A generic snippet would allow anyone to have whatever custom columns they need while still allowing updates to be performed with little impact on existing installs... The snippet could even go so far as to contain a data model at the top which could be used to automagically ALTER or CREATE the table holding the additional data... Adding the appropriate meta data to the data model would cause the snippet to make the required changes...

Just a thought...

#5 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 26 March 2007 - 10:27 AM

View Postluislacerda, on Mar 26 2007, 12:17 AM, said:

I was about to place the exact same question.
Thanks Cris D. Hopefully we will get some help here.
As you can see, apparently it is easier to write a new snippet rather than mucking with the original. Unfortunately, I'm not familiar with PHP & MySQL language to know where to start (but I'm learning). What i'm saying is that although I will still be working on this, don't hold your breath waiting for me luislacerda. Are you capable of writing this? Do you know what Ralph is talking about? I understand the concept but do not know how to structure it or write it. (Which is why I prefer to hack than create at this stage :)

I have posted this to continue in Etogal Wish List here.

Edited by Cris D., 26 March 2007 - 10:55 AM.


#6 luislacerda

    Etomite Forum Fan

  • Member
  • Pip
  • 87 posts

Posted 26 March 2007 - 09:32 PM

View PostCris D., on Mar 26 2007, 11:27 AM, said:

As you can see, apparently it is easier to write a new snippet rather than mucking with the original. Unfortunately, I'm not familiar with PHP & MySQL language to know where to start (but I'm learning). What i'm saying is that although I will still be working on this, don't hold your breath waiting for me luislacerda. Are you capable of writing this? Do you know what Ralph is talking about? I understand the concept but do not know how to structure it or write it. (Which is why I prefer to hack than create at this stage :)

I have posted this to continue in Etogal Wish List here.
Cris D. I'm with you again. I can fiddle with MySQL and PHP but in a very limited way. Thanks anyhow!

Edited by luislacerda, 26 March 2007 - 09:32 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users