Page 1 of 1
Populating Table
Posted: Thu Aug 06, 2009 3:25 am
by zobi316
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.
Re: Populating Table
Posted: Thu Aug 06, 2009 4:11 am
by turbolemon
I think we need to straighten out your terminology here.
zobi316 wrote: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.
When you are "populating" the table, do you mean perform INSERT commands to add rows to a database table, or a SELECT command which generates a HTML table? There's a huge difference!
Also, if you are struggling, that gives the impression that you have had a go and should have some code. You should post that here too if you want help with your problem.
Re: Populating Table
Posted: Thu Aug 06, 2009 4:56 am
by zobi316
This is the search::
Code: Select all
<!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"> </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:
Code: Select all
<!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> </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> </p>
<p> </p>
</body>
</html>
Re: Populating Table
Posted: Thu Aug 06, 2009 5:08 am
by turbolemon
The first thing I have spotted is your query is malformed:
SELECT * FROM dbo.DesignControl WHERE Spec_Ref LIKE'$SpecRef%' (You need a space here)
It's easy to find out what's wrong with your SQL, using the provided error reporting functionality:
mssql_query($query) or die(mssql_get_last_message());
Re: Populating Table
Posted: Thu Aug 06, 2009 6:46 am
by Benjamin
Do not under any circumstances post 239 lines of code in the forums without using
Re: Populating Table
Posted: Thu Aug 06, 2009 7:02 am
by zobi316
I don't think its possible to populate tables when working working frames can't you. I'm using 6 frames which all of them consist iof tables. After clicking search, i want data in them tables to be displayed .