Stupid PHP

This was posted on Wednesday, July 25th, 2007 and is filed under Web dev. You can follow any responses to this entry through the RSS 2.0 feed. You are also welcome to trackback from your own site.

PHP IconOk so I know it’s not PHP’s fault but for the past 2 hours I’ve been working on a script and I’m getting nowhere. I’ve been working on this project for about 2 weeks now and this is the first real problem I’ve come across. I just can’t seem to get it right. Let me explain…

I have two tables - ‘modules’ and ‘user_modules’.

The ‘modules’ table basically consist of an ‘ID’ and ‘filename’ column. The ‘user_modules’ table consists of ‘ID’, ‘userID’, ‘moduleID’, ‘order’ and ‘location’.

The basic idea behind the script is to allow the user to select which modules he/she wants to display on a page and in what order. There are 3 possible locations for the modules which I am identifying with numbers 1, 2 and 3 in the ‘location’ column.

On my page I first have a query to the database which is pulling every row from the ‘user_modules’ table as well as those from the ‘modules’ table where ‘user_modules.moduleID’ equals ‘modules.ID’. I have then built this into an array with this structure.

$modules[location][filename]

Then in the three different locations (1, 2 and 3) I am using a foreach loop to loop through the $modules[location] array so I can get out all of its filenames. The files are then included one by one. The problem though is that in location 1 it works fine, in location 2 only the first file is being included and in location 3 none at all.

I cant quite get my head around it right now and its annoying me. If you have any suggestions as to what could be causing this let me know.

Ill keep trying…

4 comments

  1. Toby Says:

    I also have this same problem with PHP :P

  2. Michael Morgan Says:

    haha, sure you do :p

  3. Steve Hannah Says:

    I see this is an older post, so undoubtedly you’ve solved this one by now, but a couple of tips:
    1. print_r() to print the contents of your $modules array, so see what is actually getting loaded into the array.

    2. Post source code so that others can pin-point and learn from the problem you are having.

    Best regards

  4. Michael Morgan Says:

    Thanks for the reply but yes, I have already solved this problem. It was quite a while ago but if I remember correctly I had a function which was messing with the $modules array so once I cleared that up it worked like a charm.

Leave a reply

Bookmark on digg
Bookmark on del.icio.us
Archives
Related Posts
  • No related posts
Links
        RSS Feed