1989gta Posted February 28, 2008 Share Posted February 28, 2008 I've been doing manual reporting for some time now and would like to automate my table but i've hit a road block, i have two tables one that i manually alter(deletes) and a data pump (conversions) that i reference. Basically i run a look up find all the machines that should not have an app installed check the conversions table to make sure it's gone then update the deletes table with my findings but something is missing can you point me in the right direction? <? ////////////////////uninstalls ///////////////// if ($form_type == 'uninstalled'){ $current_date = date('m-d-y'); /////////////////1st query pulls all the workstations have installed but not uninstalled///////////////// $query = "select name,app from deletes where takeover = 'yes' and uninstalled <> 'yes'"; $result = mssql_query($query); while ($row = @mssql_fetch_row($result)) { ////////2nd query takes data and looks for uninstalled or not and outputs machines not uninstalled// $query1 = "select machine_name,package_name from conversions where date_current = '$current_date' and machine_name ='$row[0]' and package_name ='$row[1]'"; $result1 = mssql_query($query1); while ($row1 = @mssql_fetch_row($result1)) { ///////takes output and querys all machines that have the app but not that workstation////////////////// /////////////////////no workey/////////////////////////////////////////////////////////// $query2 = "select name,app from deletes where takeover='yes' and uninstalled <> 'yes' and name <> '$row1[0]' and app ='$row1[1]'"; $result2 = mysql_query($query2); while ($row2 = @mysql_fetch_row($result2)) { echo $row2[0]; echo "-\n"; echo $row2[1]."<br>"; /////////take output and update and update the unistalls///////////////////////////// $query3 = "update deletes set uninstalled ='yes' where name ='$row2[0]' and app ='$row2[1]'"; $result3 = mssql_query($query3); while ($row3 = @mssql_fetch_row($result2)) { echo $row3[0]; echo $row3[1]."<br>"; } } } } } ?> Quote Link to comment Share on other sites More sharing options...
stlewis Posted February 29, 2008 Share Posted February 29, 2008 Without seeing the error output that your code generates, its a little hard to make any really good suggestions, but I do have the following for you...First of all, save yourself some headache and convert all those mssql_fetch_row calls to mssql_fetch_array. That'll let you reference the fields in your database by name, rather than by number, ie: <?php while ($row = mssql_fetch_array($result){ $machine_name = $row['name']; $application = $row['app']; } ?> Not a big thing, but a huge help to aid clarity, and since PHP handles all arrays as hashes, you won't see a performance hit for using named keys rather than scalars. Next thing I could suggest, and unfortunately, I don't have the time to unknot the ball of yarn myself right now, but you should consider refactoring your code to eliminate some of the nested looping. Perhaps pull the data from your database in to an array, and then use for each to cycle all of the output of the first query through your next query, and so on? Again, not a huge improvement, but splitting things out like that might make it easier for you to see what's going on. Quote Link to comment Share on other sites More sharing options...
1989gta Posted March 10, 2008 Author Share Posted March 10, 2008 i have updated and simplified the page, in the if statement i can get it to work and display apps still installed but when i add an else or look for =='' it still displays nothing any ideas? thanks for looking ///////////////////uninstalls ///////////////// if ($form_type == 'uninstalled'){ $current_date = date('m-d-y'); /////////////////1st querys machines marked for delete but not uninstalled///////////////// $query = "select name,app from tbldeletes where takeover = 'yes' and uninstalled <> 'yes'"; $result = mssql_query($query); while ($row = @mssql_fetch_row($result)) { ////////2nd query takes data and looks in marimba for uninstalled or not and outputs machines not uninstalled// $query1 = "select machine_name,package_name from marimbaconversions where date_current = '$current_date' and machine_name ='$row[0]' and package_name ='$row[1]'"; $result1 = mssql_query($query1); while ($row1 = @mssql_fetch_row($result1)) { if ($row1 != ''){ echo "$row1[0]"; echo "-\n"; echo "$row1[1]"; echo "-\n"; echo "<b>still installed</b><br />"; }}}} Quote Link to comment Share on other sites More sharing options...
1989gta Posted March 12, 2008 Author Share Posted March 12, 2008 with the help of a friend i was able to get this working. here is the code if ($form_type == 'uninstalled'){ $current_date = date('m-d-y'); $query = "select name,app from deletes where takeover = 'yes' and uninstalled <> 'yes'"; $result = mssql_query($query); while ($row = @mssql_fetch_row($result)) { $query1 = "select machine_name,package_name from conversions where date_current = '$current_date' and machine_name ='$row[0]' and package_name ='$row[1]'"; $result1 = mssql_query($query1); if(mssql_num_rows($result1)>0){ //this is the line that solved the issue while ($row1 = @mssql_fetch_row($result1)) { echo "$row1[0]"; echo "-\n"; echo "$row1[1]"; echo "-\n"; echo "<b>still installed</b><br />"; } }else{ echo "$row[0]"; echo "-\n"; echo "$row[1]"; echo "-\n"; echo "<font color='red'>uninstalled</font> <br />"; }} } 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.