Populating table

Discussion in 'PHP' started by majidk, Aug 6, 2009.

  1. #1
    Hi

    Im trying to populate a table via sql but struggling to how i can do it. i have search box, and when it is clicked i want the results going in the table.
     
    majidk, Aug 6, 2009 IP
  2. marshalprince

    marshalprince Peon

    Messages:
    435
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    where you are getting the trouble. Please send some more details so that we can undrstand the problem more precisely.
     
    marshalprince, Aug 6, 2009 IP
  3. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #3
    As of I understood, you have a search and you want to INSERT the results into a table?
    What code are you trying to use? And I wonder where the search results come from..?
     
    Sky AK47, Aug 6, 2009 IP
  4. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This is the search::

    <!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>
    <style type="text/css">
    <!--
    body,td,th {
    font-size: 10px;
    }
    -->
    </style>

    <?
    $myServer = '**;
    $myUser = '**';
    $myPass = '***';
    $myDB = '***';
    $SpecRef = $_GET['query'];
    print ("$SpecRef");



    //connection to the database
    $dbhandle = mssql_connect($myServer, $myUser, $myPass)
    or die("Couldn't connect to SQL Server on $myServer");



    //select a database to work with
    $selected = mssql_select_db($myDB, $dbhandle)
    or die("Couldn't open database $myDB");
    //error message (not found message)begins
    $XX = "No Matches Found";
    //query details table begins
    $query = ("SELECT * FROM dbo.DesignControl WHERE Spec_Ref LIKE'$SpecRef%' ");
    // $query = ("SELECT * FROM dbo.DesignProcess");

    //execute the SQL query and return records
    $result = mssql_query($query);

    $numRows = mssql_num_rows($result);

    //display the results


    while($row = mssql_fetch_array($result)){


    $Spec = $row["Spec_Ref"] . "\n";
    $PrePressDate = $row["Pre_Press_Date"] . "\n";
    $JobDescription = $row["Job_Description"] . "\n";
    $ReproHouseDesignAgency = $row["Repro_House_Design_Agency"] . "\n";
    $EndUserFamily = $row["End_User_Family"] . "\n";
    $XRef = $row["X_Ref"] . "\n";
    $CustRef= $row["Cust_Ref"] . "\n";
    }
    echo"<form action='Pre-presscopy.php' method='get'>";
    echo "Spec Ref <input type='text' name='query' id='query' size='40' value='$SpecRef' action='Pre-presscopy.php' columns='2' autocomplete='off' delay='1500' />";

    echo"<input type='submit' value='Search'>";
    echo"<input type='hidden' name='search' value='1'>";

    echo"</form>";


    echo "<form>";
    echo " Pre Press Date <input type='text' value = '$PrePressDate'>" ;
    echo " Job Description <input type='text' value = '$JobDescription'>" ;
    echo " Repro House Design Agency <input type='text' value = '$ReproHouseDesignAgency'>" ;
    echo " End User Family <input type='text' value = '$EndUserFamily'>" ;
    echo " X Ref<input type='text' value = '$XRef'>" ;
    echo " Cust Ref <input type='text' value = '$CustRef'>" ;
    echo "</form>";


    mssql_close($dbhandle);
    //display the results
    while($row = mssql_fetch_array($result))
    {
    echo "<li>" . $row["Spec_Ref"] . "</li>";
    }
    //close the connection
    mssql_close($dbhandle);

    //textareaContent = "";

    //while ($row = @mysql_fetch_array($query))
    //{
    //$var1=$row["Player"];
    //$var2=$row["Avg"];
    //$var3=$row["HR"];
    //$var4=$row["RBI"];

    $textareaContent .= "Spec Ref: $var1 Avg: $var2 HR: $var3 RBI $var4 <br/>";
    //}

    //if (!isset($var1) || $var1=="") {
    //echo $XX;
    //}

    // begin to show results set
    //echo "Results";
    $count = 1 + $s ;




    $count++ ;




    ?>
    <body>
    <form id="form1" name="form1" method="post" action="search.php">
    <label> </label>
    <span class="searchform">
    <td bgcolor="#FFFFCC">&nbsp;</td>
    </span>
    <label for="textfield2"></label>

    <label for="textfield3"></label>
    <form action="Search.php" method="POST">
    <label for="textfield7"></label>
    <div>
    </form>



    </p>
    <html>
    </body>
    </html>

    In this part, I have seven text boxes and a search. When I click search, the results are displayed in them text boxes. But how do i do it to the other table so that when i click search, the results are also displayed in them text boxes.

    This is the table i am working towards:

    <!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>
    <style type="text/css">
    <!--
    body,td,th {
    font-size: 9px;
    }
    -->
    </style></head>

    <body>
    <table border="1" cellspacing="0" cellpadding="0">
    <tr>
    <td width="70" valign="top"><p>Substrate</p></td>
    <td width="54" valign="top"><p>Film1</p></td>
    <td width="76" valign="top"><p>Lamination</p></td>
    </tr>
    <tr>
    <td width="70" valign="top"><p>Printed/plain</p></td>
    <td width="54" valign="top"><p>
    <input name="name_<? echo $row['Spec_Ref']; ?>" type="text" id="name_<? echo $row['X_Ref']; ?>" value="<? echo $row['X_Ref']; ?>" size="8" />
    </p></td>
    <td width="76" valign="top"><p>
    <input name="textfield" type="text" id="textfield" size="8" />
    </p></td>
    </tr>
    <tr>
    <td width="70" valign="top"><p>Film type</p></td>
    <td width="54" valign="top"><p>
    <input name="name_<? echo $row['Spec_Ref']; ?>" type="text" id="name_<? echo $row['X_Ref']; ?>" value="<? echo $row['X_Ref']; ?>" size="8" />
    </p></td>
    <td width="76" valign="top"><p>
    <input name="textfield3" type="text" id="textfield3" size="8" />
    </p></td>
    </tr>
    <tr>
    <td width="70" valign="top"><p>Gauge</p></td>
    <td width="54" valign="top"><p>
    <input name="name_<? echo $row['Spec_Ref']; ?>" type="text" id="name_<? echo $row['X_Ref']; ?>" value="<? echo $row['X_Ref']; ?>" size="8" />
    </p></td>
    <td width="76" valign="top"><p>
    <input name="textfield14" type="text" id="textfield14" size="8" />
    </p></td>
    </tr>
    <tr>
    <td width="70" valign="top"><p>Colour </p></td>
    <td width="54" valign="top"><p>
    <input name="name_<? echo $row['Spec_Ref']; ?>" type="text" id="name_<? echo $row['X_Ref']; ?>" value="<? echo $row['X_Ref']; ?>" size="8" />
    </p></td>
    <td width="76" valign="top"><p>
    <input name="textfield13" type="text" id="textfield13" size="8" />
    </p></td>
    </tr>
    <tr>
    <td width="70" valign="top"><p>Treatment/coating</p></td>
    <td width="54" valign="top"><p>
    <input name="name_<? echo $row['Spec_Ref']; ?>" type="text" id="name_<? echo $row['X_Ref']; ?>" value="<? echo $row['X_Ref']; ?>" size="8" />
    </p></td>
    <td width="76" valign="top"><p>
    <input name="textfield12" type="text" id="textfield12" size="8" />
    </p></td>
    </tr>
    <tr>
    <td width="70" valign="top"><p>Film width</p></td>
    <td width="54" valign="top"><p>
    <input name="name_<? echo $row['Spec_Ref']; ?>" type="text" id="name_<? echo $row['X_Ref']; ?>" value="<? echo $row['X_Ref']; ?>" size="8" />
    </p></td>
    <td width="76" valign="top"><p>
    <input name="textfield11" type="text" id="textfield11" size="8" />
    </p></td>
    </tr>
    <tr>
    <td width="70" valign="top"><p>Part number</p></td>
    <td width="54" valign="top"><p>
    <input name="textfield9" type="text" id="textfield9" size="8" />
    </p></td>
    <td width="76" valign="top"><p>
    <input name="textfield10" type="text" id="textfield10" size="8" />
    </p></td>
    </tr>
    <tr>
    <td colspan="3" valign="top"><p align="center"><strong>Print Work Centre</strong></p></td>
    </tr>
    <tr>
    <td colspan="3" valign="top"><p><strong>&nbsp;</strong>6E
    <input type="checkbox" name="checkbox3" id="checkbox3" />
    6F
    <input type="checkbox" name="checkbox" id="checkbox" />
    8A
    <input type="checkbox" name="checkbox2" id="checkbox2" />
    8B
    <input type="checkbox" name="checkbox4" id="checkbox4" />
    10
    <input type="checkbox" name="checkbox5" id="checkbox5" />
    NA/
    <input type="checkbox" name="checkbox6" id="checkbox6" />
    </p></td>
    </tr>
    </table>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </body>
    </html>
     
    majidk, Aug 6, 2009 IP
  5. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #5
    Put that between BBCODE code tags please. But why do you want to save the search results while they are already in a table...?
     
    Sky AK47, Aug 6, 2009 IP
  6. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I don't wish to save the results, i want them results to be displayed in that table. Im using frames to create these tables, so I don;t think you can can't you. I have 6 tables in total and have used 6 frames for them. When I click search, i want them 6 tables to be displayed with information.
     
    majidk, Aug 6, 2009 IP
  7. nomzz

    nomzz Well-Known Member

    Messages:
    475
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    110
    #7
    try to post your code here http://pastie.org/ in php format so ppl can see better format and can tell you how to format yor tables.
     
    nomzz, Aug 6, 2009 IP
  8. oop

    oop Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    or pastbin.org
     
    oop, Aug 7, 2009 IP