Jump to content


Newbie Coding Questions


110 replies to this topic

#1 Cris D.

    Loves Etomite Forums!

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

Posted 06 April 2007 - 02:54 PM

*** If your reading this thread, perhaps you are trying to get a grasp of PHP, SQL or etomite snippets or API's If you can't find the answer in the etomite documentation or in this thread...Try: PHP Tutorial or SQL en Tutorial and http://www.w3schools.com/ of course Ralph's own Tutorials.
Or failing that you can try My Etomite Blog where I have been documenting ideas that have helped me, snippet practices and tips.
Have fun snippeting:)***** added 26/4/07[/b]

3 questions:
1)I am using the getIntTableRows() API and want to retreive all data from the table (can do with the wildcard) but I also want to sort the data, but to use $sort I have to put a value in for the $where var. I can't use a wildcard here (i've tried) and don't want to limit any data. Is there a wildcard hack for this? or another easy dummy $where argument? I tried where="id=>0", this doesn't work. EDITED it's supposed to be...$where=" 'id' >=0" or even $where="id>=0" works.

2) There seems to be some inconsistency accross snippets with the use of "", '' and ``. I understand the application of the first 2, what is the use of the back ticks? Is this just etomite? (I can't find them referred to in the PHP docs). I know I read this in the formum somewhere, sorry Ralph but i can't re-find it :blush:

3) Is there an easy way to print or echo in a snippet that calls it in the "content" rather than at the top of the page without writing a chunk for one or 2 words?

Edited by Cris D., 06 May 2007 - 03:39 AM.


#2 Randy

    Likes Etomite Forums!

  • Member
  • PipPip
  • 309 posts

Posted 06 April 2007 - 03:31 PM

You've been working so hard at this! That makes it really easy to try to help you!

1) there must be more to this story as it should work fine. Can you echo out the $sql variable so I can see the actual SQL being sent to the DB engine?

2) Go here: http://us3.php.net/language.operators.execution

3) Not from a Snippet. The snippets must 'return()' a value in order for it to be placed into the 'content' of the page. If this is for troubleshooting, most of us probably put our 'echos' and print_r()s into the collection of output being returned by the snippet. $output .= "My test value is: ".$testValue; return $output;

#3 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 06 April 2007 - 04:26 PM

See the my tutorials for more information on how to use the API for custom data abstraction... You're close - you just need to send the arguments to the function calls in a more accurate manner and the tutorials cover that thoroughly, as well as how to format and display data...

#4 Cris D.

    Loves Etomite Forums!

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

Posted 07 April 2007 - 08:54 AM

Thanks Guys,
At the moment your site is down Ralph, will check out the tut's in detail in the future. I thought I had gone through them all but maybe I didn't understand the question the tutorials answered?! I'll have another look. Your section on formatting the data was great, I have been able to create a snippet & chunk combo that retuns all pictures in all galleries on the one page formatted the way I want (now I just need to sort them into a logical order, hence my question).

Randy, the sql query that returns an error (contains the dummy "where" argument) is:

/*SELECT id,gal_id,filename,descr,title,date FROM `cdeag1_eto`.etomite_etogal WHERE id=>0 ORDER BY ASC 1 ;*/

I tried to echo the working sql variable but it just returns "Array".

Edited by Cris D., 07 April 2007 - 08:58 AM.


#5 mikef

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,551 posts

Posted 07 April 2007 - 12:55 PM

View PostCris D., on Apr 7 2007, 09:54 AM, said:

/*SELECT id,gal_id,filename,descr,title,date FROM `cdeag1_eto`.etomite_etogal WHERE id=>0 ORDER BY ASC 1 ;*/
That doesn't look right to me, though I haven't actually checked the SQL syntax.

I'd try id>=0 (since => means something completely different in some other languages)
I'm not sure about the ORDER BY clause either; I'd expect something like 'ORDER BY id ASC' but other formats may be acceptable?

#6 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 07 April 2007 - 03:11 PM

In addition, use print_r() instead of echo as you are trying to display array contents, not string contents... Make php.net your best friend as it will answer many questions more quickly than asking them here... Each function will also point to related functions that you will eventually end up using...

#7 Randy

    Likes Etomite Forums!

  • Member
  • PipPip
  • 309 posts

Posted 07 April 2007 - 03:17 PM

View PostRandy, on Apr 6 2007, 10:31 AM, said:

1) there must be more to this story as it should work fine. Can you echo out the $sql variable so I can see the actual SQL being sent to the DB engine?

Hey,

OK. The problem is you're sending an empty string as the $sort column. The SQL query fails, not because of the lack of WHERE clause, but because of the lack of a column name after ORDER BY.

You can remove the WHERE clause as it is not necessary in order to sort the query results. Investigate why your $sort is empty and you'll likely find the problem.

See you,

#8 Cris D.

    Loves Etomite Forums!

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

Posted 08 April 2007 - 03:49 AM

OK Done: The Etomite API getIntTableRows() documentation lists the $where as "any optional WHERE clause". I thought that this meant that is could be removed. When it is removed, the API looks for the where clause and if it is missing, interprets the next field ($sort) as WHERE and ($dir) as ORDER BY.
so [ fields="", $from="table",$sort="id", $dir="ASC", $push=TRUE] is interpreted as...
[GET fields, FROM table, WHERE id ORDER BY ASC LIMIT=1 ].

Obviously, even though a field is "optional", in some cases it must be present if the API is to perform "as expected".
I also mistakenly thought that leaving off the limit clause would return "all", however the default is 1.

All working now: print_r() is a TOP TIP! Certainly saves the guesswork!

PHP now bookmarked, will be my first port of call before filling up this forum with silly stuff. Thanks.

Edited by Cris D., 08 April 2007 - 04:02 AM.


#9 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 08 April 2007 - 02:36 PM

One thing to remember, and an item which we will be addressing in the next release, is that all API functions must have all arguments, up to the last one changed, sent in the function call... That means that even if a value is optional, it must still be sent in the function call as is the case with most third party functions... If you were to look at a sampling of existing snippets, as well as the tutorials on my, you will see what I mean... I always send all arguments just to be safe...

#10 mikef

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,551 posts

Posted 08 April 2007 - 03:11 PM

Ralph, does your forms module easily allow for
1) picking data from multiple tables using a key from the first table
2) putting editted (or new) data back into the tables
assuming one row in each table for the common key.
(ie etogal table as 'master' with the id being used as key to an optional row in a second table)

If so I'll look at doing an EtoGalAdmin snippet to support an extension table.

#11 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 08 April 2007 - 03:42 PM

As it stands now the forms class is mainly geared towards creating XHTML compliant data entry forms, complete with Tigra Form Validation... Etomite itself has the getFormVars() function for extracting the submitted data which can then be tweaked or sent into a database table using either putIntTableRow() or updInttableRows()... The getIntTableRows() function should work with multiple tables as that was how it was originally coded...

#12 Cris D.

    Loves Etomite Forums!

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

Posted 16 April 2007 - 12:58 PM

Some more Noob Coding Questions...

1)I've made a simple radio button form that should just re-load when submitted (as there is nothing else in the snippet). When submitted on "1" redirects to my index.php,
when submitted on "2" redirects to 404. The form action is set to action="" and I have tried setting the url to the //http://mydomain.com/index.php?id=//$this->documentIdentifier;

However, even though the address is correct on mouse-over, it still does not re-load correctly.

Again, I have read about something like this recently but can not find it again.
(By the way, I have printed off all your documentation and am becoming very familiar with it).

2)Is there another list of API's for Etomite NOT in the Documentation somewhere? I know some are missing.

Edited by Cris D., 16 April 2007 - 01:05 PM.


#13 Dean

    Loves Etomite Forums!

  • Admin
  • 4,758 posts
  • Gender:Male

Posted 16 April 2007 - 01:11 PM

(2) No - no-one has documented (fully) the etomite API as far as I am aware.

#14 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 16 April 2007 - 01:16 PM

You're coming along Cris D...

1.) You should be using $etomite-> instead of $this-> which is for internal class use only...

2.) Open up the index.php parser file and you will see that all of the API functions are documented within the Etomite class itself... But note that some of the functions are intended to be private to the class itself so only try using those which are marked as being API functions...

#15 Cris D.

    Loves Etomite Forums!

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

Posted 17 April 2007 - 05:08 AM

I am working on this snippet and don't know if I am wasting my time. Is this a sound structure?
//get formfield['id']and formfield ['prefix'] from $form1

if(isset$_POST['prefix']) $form_prefix=$_POST['prefix'];

if ($form_prefix=="frm1_"){
return "form 1 submitted"
getIntTableRows() mergeCodeVars()
//display fields based on $form1[id]
return $output;

}elseif{
   ($form_prefix=="frm_2"){
return "form 2 sumbitted"
putIntTableRows();
}
}else{
return "no form submitted or error";
//otherwise prefix not set, show form.
return $etomite->getChunk($form1);
}

In context, I want to show $form1 (collect field['id']) and use this to set a field [id] to index data extraction from a table:
if id set...
extract and display the data using...getInTableRows & mergeCodeVars(),
then getChunk($form2)
else if
$form2 submitted,
getFormVars(), putIntTableRows (on submit $form2) and return to $form1.

Is this sound in theory or am I trying to do too much on the one page?

#16 Randy

    Likes Etomite Forums!

  • Member
  • PipPip
  • 309 posts

Posted 17 April 2007 - 05:34 AM

View PostCris D., on Apr 17 2007, 12:08 AM, said:

Is this sound in theory or am I trying to do too much on the one page?

Hi Chris,

Yes this looks fine. There are some coding errors you'll discover soon enough. (hint: count {} and make sure your php statements end with ; )

This is exactly what 'dynamic' content refers to in all those books out there. You've not over done it.

You're also likely to discover there are ten ways to skin the cat (sorry cat lovers), meaning many many ways to solve a single coding scenario. The one you've chosen is just fine.

Hope you're enjoying yourself :)

You're doin' great!

#17 Cris D.

    Loves Etomite Forums!

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

Posted 17 April 2007 - 12:43 PM

OK I thought that I had finished writing this snippet. It is the first time that I have tested one and there are NO ERRORS (yay), however, there is also no output.

I'm still new at this and would like to know how you go about systematically identifying problems with a snippet. Is there a standard procedure? I use Dreamweaver to write it so I can easily see problems with the code, however, it does not recognise etomite functions or API's(obviously). So what else is left to test these to identify preoblems? The snippet (as is) is posted in my blog here.

Any feedback or comments (constructive or otherwise) would be greatly appreciated.

#18 Randy

    Likes Etomite Forums!

  • Member
  • PipPip
  • 309 posts

Posted 17 April 2007 - 04:30 PM

Hi Chris,

Took a brief look and say this type of problem $var="this is some "special" text";

You Can't enclose doubles inside doubles.
--

When you start to get into more complex code scenarios you may want to google php ide. I use a full blown Integrated Development Environment (IDE) for complex coding. It not only provides highlighting, but it also checks syntax and comes with a debugger that will help identify logic problems.

I probably won't recommend one since these things are very personal choices and folks can be quite religious about their choices.

#19 Cris D.

    Loves Etomite Forums!

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

Posted 18 April 2007 - 07:16 AM

Thanks Randy, little things like that (can't have double quotes in double quotes) save me hours of trying to work out why it's not working.

I downloaded and have had a play with Eclipse. Looks like a big committment to configuring and learning it.

Don't reccommend an IDE, just tell me which one YOU use : )

#20 Randy

    Likes Etomite Forums!

  • Member
  • PipPip
  • 309 posts

Posted 18 April 2007 - 01:53 PM

Yes, Eclipse is a pain in the Arse and doesn't natively support PHP very well. The plug in is ok...but you're right. I don't like it.

View PostCris D., on Apr 18 2007, 02:16 AM, said:

Don't reccommend an IDE, just tell me which one YOU use : )

OK...That's fair I guess :)

I've used just about all of them and most have ups and downs. My current is phpEd ( http://www.nusphere.com/products/phped.htm ). Its expensive, but professionally it worth it. if you're a hobbiest it may not be worth the money to you.

I've also used one called EnginSite PHPEditor. An obscure company in Germany put together a fairly good editor and some GREAT suplementary tools. http://www.enginsite.com/ . I actually love this editor. It's very powerful. The problem is it tends to be finicky, tempremetal, and quirky. I over looked that for a long time because Sergey Lucka (the man) was very helpful fixing the product up.

Hope this is helpful.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users