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
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;

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

 

<?

}

?>

 

 

 

 

Link to comment
Share on other sites

<!-- 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>

Link to comment
Share on other sites

	<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)){

Link to comment
Share on other sites

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.