Jump to content

Recommended Posts

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>

 

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.

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

 

dt_ctip_asc2.gif

there maybe multiple input/output arrows on any given side

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?

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.

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.