DeepakJ Posted July 30, 2007 Share Posted July 30, 2007 I spent like 10 hrs trying to fix this code. <?php $hostname = "localhost"; $username = "root"; $password = "98989lol"; $dbname = "licensinginformation"; mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname"); $selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname"); $query = "SELECT customerid FROM invoiceid"; $Result = mysql_query($query); echo "<html><head><title>AlibreCam Verification System</title></head>"; while($row = mysql_fetch_array($Result)){ $alpha = $row['customerid']; echo "<center><TABLE border=0 cellpadding=3><tr><td><center>Customer ID:</center></td> <td><center>".$alpha."</center></td></tr><tr><td><center>Invoice Number:</center></td> <td><center>"; $query2 = "SELECT invoicenum FROM invoiceid WHERE customerid='$alpha'"; $aResult = mysql_query($query2); while($row1=mysql_fetch_array($aResult)){ $invoicenum[]=$row1['invoicenum']; echo $row1['invoicenum']."</center></td></tr><tr><td><center>"; } echo "Product ID:</center></td> <td><center>"; $counter = 0; foreach($invoicenum as $num => $value){ $query3 = "SELECT * FROM productid WHERE invoicenum = '$value'"; $bResult = mysql_query($query3); while($row2=mysql_fetch_array($bResult)){ $pid = $row2['productid']; $counter = $counter++; echo $pid."</center></td></tr><tr><td></td><td><center>"; } } echo "Number of copies bought:</center></td> <td><center>"; $query3 = "SELECT * FROM invoiceid WHERE customerid = '$alpha'"; $cResult = mysql_query($query3); $numoflicenses=0; while($row3=mysql_fetch_array($cResult))( $numoflicenses = $numoflicenses + $row3['numoflicenses'] ); echo $numoflicenses."</center></td></tr><tr><td><center># of licenses remaining:</center></td> <td><center>".$counter."</center></td></tr></table><br>"; } ?> It is supposed to print out the data from the database onto a table. What happens though is that it complete skips the productid code and repeats the customerid info many times. I'm not sure how to fix this. Help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
jscix Posted July 30, 2007 Share Posted July 30, 2007 I'm not sure how your information is setup, but you may be able to make this a bit easier by fetching multiple requests at once, and printing them out together, you have a massive loop with multiple inbedded loops, this is bound to be confusing.. especially if you will need to go back at some point and modify your code. Generally the best answer is a simple one, try a new approach I think. http://www.samspublishing.com/articles/article.asp?p=377068&seqNum=9&rl=1 Quote Link to comment Share on other sites More sharing options...
DeepakJ Posted July 30, 2007 Author Share Posted July 30, 2007 I forgot to mention that customerid is NOT the key of the first table. The tables are divided into two. Productid which has productid and invoicenum as well as invoiceid which has customerid, invoicenum, numoflicenses. I am looking for a way to display ALL the information in the linked tables in an organzed fashion such as below(html code for form) <html><head><title>AlibreCam Verification System</title></head> <center><TABLE border=0 cellpadding=3> <tr> <td><center>Customer ID:</center></td> <td><center>customerid@xxxx.com</center></td> </tr> <tr> <td><center>Invoice Number:</center></td> <td><center>######</center></td> </tr> <tr> <td><center>Product ID:</center></td> <td><center>######</center></td> </tr> <tr> <td></td> <td><center>######</center></td> </tr> <tr> <td></td> <td><center>######</center></td> </tr> <tr> <td></td> <td><center>######</center></td> </tr> <tr> <td><center># of copies bought:</center></td> <td><center>######</center></td> </tr> <tr> <td><center># of licenses remaining:</center></td> <td><center>######</center></td> </tr> </table><br> </html> Quote Link to comment Share on other sites More sharing options...
DeepakJ Posted July 30, 2007 Author Share Posted July 30, 2007 Could you like give me a generally idea on how to structure the query relative to my project. This stuff is way over my head. Quote Link to comment Share on other sites More sharing options...
jscix Posted July 30, 2007 Share Posted July 30, 2007 http://databases.about.com/od/sql/l/aajoins3.htm http://www.udel.edu/evelyn/SQL-Class2/SQLClass2_SQL.html http://www.devx.com/tips/Tip/13075 These should give you a good understanding, Quote Link to comment Share on other sites More sharing options...
DeepakJ Posted July 30, 2007 Author Share Posted July 30, 2007 I'm still completely lost. Please help Quote Link to comment Share on other sites More sharing options...
DeepakJ Posted July 30, 2007 Author Share Posted July 30, 2007 Thanks for the help! Quote Link to comment 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.