Pjack125 Posted January 22, 2009 Share Posted January 22, 2009 I am having trouble with the following i have to dynamically create tables from the following SQL $Query1 = "SELECT * FROM STEPS"; that's the easy part i made it using a while loop... but the thing is this table contains 3 cells and in cell number one and three i need to run another query based on the result of the first one. SQL i have for that is $STEPNO = $row{'STEPNO'}; $Query2 = "SELECT IO.* FROM IO Where STEPNO = ".$STEPNO." And TYPE ='I';"; where STEPNO is taken form the first one so we would have ++++++++++++++++++++++++++++++++++++++++ + step 1 input 1 + step 1 + Output 1 + + step 1 input 2 + + Output 2 + ++++++++++++++++++++++++++++++++++++++++ Currently I have this but its not looping the second query as i thought it would please help $Query1 = "SELECT * FROM STEPS"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title></head> <body> <?php //fetch tha data from the database $result = mysql_query($Query1) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $STEPNO = $row{'STEPNO'}; $Query2 = "SELECT IO.* FROM IO Where STEPNO = ".$STEPNO." And TYPE ='I';"; $result2 = mysql_query($Query2) or die(mysql_error()); while ($row2 = mysql_fetch_array($result2)){$RunME = $row2{'INFO'}."<br>------------->";} echo "<table border='0' align='center' cellpadding='4' cellspacing='4'> <tr> <td width='108'><strong>inputs</strong><br>".$RunME."</td> <td width='200' align='center' bgcolor='#0099FF'>Step [".$row{'STEPNO'}."]<br>".$row{'DESCRIP'}."</td> <td width='101'><strong>outputs</strong>gg<img src='arrow.gif' width='162' height='7' /></td> </tr> </table>"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/ Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 That will only loop through the rows in $query1, have you check how many row are in their ? Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743456 Share on other sites More sharing options...
Pjack125 Posted January 22, 2009 Author Share Posted January 22, 2009 I just didn't want to draw more than one table in the diagram $query1 returns 3 rows. so that would create tree tables inside of table 1 there is two input and two output in table two there is only one out put in one input and in three there should be two input and one out put. the issue is here <?php "<table border='0' align='center' cellpadding='4' cellspacing='4'> <tr> <td width='108'><strong>inputs</strong><br>".$RunME."</td> <td width='200' align='center' bgcolor='#0099FF'>Step [".$row{'STEPNO'}."]<br>".$row{'DESCRIP'}."</td> <td width='101'><strong>outputs</strong>gg<img src='arrow.gif' width='162' height='7' /></td> </tr> </table>"; ?> where i currently have $RunME should really be running another while loop if that was possible but that only gives an error message. Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743467 Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 No it shouldn't, you can't run a loop through a variable, each loop is run separately. Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743470 Share on other sites More sharing options...
Pjack125 Posted January 22, 2009 Author Share Posted January 22, 2009 Is there a work around to that to where i get the lops to run separately? but somehow graphically organize it to show it the correct way? Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743485 Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 If you tell us exactly what you need to do then i will be able to advise you on how to do it. Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743486 Share on other sites More sharing options...
Pjack125 Posted January 22, 2009 Author Share Posted January 22, 2009 Here is where i am working on it http://www.pixelfxmedia.com/steps.php Its a flow chart with inputs and outputs on the side of each step. the steps are stored in a database so i need to first get all the steps in that database which i was able to do. After getting those steps I have to get the inputs and outputs for each step from another table and display the input on the left of the step and the outputs on the right. I am not able to upload graphics to the server so i hope this clears things up a bit. the closet image online i could find to link it to is this there maybe multiple input/output arrows on any given side Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743525 Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 So if i am getting it correct, you have a table with inputs? And one with outputs? Or are they both in one table, and you want to loop through each input and find the process and then the outputs for that process? Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743528 Share on other sites More sharing options...
Pjack125 Posted January 22, 2009 Author Share Posted January 22, 2009 all the processes are stored in one table all their input and output are stored in another table. the first action i am guessing is to get all the processes or steps. then after that the second thing would be to display the corresponding inputs and outputs to that each step. Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743544 Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 Yes the best way to this is to have one query which will get the process (use a while loop to loop through each process) then in the loop you will have two queries (or one joined query) to get the inputs and outputs, then use php to echo them or create an image using them Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743545 Share on other sites More sharing options...
Pjack125 Posted January 22, 2009 Author Share Posted January 22, 2009 GOT IT !! Thanks for talking trough it with me. $Query1 = "SELECT * FROM STEPS"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title></head> <body> <?php //fetch tha data from the database $result = mysql_query($Query1) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo "<table border='0' align='center' cellpadding='4' cellspacing='4'> <tr><td>"; $STEPNO = $row{'STEPNO'}; $Query2 = "SELECT IO.* FROM IO Where STEPNO = ".$STEPNO." And TYPE ='I';"; $result2 = mysql_query($Query2) or die(mysql_error()); while ($row2 = mysql_fetch_array($result2)){ echo $row2{'INFO'}."<br>-------------><br>";} echo "</td><td width='200' align='center' bgcolor='#0099FF'>Step [".$row{'STEPNO'}."]<br>".$row{'DESCRIP'}."</td><td>"; $Query2 = "SELECT IO.* FROM IO Where STEPNO = ".$STEPNO." And TYPE ='O';"; $result2 = mysql_query($Query2) or die(mysql_error()); while ($row2 = mysql_fetch_array($result2)){ echo $row2{'INFO'}."<br>-------------><br></td></table> <center><pre>| | | V</pre></center>";} } ?> Its so simple i can't believe i kept scratching my head over it lol Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743594 Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 No problem, you might want to look into some database tutorials to help get your head around some db stuff. Quote Link to comment https://forums.phpfreaks.com/topic/141988-solved-runing-a-query-inside-of-a-query-using-a-loop/#findComment-743599 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.