Jump to content

problems finishing page


1989gta

Recommended Posts

I am in the process of writing a page and I need a point in the right direction

Basically the page will resemble a spread sheet with 8 columns. I have all the queries worked out my code will look something like this (below) the information in column A will be used in every query through out the page.



echo "<table border=1>";

    echo "<tr>";
echo "<td>column_A</td>";
      echo "<td bgcolor=#f8f3df> column_B</td>";
      echo "<td bgcolor=#f8f3df> column_C</td>";
      echo "<td bgcolor=#f8f3df> column_D</td>";
      echo "<td bgcolor=#f8f3df> column_E</td>";
      echo "<td bgcolor=#f8f3df >column_F</td>";
      echo "<td bgcolor=#f8f3df> column_G</td>";
      echo "<td> column_H</td>";
    echo "</tr>";

/////column_A//////
$query = "";
$result = mssql_query ($query);

while($line = mssql_fetch_array($result)){
echo "<tr border=1>";
$app =$line[0];
  $install_date =$line[1];
  echo "<td>";
  echo $A);
echo "</td>";
}
////b////
$current_date = date('m-d-y');
$query = "";
      $result = mssql_query ($query);
                        while($line = mssql_fetch_array($result)){
    $todays_count = $line[0];

      echo "<td>";
        echo $B;
      echo "</td>";

}
and so on with the remaining 6 queries...


The problem I'm having is this seems to work fine when i have one piece of data echoed for column A all the query's run and echo what needs to, but when i have more that one piece of data it only echo's the last piece of data queried
so i need to change the page so when the query for column A and it finds more than one entry it takes that piece and runs the 7 query's and echoes the data and moves on the next and does the same thing.


I hope that i got my point acrossed

Thank you for viewing this post

Link to comment
https://forums.phpfreaks.com/topic/29865-problems-finishing-page/
Share on other sites

I think I get what you are saying so here is what you need to do.
[code]
$data=Array();

Now for each query something like this

query A
  $data['a']=Array();
while($line = mssql_fetch_array($result)){
    array_push($data['a'],$line);
}


query B
  $data['b']=Array();
while($line = mssql_fetch_array($result)){
    array_push($data['b'],$line);
}
[/code]
do this for each of your 7 - give you an array or arrays.

now
[code]
$j=strlen($data['a']);
for($i=0;$i<$j;$i++){

      echo "<tr>";
      echo "<td>" . $data['a'][$i] . "</td>";
      echo "<td bgcolor=#f8f3df>" . $data['b'][$i] . "</td>";
      echo "<td bgcolor=#f8f3df>" . $data['c'][$i] . "</td>";
      echo "<td bgcolor=#f8f3df>" . $data['d'][$i] . "</td>";
      echo "<td bgcolor=#f8f3df>" . $data['e'][$i] . "</td>";
      echo "<td bgcolor=#f8f3df >" . $data['f'][$i] . "</td>";
      echo "<td bgcolor=#f8f3df>" . $data['g'][$i] . "</td>";
      echo "<td> column_H</td>";
      echo "</tr>";
}
[/code]

Now obviously this is incomplete code, but will hopefully get you going in the right direction.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.