Jump to content


Newbie Coding Questions


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

#41 Cris D.

    Loves Etomite Forums!

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

Posted 30 April 2007 - 12:20 PM

Is there a way to "wrap" the output from megecodeVars() so that the output is not repeated and presented horizontally instead of vertically? Your tutorial uses odd and even class to change the way is looks but it's output is linear too.

eg. page display:
id1 id2
id3 id4

instead of...
id1
id2
id3
id4

I tried using
<table><tr><td>[!etogal_multigals!]</td>
<td>[!etogal_multigals!]</td></tr></table>
as the chunk to parse but it just repeated the output 4 times in a line.

Edited by Cris D., 30 April 2007 - 12:42 PM.


#42 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 30 April 2007 - 03:12 PM

You don't need to use tables for the output, Cris... While the default tags for mergeCodeVars() is tr, you can completely omit the tag altogether and simply use your own data template... I quite often use formatting not related to tables for the output...

#43 Cris D.

    Loves Etomite Forums!

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

Posted 05 May 2007 - 11:11 AM

I have been playing with templates... Is there a way to set a "target" for an instance of a row of data parsed through a chunk using mergeCodeVars (or any other API)?

I know how you all hate vague, so here's a concrete example...

$target1.="<table name=\"one\"><tr><td>".$output{evenStyle};
$target1.="</td></tr></table>";
$target2.="<table name=\"two\"><tr><td>".$output{oddStyle};
$target2.="</td></tr></table>";
mergeCodeVars(...
oddStyle=$target1;
evenStyle=$target2;
);
return $output;

Now I know this doesn't work, but I hope you can see what I'm getting at. Controlling the output from a single snippet rather than syncronising multiple snippets.

#44 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 05 May 2007 - 01:06 PM

@Cris D.

Are you referring to having alternating row colors, by chance, which can already be done by sending $oddStyle and $evenStyle to mergeCodeVars()...??? It works as is evident by the tutorials on my website as well as the multitude of data interfaces that I have written for several sites... The control is handled by the mergeCodeVars() function itself, based on passed parameters... This tutorial probably explains it best... You might also find some good information in this one too...

#45 Cris D.

    Loves Etomite Forums!

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

Posted 05 May 2007 - 09:59 PM

Thanks Ralph,
Changing the colours is not what I mean, your tutorials (I have ALL of them printed off and know them well). I guess I'm trying to understand the boundaries of Etomite so that I can work within them.

The question that I have been trying to ask since post 41 http://www.etomite.com/index.php?s=...ost&p=42415
is besides the $tag variable, how can I format the output from a mergeCodeVars to wrap inside a page from left to right and from top to bottom.

Given the nature of Etomite and Dean's (and other's work) with templates, the $tag and $chunkName doesn't seem sufficient to do this (unless I am missing something simple that everyone knows and I don't!)

Option 1) If I use a chunk, My options are to enclose the output in <table>, a series of tables will be returned: they are returned down the page, not wrapped. I set the table width to say 20px, a series of 20px tables are returned down the page, I set the table in the snippet and enclose the chunk inside <tr>, a single row is returned (no wrap), I enclose in <td>, a single row is returned that goes a mile off the screen to the right.

Option 2) If I try to use the $tag and set it to <div> the result is obvious: no wrap. I set to table, there is no wrap, I set it to <tr>, guess what: no wrap, I set to <td>, all results are returned a mile off the screen to the right, hmmm no wrap.

My question is: What is option number 3? So the results say 20px wide can be returned in a 800px window, 4 times, then wrap down to the next row?

[EDIT 27/9/07] This is solved by using your CSS. Set the oddStyle and evenStyle classes in the css to use .oddStyle{float:left} for example. CSS is now more about positioning and layout than just colors and borders. Up to this stage, I did not realize how powerful CSS was now-days. It's really an essential tool! [/EDIT]

Edited by Cris D., 27 September 2007 - 11:04 AM.


#46 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 05 May 2007 - 10:41 PM

Okay, Cris D., Now I see what you want... You want multiple columns for your results... There are several ways to do this...

First way... If, for example, you want item one and item two on the same line but in columns, you can simply merge two records into one and then send the merged data to mergeCodeVars() where your row template can display the two records at once... This will even work with sending the entire merged result set in a single mergeCodeVars() call...

Second way... If you want the first half of the results in the left column and the last half in the right column you can process each half into its own template, one representing the left div and the other being the right div... Using div positioning you would have two side by side snaking columns of data...

Both methods take a minimum of additional code within your snippet... If you need more information on how to do this, just shout... You seem to grasp things pretty well so this might be enough to get you started... Oh yeah, I did say several ways because there are more ways but these two are probably the best two to start with...

#47 Cris D.

    Loves Etomite Forums!

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

Posted 05 May 2007 - 10:55 PM

OK I got the merge data bit for the First way... makes sense.
The second way, Do you mean using 2 different snippets calling the data independantly and using the $tag="div" to align them?

#48 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 06 May 2007 - 12:12 AM

View PostCris D., on May 5 2007, 06:55 PM, said:

OK I got the merge data bit for the First way... makes sense.
The second way, Do you mean using 2 different snippets calling the data independantly and using the $tag="div" to align them?
No, my thinking is along the lines of creating two data sets from the original results, using a single loop to load the two, and then making two separate calls to mergeCodeVars(), one for each column... All done from one snippet... So one loop and two calls to process the two data sets... Using a different class or id for the template would allow you to use the same template code for each column, letting the class or id css control positioning... Make sense...???

#49 Cris D.

    Loves Etomite Forums!

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

Posted 13 May 2007 - 11:11 AM

I'm trying to extend the tableMaker snippet to allow the column names to be set from the snippet call. When I put...

[! tableMaker?names=name,age,phone,address!] then try to call the variables as an array

$names=array();
print_r($names);

the array is blank and the error is returned "using automatic data entry in snippet call"

I am trying to do this...
($colName=$name=>name)
$colName."".$i=$key=>$value Therefore $colName1="name";
$colName."".$i=$name=>age Therefore $colName2="Age";
$colName."".$i=$name=>phone Therefore $colName3="phone";

I know my use of $i sux and my array syntax is not right (I can work on that by myself). I just want to know...
Why the $names=array() would be blank if it was generated in the snippet call: the error is telling me it DOES exist!

#50 mikef

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,551 posts

Posted 13 May 2007 - 11:41 AM

View PostCris D., on May 13 2007, 12:11 PM, said:

I'm trying to extend the tableMaker snippet to allow the column names to be set from the snippet call. When I put...

[! tableMaker?names=name,age,phone,address!] then try to call the variables as an array

...
I just want to know...
Why the $names=array() would be blank if it was generated in the snippet call: the error is telling me it DOES exist!
I expect that
$names=array();
replaces the initial contents of $name with a new, empty, array, which isn't what you want!

To get the column names from the snippet variable into an array try something like:
$cnames=explode( "," ,  $names );

Edited by mikef, 13 May 2007 - 11:44 AM.


#51 Cris D.

    Loves Etomite Forums!

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

Posted 13 May 2007 - 01:09 PM

^_^ Thanks mikef works like a charm.

#52 Cris D.

    Loves Etomite Forums!

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

Posted 16 May 2007 - 12:51 PM

3 small items has grown rather FAT. Sorry. :D But I still have more questions!

I have been trying to get a variable appended to each element of a variable length array for over 2 weeks with limited success.

I want Array[0]=>($field1."VARCHAR (100), $field2."VARCHAR (100)",$field3."VARCHAR (100)")

At best all I can manage is Array[0]=>($field1,$field2,$field3,VARCHER(100)).
Details: The $fields are user-chosen names called from a snippet call and can be ANY NUMBER of fields.

I have tried foreach(), while(), do while(), for() but each instance (required to count the number of fields and add the variable text to each) only adds the text to the end of the array.

How do I append a variable to an element of an array?

#53 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 16 May 2007 - 01:52 PM

View PostCris D., on May 16 2007, 08:51 AM, said:

How do I append a variable to an element of an array?
What, exactly, are you trying to achieve...??? Although some people frown upon its use, I make extensive use of PHP's extract() function - mainly because it has more power than people give it credit for having and uses far less code than loops... If you've been playing with my code tutorials, and I know you have, then you would notice that I use extract() and the getFormVars() API function... But, regardless of where the data comes from, you should still be able to concatenate any number of values into an array value - if done properly... It all depends on what you're trying to accomplish...

In your examples above, it appears that you are addressing the task at hand incorrectly... Here is how I think you want to tackle this task...

$fields = array();
$fields[] = $field1." VARCHAR(100)";
$fields[] = $field2." VARCHAR(100)";
$fields[] = $field3." VARCHAR(100)";

But, again, it all depends on where the data is coming from... If you are trying to extract the data from a forms $_POST results then you would either need a loop, if you don't know exactly how many results there might be, or you need to hand-code as I displayed above... Have you looked at the FormHandler snippet, by chance...???

Any way you slice it, more details would be helpful in assuring that you get the correct answers to your questions...

#54 Cris D.

    Loves Etomite Forums!

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

Posted 17 May 2007 - 09:37 AM

I try to make my posts as short as possible, but you want details...
Currently I am using hand-coded queries that create a generic table...
##########New Table Configuration###################
$char=" VARCHAR ";//Set preferred character Type
$length="(100),";//set preferred length
$fieldname1="name1";//insert names here to be used
$fieldname2="name2";//for all new tables
$fieldname3="name3";
$fieldname4="name4";
$fieldname5="name5";
$field1=$fieldname1."".$char."".$length;
$field2=$fieldname2."".$char."".$length;
$field3=$fieldname3."".$char."".$length;
$field4=$fieldname4."".$char."".$length;
$field5=$fieldname5."".$char."".$length;

###########Create New Table and populate it##########################

$newtable.='CREATE TABLE `'.$etoPrefix."".$tmPrefix."".$table.'`';
$newtable.="(";
$newtable.="`id` INT(100) NOT NULL AUTO_INCREMENT,";
$newtable.=$field1;
$newtable.=$field2;
$newtable.=$field3;
$newtable.=$field4;
$newtable.=$field5;
$newtable.="PRIMARY KEY (`id`)";
$newtable.=")";
$newtable.=" TYPE=myisam;";

$etomite->dbQuery($newtable);
 
//enter dummy data for row 1 so that getIntTableRows has something to display
  $sql = 'INSERT INTO `'.$etoPrefix."".$tmPrefix."".$table.'` (`id`, `name1`, `name2`, `name3`, `name4`, `name5`) VALUES (NULL, \'data1\', \'data2\', \'data3\', \'data4\', \'data5\');';
$etomite->dbQuery($sql);

I'm trying to extend that to allow for user input (via snippet call, form, whatever, it's fairly easy to get an array to use but I can't seem to integrate all the bits together).

I tried adapting formHandler foreach function with code like this:

$names=array([0]=>(name,age,phone));
$cnames=explode( " , " ,  $names );
$i=1:
$fname="fieldname";
foreach($cnames as $value){//I also tried $cnames as $key=>$value and other combos
$chunkNames.=$fname."".$i;
$column_name.=$value;
$newFields.=$value."".$char."".$length;
$i++;
}
Thinking that this would collect the following output:
return $chunkNames;
would show: fieldname1fieldname2fieldname3
return $column_name;
would show: nameagephone
return $newFields;
would show:name VARCHAR (100) age VARCHAR (100) phone VARCHAR (100)

However, this is the result for $newFields (the most important one for me at the moment).

nameagephone VARCHAR (100).

Obviously each array element is being included, but not appending the $char."".$length between the elements, just once at the end!

As mentioned, I tried a whole range of functions with a variety of syntax styles...

Quote

I have tried foreach(), while(), do while(), for()
But the result is always the same, it seems to loop, but not append the $variables between elements, only at the end...

Therefore...

Quote

How do I append a variable to each element of an array in a loop?

Edited by Cris D., 17 May 2007 - 11:25 AM.


#55 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 17 May 2007 - 01:27 PM

Okay... Right from the start I see a problem... $names=array([0]=>(name,age,phone)); should be more like $names=array([0]=>('name','age','phone'));... By not encapsulating the variables in quotes you are passing them as constants - which will be empty... BUT... If you are passing $names in the snippet call then you have more problems... You don't need to play around with $names=array([0]=>('name','age','phone')); at all... You would pass $columns as ?columns=name,age,phone in the snippet call and then simply do the $names = explode(",", $columns) on within the snippet... That would create the $names array which would contain ([0]=>'name',[1]=>'age',[2]=>'phone')... But this is only a single dimensional array... You need a multi-dimensional array or you need to build the SQL on the fly... I'm a bit short on time at the moment to give an example of how, in my opinion, best to achieve this task... I might be able to elaborate more on this subject later...

#56 Cris D.

    Loves Etomite Forums!

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

Posted 19 May 2007 - 11:43 AM

I got the array working my problem was whitespace in the explode("_,",_$names)!!!... Now, you were saying?

Edited by Cris D., 19 May 2007 - 11:53 AM.


#57 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 19 May 2007 - 02:50 PM

View PostCris D., on May 19 2007, 07:43 AM, said:

I got the array working my problem was whitespace in the explode("_,",_$names)!!!... Now, you were saying?
Which whitespace...??? Do you have an example of the parameters you are working with...???

#58 Cris D.

    Loves Etomite Forums!

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

Posted 19 May 2007 - 09:42 PM

It was identical to the example you had above...

Quote

You would pass $columns as ?columns=name,age,phone in the snippet call and then simply do the $names = explode(",", $columns) on within the snippet...
which was creating the array to look like this:
array([0]=>name,age,phone). MikeF showed me the explode() and going from his example,

Quote

To get the column names from the snippet variable into an array try something like:
CODE
$cnames=explode( "," , $names );
I wasn't sure if there was supposed to be whitespace between any of the characters in the function parameters, I was sure I tried it without, but must have added some in at some time so I was using a variety of...
explode(" , " , $columns);
explode("," ,$columns);
explode( ", " ,$columns); I realised when I got an undefined parameter"" error that the encapsulations were to define the delimiter "," so I removed any whitespace there.
Don't worry, the snippet call variables were passing fine and OkeyDokey:) (no whitespace there)

#59 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 20 May 2007 - 04:04 AM

Why do you persist in representing your data as array([0]=>name,age,phone) rather than simply array('name','age','phone')...???

Anyway, if you pass the values in the snippet call, no, they shouldn't have whitespace in them to begin with... You would simply use $columnsArr = explode(",",$columns);, for example... This would convert the ?columns=one,two,three into:

$columnsArr(
[0]=>'one',
[1]=>'two',
[2]=>'three'
)


which can then be accessed using $columnsArr[0], etc...

But if you want to make those elements multi-dimensional you would need to take a different route... If you want to have something more like:

$columnsArr(
[0]=>array('name'=>'one','type'=>'varchar(100)'),
[1]=>array('name'=>'two','type'=>'varchar(100)'),
[2]=>array('name'=>'three','type'=>'varchar(100)')
)


You would need to do some manual wrestling with the data... You could loop through the results of the initial explode() to build the multi-dimensional array, for example, and push the values into the new array... One way of doing this would be to do something like:

foreach($columnsArr as $key=>$value)
{
$newArr[] = array('name'=>$value,'type'=>'varchar(100)');
}


OR

$count = count($columnsArr);
for($i=0; $i<$count; $i++)
{
$newArr[$i]['name'] = $value;
$newArr[$i]['type'] = "varchar(100)";
}


Anyway, I'm rambling... Not sure if any of this helps address the problem or not, but there you have it...

#60 Randy

    Likes Etomite Forums!

  • Member
  • PipPip
  • 309 posts

Posted 20 May 2007 - 04:27 AM

I don't understand the reason for a lot of this work, but why are you making it so hard on yourself. If you're going to hard code the data types anyway, why not just hard code them into the SQL statement and forget the arrays?

You'll undoubtedly remind me that you're only getting started... Soon enough you'll have Ralph rewriting PHPMySQLAdmin inside Eto as he assists you along the way. <_<

Hey...why don't you look at integrating part or all of PHPMySQLAdmin rather than eventually rewriting all its functionality. ;)

---
Eventually you'll get close to this...

http://phpmyadmin.svn.sourceforge.net/view...php?view=markup
---

Edited by Randy, 20 May 2007 - 04:38 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users