Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

displaying a mysql select query on the same page

Status
Not open for further replies.

nichols

Technical User
May 24, 2001
92
GB
I am a newbie to php and mysql.

I have a Mysql database set up with categories.

I have a list of categories down the side of my page as shown below

category1
category2 table in centre of page
category3
etc


I want to be able to click on a link at the side of the page and this output the categories from my mysql database in tabular form in the main centre of the page in 5 columns.

I would also like those categories to be represented as a link to either the products in the category or subcategories or even both in two separate tables

I don't know if this is possible with php?

If anyone knows if this is possible could you point me in the right direction. My php text book is not as advanced as would like.

Cheers
Chris
 
In your category links, you'll need to include a value and then run a query off of that value to display the information.

Example:
Code:
<a href="categorypage.php?category=firstcatetgory">Category 1</a>
<a href="categorypage.php?category=secondcatetgory">Category 2</a>
<a href="categorypage.php?category=thirdcatetgory">Category 3</a>
.
.
.

Then you would check your database for the relevant category.
Code:
$qry="SELECT *from mytable WHERE category='" . $_GET['category'] . "'";
run the query to the DB. using mysql_query, and then output your results into the table.

something like:
Code:
$results=mysql_query($qry,...); [green]\\Run query[/green]
echo "<table><tr><td>field 1</td><rd>field2</td>...";[green]\\output table html[/green]

while($rowofdata=mysql_fetch_array($results){[green]\\cycle through query results[/green]
echo "<tr><td>" . $rowofdata['field1name'] . "</tr></td>" . $rowofdata['field2name'] . "</td>...";[green]\\output each row, with appropriate html table code.[/green]
}
echo "</table>"[green]//close table html.[/green]

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Cheers for that I will try this at home tonight after work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top