Open an HTML web-page by selecting a MySQL table row using php

I am a “seasoned” MS Access developer now managing web-sites as well; I have searched far and wide but can not find an exact [or near] match to my puzzle.

I have a MySQL database on a web-host that feeds table data into a php web-page; the page displays a table of x40 Groups in multiple columns per row. I also have a drop-down box filter that allows users to select rows based upon a column cell that lists the day of the week that each Group takes place. Now, to enhance it, I need to allow users to select a Group table row and have the html page open for that Group, either in place of the php page “_top”, or in a new tab “_blank” [no preference].

In .NET with SQLServer, I can have the table web-page open with a “Select” link on each row, and clicking that “Select” option opens the appropriate page based upon the content of a cell in that row. I need to do the same [or similar] in php.

Can this be done in php? If so, can anyone supply sample code or clues?

Many thanks in advance.
:confused: Dave B.

Sample data please :slight_smile: I’m also a little confused on your definition of “Group”. Do you mean a group of rows, or do you mean a “Group” that is a column within the table structure?

But just break the task down to it’s simplest form and then use PHP to fill in your variable. Where are you getting the group from? What is the url you will be forwarding them to?

Thanks for your prompt reply. Sorry for the confusion - the “Group” is a table column header and these are mutual-interest groups of people, as in Gardens Group, Social Group, Play Reading Group, etc. I need to put a row-selector in each row [perhaps even using the cell with Group name] that will open the web-page for that row. So click on the selector for the Gardens Group row and the URL …/…/Gardens.html would open.

How do I add a selector to each row in php and how can I have the appropriate page open?
Would the code be in a separate page or in the same php page?

Dave B.

You’ll need to pull up the area that produces the rows based on your recordset. You’ll see that the result is returned to an array and there will be a foreach loop to show all the records. Within that loop you’ll want to find a nice cozy place to put something along the lines of this :

echo '<a href = "../../' . $array['Group'] . '.html">' . $array['Group'] . '</a>';

While looping through it will use the current rows “Group” to populate your line.

Many thanks - I’ll have a play and let you know how I get on
Dave B.

If you get stuck, post the code you have (minus any database connections, we will assume you did that right ;)) and we’ll take a look at it.

Many thanks for the offer. I managed to make it work, even though I have an i loop for the rows not an array:
3 specimen columns including the one with the html link:
echo “<td bgcolor=‘#FFFFFF’>” . $i[‘Subject’] . “</td>”;
echo “<td bgcolor=‘#FFFF66’><a href = g” . $i[‘Group’] . “.html target=‘_blank’>” . $i[‘Group’] . “</a></td>”;
echo “<td bgcolor=‘#FFFFFF’>” . $i[‘Frequency’] . “</td>”;

NB The Group URL’s all start with a ‘g’ [for group (as opposed to t for tab, etc.)]

BUT, isn’t there always a ‘but’, it only works where the html URL name is identical to the Group column name, one word - no gaps, etc. Sooooooooooooo, I’ll have to add a column to the MySQL table that holds the URL name and hide it [width=zero] on the php page; then refer the href to the hidden URL column and not the Group name. All good.

What larks, eh Pip?

Thanks again
Dave B. :cool:

As an FYI, that is an array, your variable name is $i where K. Wolfe used $array as his variable name. So, same concept indeed.

Another FYI, you don’t have to output every column you select from MySQL, so you can return the column into your results, and then use it to build your link without making it an additional html column. Or you can use preg_replace() to strip out all invalid characters from the Group column name to build the URL (strip out spaces for example).

Might be a little soon to whip that one out :stuck_out_tongue:

Thanks for your help. I hadn’t read you latest, but found out about not outputting all columns by experimentation. Also, the Group URL name is sometimes not as straightforward as removing spaces, e.g. Walking Group 1 [and 2] is just gWalking.html. Anyhoo, I added a URL column to the source table [in MS Access] which exports to the MySQL table - used the URL code in the <a href…> section - did not display the URL column, and that’s all there is to it!!!
Being so pleased with the results, I added a table of Venues [where Groups meet] in the same php page and created the links to each Venue using the Venue Code in the <a href…> (So no need for an extra column this time!)
All works swimmingly and looks good too.
Many thanks again
Dave B.