Jump to content

Autofill table from database


mikebyrne

Recommended Posts

I want my php code to autofill form my table as opposed to the fixed figures its using now

 

I want to display, ProductNo, ProductName, Display and Price

 

My SQL is:

 

CREATE TABLE `product` (
  `Producttype` varchar(4) collate latin1_general_ci default NULL,
  `ProductNo` decimal(7,0) NOT NULL default '0',
  `ProductName` varchar(30) collate latin1_general_ci default NULL,
  `Stockamount` decimal(5,0) default NULL,
  `Display` varchar(3) collate latin1_general_ci default NULL,
  `Description` varchar(10000) collate latin1_general_ci default NULL,
  `Price` decimal(6,2) default NULL,
  PRIMARY KEY  (`ProductNo`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 

My php is:

 

<!-- data content start -->
<div id="containerBg4">

	<!-- data start -->
	<div class="padTop11"><!-- --></div>

	<div class="clr"><!-- --></div>
	<div class="padTop1">
		<table width="850" border="0" cellspacing="0" cellpadding="0">
			<tr align="left">
				<td width="39"> </td>
			  <td width="31" align="center"><input name="ftd" type="radio" value="01" checked="checked"  /></td>
				<td width="100"><a class="black">3128385949</a></td>
				<td width="333">btrax ring 01</td>

				<td width="95" align="center">
<select name="position">
<option value="1" selected="selected">1</option>
<option value="2" >2</option>
<option value="3" >3</option>
<option value="4" >4</option>
<option value="5" >5</option>

<option value="6" >6</option>
<option value="7" >7</option>
<option value="8" >8</option>
<option value="9" >9</option>
<option value="10" >10</option>
</select>
				</td>

				<td width="46" align="center">show</td>
				<td width="66" align="right">$125.00</td>
				<td width="30"> </td>
				<td width="110"><a href="edit.php"><img src="../images/btn_edit.gif" alt="edit" width="73" height="23" border="0" /></a></td>
			</tr>
	  </table>
	</div>
	<div class="clr"><!-- --></div>

	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="dottedIn"><!-- --></div>
	<div class="clr"><!-- --></div>
	<!-- data finish -->

	<!-- data start -->
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop1">
	</div>
	<div class="clr"><!-- --></div>
	<div class="padTop11"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="dottedIn"><!-- --></div>
	<div class="clr"><!-- --></div>

	<!-- data finish -->

	<!-- btn start -->
	<div class="clr"><!-- --></div>
	<div class="padTop100"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="btn">
		<div id="btnL"><img src="../images/btn_update.gif" alt="update" width="73" height="23" /></div>
		<div id="btnSpace"><!-- --></div>
	</div>

	<div class="clr"><!-- --></div>
	<div class="padTop16"><!-- --></div>
	<div class="clr"><!-- --></div>
	<!-- btn finish -->


</div>
<div class="clr"><!-- --></div>
<!-- data content finish -->



<!-- data btm start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>
<div class="clr"><!-- --></div>
<!-- btm finish -->

</form>

 

Link to comment
https://forums.phpfreaks.com/topic/92926-autofill-table-from-database/
Share on other sites

So you basically want to:

$query = "SELECT ProductNo,ProductName,Dispay,Price FROM product";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)):
  echo "<td>" . $row[ProductNo] . "</td>";
  echo "<td>" . $row[ProductNName] . "</td>";
  echo "<td>" . $row[Display] . "</td>";
  echo "<td>" . $row[Price] . "</td>";
endwhile;

Yeah that looks like what im after but I've my table already predifined ie

 


<td width="100"><a href class="black">3128385949</a></td>
				<td width="333">btrax ring 01</td>

 

The 3128385949 refers to the ProductNo and "btrax ring 01" is the ProductName. Is it just a matter of replacing these with varible, if so how?

 

Thanks in advance for any help!

Im getting the error

 

 

Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\Admin_files\list.php on line 176

 

My code so far is:

 

	<!-- data start -->
	<table width="850" border="0" cellspacing="0" cellpadding="0">
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Dispay,Price FROM Product";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)):
// loop through and display
?>

<tr align="left">
<td width="33"> </td>
<td width="82"><a class="black"><?php echo $row['ProductNo'];?></a></td>
<td width="61"><?php echo $row['ProductName'];?></td>
<td width="61"><?php echo $row['Display'] ;?></td>
<td width="230"><?php echo $row['Price'];?></td>

</tr>

<?
}
?>

</table>

 

line 176 is the bracket in the loop

 

<?

}

?>

 

 

 

 

<!-- data start -->
	<table width="850" border="0" cellspacing="0" cellpadding="0">
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Dispay,Price FROM Product";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
// loop through and display
?>

<tr align="left">
<td width="33"> </td>
<td width="82"><a class="black"><?php echo $row['ProductNo'];?></a></td>
<td width="61"><?php echo $row['ProductName'];?></td>
<td width="61"><?php echo $row['Display'] ;?></td>
<td width="230"><?php echo $row['Price'];?></td>

</tr>

<?
}
?>

</table>

	<table width="850" border="0" cellspacing="0" cellpadding="0">
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Dispay,Price FROM Product";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)){
// loop through and display
?>

<tr align="left">
<td width="33"> </td>
<td width="82"><a class="black"><?php echo $row['ProductNo'];?></a></td>
<td width="61"><?php echo $row['ProductName'];?></td>
<td width="61"><?php echo $row['Display'] ;?></td>
<td width="230"><?php echo $row['Price'];?></td>

</tr>

<?
}
?>

</table>

 

 

This brings up:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Admin_files\list.php on line 162

 

Line 162 is: while ($row = mysql_fetch_array($result)){

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.