P
pablodelapena

  • Jul 30, 2008
  • Joined Mar 29, 2003
  • Hello,

    confusing title perhaps but what I am trying to do is this..

    I have an array which contains arrays which contains arrays which contain arrays...and so forth.

    These arrays are dynamically created so I don't always know whether the value of a key is a plain string or another array. example:

    $main_array = array(
    [key1] => "a string",   // a simple 
    [key2] => array('hello','world'), //this key contains a simple array
    [key3] => array(
       [another_key] =>'foo',
       [a_third_key]  => array(  'foo',   'bar' )
       )
    );
    

    So, $main_array is an array which contains three indexes, key1, key2 and key3 which contain values which could be another array etc.

    Now, essentially what I'd like to be able to do is to replicate the code above as a string which can be echo'd to the browser. However I also need $main_array to be useable by the script and keys to be preserved if possible.

    I've tried print_r() but that doesn't quite format things properly and had a bash at array_walk_recursive() to no real avail.

    I'm a bit stuck, so if anyone has any ideas as to how to do this (or indeed a better method of storing similar data*) then please, share

    Thanks in advance and I hope I've made sense.

    Pablo.

    *What I'm storing is a blog archive, the main keys are the years which contain an array of months which have posts and each month array contains all the relevant id's and titles of the blog.

    • If I use OR then it returns results with any of the keywords, not all of the keywords.

      As for the joins, I just need to get the data (such as name and tag) from the other tables in order to perform the search, if that makes any sense.

      • Hi all,

        I have 3 tables:

        File (FileID,name)
        Tags (TagId,Tag)
        files_tag(FileID,TagID)

        I'd like to be able to search File based on keyword tags. files_tag stores a relationship between the two tables. I'd like to return files if all keywords are matched.

        So.. if I have two files in File: (1,'a masterpiece')(2,'photograph')

        and two tags in Tags (1,'photography')(2,'illustration')

        And files_tag relationship are as follows: (1,1)(1,2)(2,1)
        (so 'masterpiece' has two tags and 'photograph' has just one)

        What would the query be to search for a file which contains both 'photo' and 'illustration', ie: return 'a masterpiece' only. ( but if i had searched for just 'photo' both files would have been returned)

        This is my SQL so far which isn't working properly (I'm sure the logic is off, but I'm not sure of the fix)

        SELECT
        	f.name,
        	t.Tag
        FROM files_tag_r AS ftr
        LEFT JOIN files AS f
        	ON ftr.FileID = f.FileID
        LEFT JOIN tags AS t
        	ON ftr.TagID = t.TagID
        
        WHERE
        
        t.Tag LIKE '%illustration%'
        AND t.Tag LIKE '%photo%'
        
        
        ORDER BY f.name
        

        Obviously if there is a different way to store the data then I'm open to suggestions!

        Thanks in advance.

        • Weedpacket;10878752 wrote:

          Why reinvent the wheel? See [man]tmpfile[/man].

          Brilliant Weedpacket, what I was looking for... I think.

          However, one flaw. This temporary file I am creating contains PHP code which I would like to be executed as PHP. ie: the class generates a PHP page using templates and then executes the created page.

          I can read the file and echo it back out no problem however I'd like to include() it if possible.

          Thanks again.

          • Hello,

            I am creating a class which creates a temporary file to write data into in __construct();

            After the script is finished I'd like __destruct() to delete the temporary file.

            However, I get a file not found error when the file is very clearly there. If I try and delete in the constructor it deletes fine though so I'm fairly certain it's not a path issue.

            Here is my code:

            <?php
            
            class myClass
            {
            
            	private $cache;
            	private $cachefile;
            
            	public function __construct($cachef)
            	{
            		//create an empty cache ready for writing
            		$this->cache = fopen($cachef, "w");
            
            		//declare cachefile for class
            		$this->cachefile = $cachef;
            	}
            
            	public function __destruct()
            	{
            		//close writing to file
            		fclose($this->cache);
            
            		//delete file
            		unlink($this->cachefile);
            	}
            
            }
            ?>
            

            Thanks in advance for any help.

            • Hello all.

              I have a simple login script which takes a username and password from a POST form compares it to a mysql table and if the result is 1 it authorises otherwise it tells them to go away.

              Strange thing is it only does this correctly if some output is sent to the browser first... but then it complains that output has been sent to browser on line X when i try to initiate a header ("Location") command.

              Here is my code

              
              <?php
              
              require_once('driver.php');
              session_start();
              
              $query = "SELECT ID,firstname FROM admins WHERE username='".$_POST['username']."' AND password='".md5($_POST['password'])."'";
              
              $SQL->query_db($query);
              
              $row = $SQL->fetch_row();
              
              //if I uncomment the following line the script executes correctly, otherwise it doesn't
              //echo "bakedbeans";
              
              if ($SQL->num_rows()!=1) {
              
              header("Location: ../?badLogin=1");
              exit();
              
              
              
              } else {
              
              //session details
              $_SESSION['SJadminName'] = $_POST['username'];
              $_SESSION['SJadminID'] = $row['ID'];
              $_SESSION['SJadminFN'] = $row['firstname'];
              
              //redirect to entrance
              
              header("Location: myaccount/");
              exit();
              
              
              
              
              
              }
              
              
              
              ?>
              
              

              for what it is worth Im using a .htaccess file te contents of which is as follows

              AddDefaultCharset ISO-8859-1

              RewriteEngine On

              ##Redirect for logging in
              RewriteRule login/$ login.php [L]

              ##Redirect for logging out
              RewriteRule logout/$ logout.php [L]

              RewriteRule login/myaccount/messagecenter/(.*)$ myaccount.php?section=messagecenter&startnum=$1 [L]

              RewriteRule login/myaccount/paymenthistory/(.*)$ myaccount.php?section=paymenthistory&startnum=$1 [L]

              RewriteRule login/myaccount/communications/(.*)$ myaccount.php?section=communications&ID=$1 [L]

              RewriteRule login/myaccount/$ myaccount.php? [L]
              RewriteRule login/myaccount/(.*)/$ myaccount.php?section=$1 [L]

              ]

              any ideas?

              • Ive ahd all sorts of problems setting this thing up and I think this is the last one related with Apache and PHP (I've not even attempted installing MySQL yet... pointers to good tutorials VERY much appreciated)

                However, I'm trying to enable the gd2 library. In the past I've simply uncommented the approriate .dll in php.ini - however I noticed this time it very clearly states WINDOWS. How do I go about enabling this module to work under a Mac OS X/Unix system?

                Thanks in advance,
                Pablo

                • Thanks alot, took a bit of snooping around but it works!

                  • hello,

                    i'm writing a page which uses the Rewriteengine to analyse directory structures.

                    i've just bought a sexy new mac and it comes with Apache and PHP installed be default.

                    However, after much problems getting PHP to work I've found another problem.

                    Apache doesn't seem to recognise the .htaccess file at all. No errors appear when I deliberatly mistype commands in the .htaccess file and it doesn't do any rewriting at all.

                    httpd.conf seems to be correct. I don't have much experiance in Apache but this line seems right, no?

                    # AccessFileName: The name of the file to look for in each directory

                    for access control information.


                    #
                    AccessFileName .htaccess

                    Can anyone help me please? thanks in advance and apologies if this is the wrong forum - I couldn't find an Apache forum.

                    • Hello there people!

                      I have just bought myself a brand spanking new iMac. It comes with Apache and PHP installed by default.

                      I have enabled PHP4 in Apache's httpd.conf file and it works well. If I load up a page with phpinfo(); it displays everything i need to know.

                      My problem is if I try and laod up any of my previous indeex pages it shows the following error:

                      Warning: Unknown(/Library/WebServer/Documents/index.php): failed to open stream: Permission denied in Unknown on line 0

                      Warning: (null)(): Failed opening '/Library/WebServer/Documents/index.php' for inclusion (include_path='.:/usr/lib/php') in Unknown on line 0

                      I've never come across an error like this. does anyone have any idea what this emans and how Ic an prevent it?

                      I've heard that Mac formats line breaks in a different way from Windows - could this be something to do with it? Files I've created on the Mac seem to work fine.

                      I appreciate any help and thank you in advance.

                      PS: on a side, far less simportant note, ehenever I try and access a url with just a folder (i.e: not putting index.php at the end) it gives me a foridden error... if anyone could help me out with this I'd appreciate it also!

                      • Hi there,

                        I'vfe created a user on my server named clientdropbox. as the name suggests this is a folder where clients can login and drop off files for use in their projects.

                        this all works hunky dory. They login they can uplaod and delete etc and my personal directory is completely offlimits.

                        However, the main body of the site (basicaly every directory apart from my mail folder) although unable to edit or upload anything they can downlaod and view files. Files such as driver.php which contains the mysql_connect() details aka username and password....

                        eeek.

                        How can i stop people from being able to go above the folder, ie out of the user clientdropbox file listing.

                        This is a huge security flaw which I need to sort out as you can imagine!

                        I'm imagining .htaccess is the answer, but if I'm wrong tell me....

                        Thanks in advance.

                        • its throwing this error after i use a DELETE query.

                          
                          $query = "DELETE FROM mailinglist WHERE email='".$_GET['email']."' AND code='".$_GET['code']."' LIMIT 1";
                          $SQL->query_db($query);
                          
                          if ($SQL->affected_rows()==1) { }
                          
                          • Im sorry. I didnt know where else to put this question.

                            Basically. I have a .htaccess file rewriting alot of my urls'. However, the RewriteBase is different on my remote server than it is on my local server.

                            Is there a way i can tell it that when its being accessed by the local server to set one base directory and when its on the remote server to use another base directory.

                            is there a way for it to distinguish between 127.0.0.1 and the ip address of my remote server?

                            Hope this made sense.

                            • I ahve the following code in a class called SQL to query the database:

                              
                              	//function to query database
                              	function query_db($the_query) {
                              
                              		  $this->query_id = @mysql_query($the_query);
                              		  	if (mysql_errno() > 0)
                              		  	{
                              				return false;
                              			}
                              
                              			return $this->query_id;
                              
                              	} // end query_db();
                              
                              
                              

                              This works perfectly well. I also ahve this code to see how many rows were returned

                              
                              	function num_rows() {
                              	       return mysql_num_rows($this->query_id);
                              	}
                              
                              

                              So why does this code not work?

                              
                              	function num_rows() {
                              	       return mysql_affected_rows($this->query_id);
                              	}
                              
                              

                              The following error appears:

                              Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\program files\easyphp1-8\www\projects\shmojo\v2\live\flash\php\files for subdomains\subdomain mailinglist\driver.php on line 43

                              any pointers appreciated!

                              • savj14 wrote:

                                <?php echo "".$LANG[17].""; echo $VAR[31] ? ' | '. $VAR[1] .'' : ''; ?>

                                That might work?

                                Otherwise look for the function called html_copyright_bottom() and edit that.

                                • You pay people to do this. Not ask on forum boards.

                                  have a great day!

                                  • Hi there.

                                    Im wondering if it is possible to use a .htaccess file to prevent users from viewing particular files or to show a different file if they type in the URL.

                                    As in, I don't have access to put files outside of the root folder and would quite like it if various config files were not accessible to view or download.. at all. However I would still want files within the system to be able toa ccess, modify and run these files whether they be PHP classes or CSV files etc.

                                    How owuld I do this if it is possible?

                                    Thanks in advance

                                    • Newcastle University (UK) organises a week long charity event where the students take part in various sponsored activities and generally try to raise money for a bundle of charities. It is known as RAG week (Raising and Giving) and we are aiming to make this the most successfull one to date.

                                      One of our charming friends has decided to sell himself on the website we all know and love. Ebay.

                                      Here's his link, help raise money for worthy causes!
                                      http://cgi.ebay.co.uk/Olly-Moore-9-year-old-male-for-sale_W0QQitemZ5662881102QQcategoryZ88433QQssPageNameZWDVWQQrdZ1QQcmdZViewItem

                                      Charities involved are:
                                      Cancer Research UK
                                      Make A Wish
                                      Percy Hedley Foundation
                                      S.C.A.N (aka Student Community Acton Newcastle)
                                      Evening Chronicle Sunshine Fund

                                      Come on, do your part and help us make this the Best RAG week ever!