mikebyrne Posted February 25, 2008 Share Posted February 25, 2008 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> Quote Link to comment Share on other sites More sharing options...
ucffool Posted February 25, 2008 Share Posted February 25, 2008 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; Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted February 25, 2008 Author Share Posted February 25, 2008 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! Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted February 25, 2008 Author Share Posted February 25, 2008 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 <? } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 You don't have a { in your loop while ($row = mysql_fetch_array($result)): // loop through and display Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 25, 2008 Share Posted February 25, 2008 <!-- 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> Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted February 25, 2008 Author Share Posted February 25, 2008 <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)){ Quote Link to comment Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 Means your query failed. Use mysql_error() to find out why Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted February 25, 2008 Author Share Posted February 25, 2008 What would the line of code be to produce the error report and where would i place it? Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted February 26, 2008 Author Share Posted February 26, 2008 Im still not to sure how to use that code revrez?? How do i get the error to report Quote Link to comment Share on other sites More sharing options...
revraz Posted February 26, 2008 Share Posted February 26, 2008 $result = mysql_query($query) or die (mysql_error()); Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted February 26, 2008 Author Share Posted February 26, 2008 I was getting the error Unknown column 'Dispay' in 'field list' so just corrected the Dispay to Display -------------------- Im getting the record 0 dispalyed in product number is there anyway I can remove this? Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted February 26, 2008 Author Share Posted February 26, 2008 If I wanted my php to just only show the products where the "Producttype" = Game what would the code be??? Quote Link to comment Share on other sites More sharing options...
revraz Posted February 26, 2008 Share Posted February 26, 2008 $query = "SELECT ProductNo,ProductName,Display,Price FROM Product WHERE Producttype = 'Game' "; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.