We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10226
    • 412 Posts
    OK I have read this whole thread and I tried the example posted by awardle. I got past the unclosed comment error no prob. Do the tables always have to be manually created, or is there a way to check for and create new tables? I have some big plans for this but I need to see it working before I can start thinking smiley

    Thanks!
      • 33372
      • 1,611 Posts
      Quote from: fruitwerks at Dec 07, 2007, 01:14 PM

      OK I have read this whole thread and I tried the example posted by awardle. I got past the unclosed comment error no prob. Do the tables always have to be manually created, or is there a way to check for and create new tables? I have some big plans for this but I need to see it working before I can start thinking
      Anything that you can do in PHP you can do in these functions, and you can also make use of the MODx API as long as you start your function with global $modx;
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn't very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 10226
        • 412 Posts
        I understand you can use PHP and the API - that is a given. I have little experience with MySQL, so we can say this is my first project I will be getting my hands dirty in with it.

        For what I am wanting to do, I will need the ability to add fields from time to time. Once I get a feel for this I will be adding an image or two, dropdown selectors, ability to bind entries to form ’trees’. As usual when I start something new I miss something simple...

        Using the example by awardle, I created the table with phpmyadmin. I was then able to submit the form, but I don’t think it stuck in the db. I’m convinced I made the table wrong. I didn’t see anything about how to make the initial table or what values the fields they need.
          • 33372
          • 1,611 Posts
          Do you mean Awardle’s Venues Snippet? If it works for Awardle, I assume that it would work for you, too (although I haven’t really reviewed it). If you post your code and table info we can take a look at it and see what might be the problem.
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 10226
            • 412 Posts
            Yep - The venue script. I recreated the table and entries are going in, but I am unable to view them:

            « MODx Parse Error »
            MODx encountered the following error while attempting to parse the requested resource:
            « PHP Parse Error »
             
            PHP error debug
              Error: 	mysql_num_rows(): supplied argument is not a valid MySQL result resource	 
              Error type/ Nr.: 	Warning - 2	 
              File: 	/var/www/localhost/htdocs/fruitwerks.us/manager/includes/document.parser.class.inc.php(769) : eval()'d code	 
              Line: 	7	 
             
            Parser timing
              MySQL: 	0.0058 s	(6 Requests)
              PHP: 	0.0131 s	 
              Total: 	0.0189 s


            the code it borks on is [[show-venues]];

               $count = mysql_num_rows($result);


            here is the table info..

              	id  	int(11)  	  	No  	 	auto_increment  	  Browse distinct values   	  Change   	  Drop   	  Primary   	  Unique   	  Index   	 Fulltext
            	member_id 	varchar(255) 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
            	venue_name 	varchar(255) 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
            	venue_address 	varchar(255) 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
            	venue_postcode 	varchar(255) 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
            	venue_time 	varchar(255) 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext


            Primary is id - I have played with MySQL enough to insert, dump, drop and manage permissions, but I have never created a table myself.
              • 33372
              • 1,611 Posts
              Try echoing $sql (and commenting out the rest of the script) to see what your query looks like. It appears that $result is not a valid reference, which probably means that your query is not being properly created. You can use the MODx dbAPI for a lot of what’s in Awardle’s snippet, btw, which might make it a little bit simpler to modify for your needs.
                "Things are not what they appear to be; nor are they otherwise." - Buddha

                "Well, gee, Buddha - that wasn't very helpful..." - ZAP

                Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                • 10226
                • 412 Posts
                I made a new page with to call a snippet of;

                <?php
                
                $sql
                
                ?>


                it renders a normal template page with this error;

                Parse error: syntax error, unexpected $end in /var/www/localhost/htdocs/fruitwerks.us/manager/includes/document.parser.class.inc.php(769) : eval()'d code on line 5


                And I have looked at the DBAPI.. maybe I found an old page, but I will look again - and I’m not going to hack stuff up until I see this particular script functioning. I would rather break working code than try to figure non-working code!
                  • 33372
                  • 1,611 Posts
                  Er, no that won’t work. What I meant was to echo (or return) the value of $sql from the show venues snippet. So it’d be something like this:
                  <?php
                  $dbase = $modx->dbConfig['dbase'];
                     $table_prefix = $modx->dbConfig['table_prefix'];
                     $usernameid = $modx->getLoginUserID();
                     $sql = "SELECT *,modx_rsvp_venues.id as venue_id FROM $dbase.".$table_prefix."rsvp_venues,".$table_prefix."rsvp_events WHERE modx_rsvp_events.member_id = '" .$usernameid ."' AND modx_rsvp_venues.member_id = '" .$usernameid ."'  ORDER BY venue_order ASC";
                  
                  return $sql;
                  ?>
                  


                  That way you can see what’s causing the error.
                    "Things are not what they appear to be; nor are they otherwise." - Buddha

                    "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                    Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                    • 7231
                    • 4,205 Posts
                     $sql = "SELECT *,modx_rsvp_venues.id as venue_id FROM $dbase.".$table_prefix."rsvp_venues,".$table_prefix."rsvp_events WHERE modx_rsvp_events.member_id = '" .$usernameid ."' AND modx_rsvp_venues.member_id = '" .$usernameid ."'  ORDER BY venue_order ASC";
                    Make sure you have the query string built correctly, with all the " and ’ in the right places (some places have both ’" which could be easily overlooked). And as always don’t forget the ; at the end.

                    Error: mysql_num_rows(): supplied argument is not a valid MySQL result resource
                    This looks like the query failed.
                      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                      Something is happening here, but you don&#39;t know what it is.
                      Do you, Mr. Jones? - [bob dylan]
                      • 10226
                      • 412 Posts
                      Hmm well one thing I did think of last night is that my table prefix is fw_ for this site. The records are finding their way into the DB, but I don’t fully understand the query and I am fairly sure that is where all the troubles are.