Page 1 of 1

do/while multiple arguments

Posted: Thu Jul 11, 2002 11:48 am
by fariquzeli
I have a huge db of data drawing information from a form that is submitted. There is so much data that i made the form submit to 4 different mysql tables that are all within the same db. Now I know I have my connections correct, but what I want to have happen is have the rows of my html table repeat, while there is still data in the 4 mysql tables. I know that the rows in the mysql tables will all be identical, so that isn't a problem, the problem i'm having is in my do {repeat info goes here} and while {what is going to make the information repeat}

sometimes I can have one table of data shown, but then it just repeats the same entry for the other 4 entries, sometimes I can have no info from all but one table, this is what I have written for my wile statement right now:

Code: Select all

while ($row_general = mysql_fetch_assoc($general) & $row_curriculum = mysql_fetch_assoc($curriculum) & $row_products = mysql_fetch_assoc($products) & $row_miscellaneous = mysql_fetch_assoc($miscellaneous));
the 4 tables are general curriculum products and miscellaneous. That code won't work it has a table with 5 rows, 4 are blank and one has the info from the first row of mysql, can anyone help?

Posted: Thu Jul 11, 2002 12:39 pm
by llimllib
you want && not &. The former is the equivalent of AND in a mysql statement, while the latter is a bitwise and.
What a bitwise and does is it takes binary arguments and compares each bit. It makes:

Code: Select all

10110111 & 01100101 = 00100101
If both are true, the resulting bit is true, otherwise it is false.
Therefore, it seems that & is not what you want.

Posted: Thu Jul 11, 2002 12:46 pm
by RandomEngy
First, it's &&, not &. Secondly I take back my statement about using || in the other thread. What it would do is set the first array, find that it is true, then short-circuit out of the evaluation because it knows if one thing in an OR is true, the statement is true. That's why (I assume)

Code: Select all

mysql_query($query) or die(mysql_error());
works.

Try a table join to get all your information into one place:

Code: Select all

$result = mysql_query("SELECT table1.field table2.field FROM table1, table2 WHERE table1.id = table2.id");
Then go through the while() loop.

The id field here is the linking field, the one all of them have in common.

Good luck on the project.

Posted: Thu Jul 11, 2002 12:47 pm
by fariquzeli

Code: Select all

while ($row_general = mysql_fetch_assoc($general) && $row_curriculum = mysql_fetch_assoc($curriculum) && $row_products = mysql_fetch_assoc($products) && $row_miscellaneous = mysql_fetch_assoc($miscellaneous));
that is the code I have now. This is what the page looks like
http://www.youngdental.com/surveys/admin/all.php

still have blank cells below the first row.[/url]

Posted: Thu Jul 11, 2002 2:21 pm
by fariquzeli
table still doesn't show anything, only shows first row.

Posted: Thu Jul 11, 2002 2:30 pm
by llimllib
First off, you should probably be able to get all of those queries into one SQL statement with one (or a few) joins.IMHO, you should pursue this to make your code a lot cleaner.
Secondly, do a print_r on the values of all the rows immediately after the while loop. If any one of them returned false then your while loop would exit. In what state are the variables once you exit the loop?

Posted: Thu Jul 11, 2002 3:11 pm
by fariquzeli
I just gave up on it, made 4 different tables, each one with a do while statement rather than try to combine it all

when joining tables on querys:

if i join them all by one unique id, i can then use all of the table's info through queries?

i'm sort of a newbie and it lookd to me like you could get specific info from one field from each table by a join, but not an entire table's data from joining them by one unique id

Posted: Thu Jul 11, 2002 3:36 pm
by llimllib
I know you gave up on it, but let me try to explain why your loop was exiting after the first iteration. That last table you have (suggesstions/comments) only has one entry. So, after the first loop, PHP went to try and find the next row in all of your statements. For the loop to continue, they all had to be true (because they were connected with ANDs). Up until the last one, they were all true, but the last one returned false because there were no more rows to return. Therefore, the loop exited, its conditions not having been met.
As to the question that you're asking now, it's really too large for me to get into here, and it involves a lot of database design. Therefore, I recommend you get a book which teaches database design. I personally have found "Relational Database Design" by Jan L. Harrington to be an excellent book. If you read it, you'll never have another question about joins or how to structure tables - a Good Thing(tm).

Posted: Thu Jul 11, 2002 3:39 pm
by fariquzeli
Oh, I totally understand what you are saying now about why my rows wouldn't repeat.

I can't believe it was the one comments/suggestions column. I will look into that book, thanks a bunch you really helped me along alot.