cyberRobot Posted February 7, 2011 Share Posted February 7, 2011 Identify is a unique id Binding everything together. I'm not sure there's a need of it. It could be replaced by the regular ID column i think. HTML table: Identify | PC-name | Archive KHS000 | PC-Basement |10-01-2011 KHS001 | PC-entrance | 12-12-2010 etc.. (number 2 is not in the mysql, it was just a sample to give you a better idea). Picture: http://img191.imageshack.us/img191/4815/udklipn.png I took another look at your database structure. Does the data need to be stored like this? Seems like you're not utilizing the full power of databases. It would be a lot easier if each entry was stored in it's own row. For example, you could create a table like: id | pc-name | archived | notes 1 | PC-basement | 10-01-2011 | MD 2 | PC-entrance | 10-10-2010 | LF But maybe there's a reason for storing the data as it is now. Quote Link to comment https://forums.phpfreaks.com/topic/226368-php-mysql-while-loop/page/2/#findComment-1171133 Share on other sites More sharing options...
zero_ZX Posted February 7, 2011 Author Share Posted February 7, 2011 Hey @ your first post, Yes that's correct @ your second post, The reason I do not store the data like this, that it wont be possible to edit the table headers (id | pc-name | archived | notes). Else I would surely have done that, as it's way easier Quote Link to comment https://forums.phpfreaks.com/topic/226368-php-mysql-while-loop/page/2/#findComment-1171143 Share on other sites More sharing options...
cyberRobot Posted February 7, 2011 Share Posted February 7, 2011 The reason I do not store the data like this, that it wont be possible to edit the table headers (id | pc-name | archived | notes). Else I would surely have done that, as it's way easier I don't see why you can't have both. For example, you could still utilize your fields table by adding an extra column for the corresponding table header from the content table: id | name | content_columnName | order | active 1 | PC-name | name | 1 | 1 1 | Archived | archiveDate | 1 | 1 Of course you would need to figure out how to utilize the modified database structure. But I think things would be a lot easier. If you don't want to modify the structure, you could look into changing the second loop so that it saves everything to an associative array. For example, you could create an array like: $pcList['KHS000'][name] = 'PC-Basement'; $pcList['KHS000'][archived] = '10-01-2011'; $pcList['KHS001'][name] = 'PC-entrance'; $pcList['KHS001'][archived] = '12-12-2010'; Once everything is in the array, you would start another loop to display the array contents. Unfortunately, I don't have time to write any code, but I'll try to answer any questions you might have along the way. Quote Link to comment https://forums.phpfreaks.com/topic/226368-php-mysql-while-loop/page/2/#findComment-1171173 Share on other sites More sharing options...
zero_ZX Posted February 8, 2011 Author Share Posted February 8, 2011 Hi, The content column is displaying everything in the tables (except the KHS00), the field table is displaying all the table headers. I'm not sure how I can join the different tables without making it look like a mess :/ As for the array, It's a good idea, but it needs to generate it automatically, as I might end up with 100 rows, or even more. Quote Link to comment https://forums.phpfreaks.com/topic/226368-php-mysql-while-loop/page/2/#findComment-1171329 Share on other sites More sharing options...
cyberRobot Posted February 8, 2011 Share Posted February 8, 2011 As for the array, It's a good idea, but it needs to generate it automatically, as I might end up with 100 rows, or even more. You can dynamically generate the array, using the database information. For example if $identifyrow["value"] contains KHS000, you can replace: $pcList['KHS000'][name] = 'PC-Basement'; $pcList['KHS000'][archived] = '10-01-2011'; with: $pcList[$identifyrow["value"]][name] = 'PC-Basement'; $pcList[$identifyrow["value"]][archived] = '10-01-2011'; You would then replace the "name" and "archived" part with something like the field column in the content table. And replace the "PC-Basement" and "10-01-2011" part with the content column of the content table. $pcList[$identifyrow["value"]][$identifyrow["field"]] = $identifyrow["content"]; For more information on multidimensional arrays (and multidimensional associative arrays), this tutorial might be helpful: http://www.webcheatsheet.com/PHP/multidimensional_arrays.php Note that they provide an example of how to loop through this type of array to display it. Quote Link to comment https://forums.phpfreaks.com/topic/226368-php-mysql-while-loop/page/2/#findComment-1171405 Share on other sites More sharing options...
zero_ZX Posted February 8, 2011 Author Share Posted February 8, 2011 Yet again, when the user adds new table headers they will have to edit the php code.. is there no way to manually avoid this? Quote Link to comment https://forums.phpfreaks.com/topic/226368-php-mysql-while-loop/page/2/#findComment-1171416 Share on other sites More sharing options...
cyberRobot Posted February 8, 2011 Share Posted February 8, 2011 Yet again, when the user adds new table headers they will have to edit the php code.. is there no way to manually avoid this? I'm sure there is. Unfortunately, without getting more familiar with what you're trying to do, the database sturcture, and your PHP background I'm not sure how much more help I can be. If you have more specific question, I'll do my best to help. Quote Link to comment https://forums.phpfreaks.com/topic/226368-php-mysql-while-loop/page/2/#findComment-1171420 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.