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:
But this displays all the fields in each cell, but doesnt add rows.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>
Anyone know how to add rows for each record?
Thanks very much for all your help
The general logic you want to use is:
Code:query(select * from table) <table> <thead> <td>title</td><td>subcat</td><td>price</td> </thead> while not at end of query <tr><td>$title</td><td>$subcat</td><td>$price</td></tr> end while </table>
If you're talking about storing variables in the uri, you can check them via the $_GET global.
$_GET['cat'] == 'Mixers';
etc..
This is not your answer but hopefully it points you in the correct direction.
he already has that working Dvelop. The only thing wrong with his code was as WP suggest he needed to lay it out how he wants it with HTML. ^_^
Thanks guys.
WingedPanther - you sorted me out there matey... here's the code which works:
Once again - thanks very much... this forum is greatCode:<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>
Glad we could help![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks