PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am hoping someone can help me with this. I have two loops, one with one. The while loop is not a problem works fine, gets the data form the DB and i can print each row. Although not all rows are used, there is a set varable '$numberof' which holds the number used. Therefore my logic come up with what i got below.
The problem is that allthough print ("$row[Item01]"); will work and print the 1st row, when i replace the 1 with the $i count my script does not want to display anything. It will print $i but anything i do does not seem to want to print the number of rows needed for each line, ect 3, 4, 6 or just 1 or 2, depending on what is set by $numberof.
while ($row = mysql_fetch_array($BillingData)){
for ($i=1; $i<=$NumberOf; $i++) {
print ("This is i : $i <br><br>");
print ("Row Data: $row[Item0$i]<br>");
}
} // End of while loop
Iam sorry dude but your use of qute marks within the arrray marker did not work at all.
Iam I not sure what your array code is trying to do.
Ok I try to explain again.
I have a DB with up to 20 fileds within it, Item01 to Item 20, but not all of them will be used, I have a count set, $numberof which holds the number of fileds used within each record set, e.g. 1, 3, 5 or 20. Alll I want to do is print Item01 to Item20 but only when they are used and not null.
GlennCurtis2009 wrote: not sure what your array code is trying to do.
The array represents data returned by a database query. The code loops through each row and, within each row, loops through the fields and displays the value.
GlennCurtis2009 wrote:I have a DB with up to 20 [fields] within it, Item01 to Item 20, but not all of them will be used
That indicates that the table structure is not normalized, as tasairis mentioned.
Assume you have a table like this one that holds numbers and multiple colors for each number.
+----+-------+--------+---------+----------+--------+
| id | name | color1 | color2 | color3 | color4 |
+----+-------+--------+---------+----------+--------+
| 1 | One | Red | | | |
| 2 | Two | Green | Greener | Greenest | |
| 3 | Three | Blue | Bluer | | |
+----+-------+--------+---------+----------+--------+
If your business rules state that each number should have four or fewer colors, this table might be acceptable. However, if adding another color requires the addition of another field, this is not the appropriate table structure. Fields do not expand, rows do.
To normalize the table, it needs to be split into two tables, one for each entity (number and color).