Jump to content

php - mysql while loop


zero_ZX

Recommended Posts

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.  :shrug:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  :shrug:

 

If you have more specific question, I'll do my best to help. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.