Search found 519 matches

by Sindarin
Wed Jul 09, 2014 11:01 am
Forum: PHP - Code
Topic: Duplicate entries in foreach() loop
Replies: 5
Views: 1533

Re: Duplicate entries in foreach() loop

I don't really get the table structure above, do I need 3 tables to join? Will this save me an extra query to query once the products and once the product_platforms tables? I pretty much solved my issue with in_array, $os = explode(' ', $products_entry['os']); foreach($products_platforms as $entry) ...
by Sindarin
Wed Jul 09, 2014 10:39 am
Forum: PHP - Code
Topic: Duplicate entries in foreach() loop
Replies: 5
Views: 1533

Re: Duplicate entries in foreach() loop

In table products_platforms, it contains 2 rows "id" and "title", like
1, Windows
2, Mac OSX
3, Linux
ect.

In table products, column "os" accepts ids like if a product is compatible with Windows and Linux, it'd be "1 3"

Is there any better way to do this?
by Sindarin
Wed Jul 09, 2014 10:26 am
Forum: PHP - Code
Topic: Duplicate entries in foreach() loop
Replies: 5
Views: 1533

Duplicate entries in foreach() loop

So pretty much I have two arrays from the database, one for all the platforms that exist and one for all the products. I need to show all platforms in a <select multiple> and mark as selected any platform that existed in the entry. Field 'os' in table accepts the values space separated like "5 ...
by Sindarin
Wed May 30, 2012 7:24 pm
Forum: PHP - Code
Topic: Get results from database in an array
Replies: 2
Views: 603

Re: Get results from database in an array

Oh... it was that easy, it should make sense...yes. I did this, $array = array(); while ($row = $this->db_object->fetch_row($sql_result)) { for($i=0;$i<$this->db_object->get_fields($sql_result);$i++) { $array[$row[0]][$this->db_object->get_field_name($sql_result, $i)] = $row[$i]; } } $this->db_objec...
by Sindarin
Wed May 30, 2012 4:08 pm
Forum: PHP - Code
Topic: Get results from database in an array
Replies: 2
Views: 603

Get results from database in an array

I am trying to create a function to get all results from the database and store it in an array so I can do this: $news_entries = $news->get_all(); echo $news_entries[1]['title_en']; //shows the title_en of the entry with id=1 echo $news_entries[1]['content_en']; //shows the content_en of the entry w...
by Sindarin
Sat May 19, 2012 12:25 pm
Forum: PHP - Code
Topic: For loop with 2D array
Replies: 1
Views: 507

For loop with 2D array

I have an array, $application_languages = array('en' => 'English', 'el' => 'Greek'); and try to show those in a for loop, I need the 'en', 'el' etc. but will also need 'English', 'Greek' values... This code will cause errors, <?php for($i=0;$i<count($application_languages);$i++) { ?> <div class=&quo...
by Sindarin
Sun Apr 29, 2012 12:59 am
Forum: PHP - Code
Topic: How can I simplify this URL rewriting code?
Replies: 2
Views: 1980

How can I simplify this URL rewriting code?

So I've been trying to create proper URL rewriting managed by PHP and not in the htaccess. So far I have this code which works but I'd like to simplify it. What I mean this: /news/3/1/ would map to: /index.php?section=news& id=3 & page=1 But for example I'd like to make the order of the quer...
by Sindarin
Wed Apr 11, 2012 1:25 pm
Forum: PHP - Code
Topic: Register user account if not already exists?
Replies: 2
Views: 1122

Re: Register user account if not already exists?

Ah totally forgot about UNIQUE. Made username field unique and added a check when mysql error is 1062 (duplicate entry). That seems it works, thanks.
by Sindarin
Wed Apr 11, 2012 1:02 pm
Forum: PHP - Code
Topic: Register user account if not already exists?
Replies: 2
Views: 1122

Register user account if not already exists?

I am trying to create a function to register an account, but I need to check if the username does not exist already. Can I do it with one query? Tried this but doesn't work: function register($details) { $query_row = ""; foreach($details as $key => $value) { $query_row .= "`".$ke...
by Sindarin
Sun Mar 11, 2012 4:07 am
Forum: General Discussion
Topic: Best open source licensing for a personal framework
Replies: 3
Views: 3460

Best open source licensing for a personal framework

I am creating a php/js framework for personal use mostly, but as it's very practical, I am also considering using it in my workplace. Although I am concerned someone could just alter the files and declare it as "company property" and I will be bound not to use it for my own projects anymor...
by Sindarin
Fri Feb 17, 2012 5:55 pm
Forum: PHP - Security
Topic: Is constant defined enough protection for included files?
Replies: 1
Views: 4987

Is constant defined enough protection for included files?

I have several files that I include as the page body for a CMS e.g. dashboard.php products.list.php products.add.php products.edit.php Those are included through index.php using a switch. index php has the login check code and also defines a constant define('AllowAccess',1); My question is, is a che...
by Sindarin
Fri Feb 10, 2012 3:00 pm
Forum: PHP - Code
Topic: How to ORDERBY mySQL results
Replies: 5
Views: 1172

Re: How to ORDERBY mySQL results

I tried to do it but I got confused with arrays again. I added 3 functions in the blog.class public function beginListEntries(){ $this->sqlResult = $this->dbObject->query("SELECT * FROM `".$this->entriesTable."`"); } public function listEntries(){ return $this->row = $this->dbObj...
by Sindarin
Tue Jan 24, 2012 3:16 pm
Forum: PHP - Code
Topic: Array problem & sorting
Replies: 5
Views: 835

Re: Array problem & sorting

Ah now I see Greg, thanks a lot.

Think I will use:

Code: Select all

arsort($fileArray); 
since I believe this will be faster than sorting and reversing the array after.
by Sindarin
Mon Jan 23, 2012 9:52 pm
Forum: PHP - Code
Topic: Array problem & sorting
Replies: 5
Views: 835

Re: Array problem & sorting

Ahh you're correct, I had this sorting issue before and couldn't tell what it was causing it. Then I resorted to a database solution and never dealt with, however I now want to do it right. Also yeah, that one => arrow, thanks. EDIT: Okay, I verified it actually sorts them by filemtime and ascending...
by Sindarin
Mon Jan 23, 2012 10:40 am
Forum: PHP - Code
Topic: Array problem & sorting
Replies: 5
Views: 835

Array problem & sorting

I am trying to sort an array of files by filemtime(), I can echo the "file modified datetime" but not the filename . Am I doing something wrong? I suck at arrays for no apparent reason and the PHP docs are down :/ <?php $dirHandle = opendir('uploads/'); $fileArray = array(); while ($file =...