How to Display each record on a row of a table

back2black

Junior Member
Joined
Dec 20, 2008
Messages
118
Reaction score
29
Hi All,

I have a mysql table with three fields:

1) Category
2) Title
3) Sub Category
4) Price

Basically, I have a php page called categories.php with a table on it, and a URL field called cat

So to get there, for example you would go via:

categories.php?cat=Mixers
categories.php?cat=Headphone
categories.php?cat=Racks etc. etc....

On this page I want to display all the records in the category URL cat. So if for example someone came to the page from ?cat=Mixers I want to display all the records in the table where Category is Mixers.

So how would I actually do this?

So far I have this code:

Code:
      <table width="700" border="1">
        <tr>
          <td width="193">Title</td>
          <td width="397">Sub Category</td>
          <td width="88">Price</td>
        </tr>
        <tr>
          <td>
                <?php 
				$catresult=$_GET['cat'];
				$result = mysql_query("SELECT * FROM tbprofo WHERE category='$catresult'");
		
					while($row = mysql_fetch_array($result))
					  {
					  echo $row['title'];
					  }
       			?>
          </td>
          <td>
                <?php 
				$catresult=$_GET['cat'];
				$result = mysql_query("SELECT * FROM tbprofo WHERE category='$catresult'");
		
					while($row = mysql_fetch_array($result))
					  {
					  echo $row['sub'];
					  }
       			?>
          </td>
          <td>
                <?php 
				$catresult=$_GET['cat'];
				$result = mysql_query("SELECT * FROM tbprofo WHERE category='$catresult'");
		
					while($row = mysql_fetch_array($result))
					  {
					  echo $row['price'];
					  }
       			?>
          </td>
        </tr>
      </table>

But this displays all the fields in each cell, but doesnt add rows.

Anyone know how to add rows for each record?

Thanks very much for all your help
 
If i understand you correctly you are not asking about the actual retrevial of data from the database, but instead the display of the data once you have made the query.

What it sounds like you want to happen is for each result from the database to be given its own line in the display like :

ItemTitle1 ItemSubCat1 ItemPrice1
ItemTitle2 ItemSubCat2 ItemPrice2
ItemTitle3 ItemSubCat3 ItemPrice3

If this is what you are looking for try the following code:

Code:
<table width="700" border="1">
	<tr>
	  <td width="193">Title</td>
	  <td width="397">Sub Category</td>
	  <td width="88">Price</td>
	</tr>
	<?php 
	$catresult=$_GET['cat'];
	$result = mysql_query("SELECT * FROM tbprofo WHERE category='$catresult'");
	while($row = mysql_fetch_array($result)){
	?>
	<tr>
		<td><?=$row['title']?></td>
		<td><?=$row['sub']?></td>
		<td><?=$row['price']?></td>
	</tr>
	<?php
	}
	?>		
</table>
 
thanks drdankmendez - code works great
 
Back
Top