Forum Moderators: coopster

Message Too Old, No Replies

Tabular data displayed manually

         

LinusIT

11:03 am on May 6, 2011 (gmt 0)

10+ Year Member



Follow on from [webmasterworld.com ]

Currently I have a page that uses a while statement to populate a table based on the results from a query. It works but I would like more control over the page.

What I'd like to do is draw the full table in html and then use "Select * from prices" then manually call each row for the data in the cells. Simple idea sounds so complicated.

Table layout would be Column1 - Name, Column2 - Price. So it would look like:


<table>
<tr>
<td>Item 1</td>
<td><?php //php code to retrieve the price ?>
</tr>
<tr>
<td>Item 2</td>
<td><?php //php code to retrieve the price ?>
</tr>
</table>


The database table layout with be each item has it's own column, so item 1, item 2, item 3, item 4 etc. Then the first row will have the price for each item.

I hope I've explained this properly as the idea works in my head :) Any suggestions/ideas would be great.

Thanks

LinusIT

8:34 pm on May 8, 2011 (gmt 0)

10+ Year Member



I thought I'd have a go and I've got it working which is great. I've used:

$sql="SELECT * FROM pricelist";
$result = mysql_query($sql) or die(mysql_error());

and

<?php while($row=mysql_fetch_array($result)) { ?>
<table cellpadding="0" cellspacing="0" id="models">
<tr>
<td colspan="2" class="headings-border">Copper</td>
<td colspan="2" class="headings border-top border-right">Aluminium</td>
</tr>
<tr>
<td class="border-left">Item 1</td>
<td class="border-right"><?=$row['item1']?></td>
<td>Item 3</td>
<td class="border-right"><?=$row['item2']?></td>
</tr>
<tr>
<td class="border-left">Item 2</td>
<td class="border-right"><?=$row['item3']?></td>
<td>Item 4</td>
<td class="border-right"><?=$row['item4']?></td>
</tr>
</table>
<?php } ?>


My next task is being able to update the items prices, I've created the page with the input boxes which display the current price. My problem is that there are probably 50+ items meaning the update SQL is going to be massive.

Is there anyway around this using an array for the update query?

Note: The "name" of the inputs are the same as the column names in the database.