Menu
hey everyone…
I have a database. It may contain several hundred individual items, in one or more subclass:
art-print-type/artist/item
so, for example, art-print-type=bird / artist = joeschmoe
What I want to do is use PHP to build the links.
On the main menu, the user selects bird prints. The PHP then:
opens the database, grabs the bird table, finds each unique subclass (artist), and builds a link – the link launches another query using the subclass (artist) as a WHERE clause.
If I pound my head on the table for an hour, I could probably come up with somthing exceptionally convoluted that might or might not work…
Help please?
John
[i]Originally posted by Daot Lagorille [/i]
[B]Hmmm... your question is a bit vague, but I think I get the gist of whast you are trying to do.
Essential it sounds like you want to create dynamic page content driven by choices the user makes.
So, the link "bird" could call the next page, with a url value of "class=bird" or something. That page has a query on the database as you mentioned, with the "where class='$varClass"".
You can then display all the artists from that query with a select dinstinctrow in the select part of the querey, and have each of those links go to a new page, passing the artist name as a new url variable "artist=$row['artist']", as well as the existing "class" variable.
That new page will take the two url varibales, and slap them into the query, and booyah, there is your content.
Is this what you mean? [/B][/QUOTE]
[i]Originally posted by Daot Lagorille [/i]
[B]Kind of - I am thinking now that you may have a database design issue.
This totally depends on the structure of your info, but why not have all records in one talbe, with an additional field of "class".
So instead of:
Table name birds with fields recordID, artist, and other_field
Table name other_class with same fields above
Have one table called "stuff" with these fields:
recordID, class, artist, other_field
the class feild will then contain an identifier analagous to the old class table names.
Now, you could create a simple search function on one page where the user fills out a form with select menus for "class" and "artist", and clicks submit.
That sends the info to a new page with a query that select from the one new table where class = user_input_class and artist = user_input_artist. [/B][/QUOTE]
[CODE]
Database
-----table birds
field item#, field artist, field description, (etc)
-----table portrait
field item#, field artist, field description, (etc)
[/CODE]
[CODE]
function make_fill_table($table_name) {
$sql = $sql = 'SELECT * '
. ' FROM '. $table_name
. ' WHERE subclass = "audubon"';
$result = mysql_query($sql);
if (!$result) {
print mysql_error() . "ERROR - query failed";
}
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
/* and etc... */
[/CODE]
[code=php]SELECT DISTINCTROW row_name FROM table_name WHERE blah blah blah...[/code]
[code=php]href="page02.php?class=birds"[/code]
[code=php]
$varClass = "unset";
if (isset($HTTP_GET_VARS['class'])) {
$varClass = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['class'] : addslashes($HTTP_GET_VARS['class']);
}[/code]
[code=php]sprintf("SELECT * FROM table_name WHERE class = '%s'"), $varClass;[/code]
[code=php]href="page03.php?class=birds&artist=<?php echo $row_ThingQuery['artist']; ?>"[/code]
[i]Originally posted by Daot Lagorille [/i]
[B]That would be:
[code=php]SELECT DISTINCTROW row_name FROM table_name WHERE blah blah blah...[/code]
Further to your other post, it is not so much relating two databases together, insofar as it would benefit you, I think, to redesign your database.
Because your two tables are identical except for containing differently classified information, it will become a lot easier to use if you put everything in one table that is exactly like the others, but contains one extra field itentifying the classification - i.e. the value of the field is either "portrait" or "birds".
That way, the link for birds on page 1 could be:
[code=php]href="page02.php?class=birds"[/code]
Page two has this variable:
[code=php]
$varClass = "unset";
if (isset($HTTP_GET_VARS['class'])) {
$varClass = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['class'] : addslashes($HTTP_GET_VARS['class']);
}[/code]
And a query like this:
[code=php]sprintf("SELECT * FROM table_name WHERE class = '%s'"), $varClass;[/code]
You then display these records with a do/while loop. Each record will have a link to page 3 that looks like this:
[code=php]href="page03.php?class=birds&artist=<?php echo $row_ThingQuery['artist']; ?>"[/code]
Then page three does the same as page two, but with the added artist variable... [/B][/QUOTE]
[CODE]
DATABASE
------- item# / Picture Type / Artist / Item Description / (etc)
[/CODE]
[code=php]
$varClass = "unset";
if (isset($HTTP_GET_VARS['class'])) {
$varClass = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['class'] : addslashes($HTTP_GET_VARS['class']);
}[/code]
[/QUOTE]
[code=php]sprintf("SELECT * FROM table_name WHERE class = '%s'"), $varClass;[/code]
[/QUOTE]
[code=php]
SELECT DISTINCT subclass
FROM ornith
[/code]
[CODE]
SELECT DISTINCT subclass
'
. ' FROM ' . $table_name
[/CODE]
[code=php]
$table_name='ornith';
$dbh=mysql_connect ("localhost", "xxxxx_joetest", "xxxxx") or die ('Cannot connect to Database - error: ' . mysql_error () );
mysql_select_db("xxxxx_joetest1",$dbh);
$sql = 'SELECT DISTINCT subclass
'
. ' FROM ' . $table_name ;
$result= mysql_query($sql);
echo "Query String= $result";
while($row=mysql_fetch_array($result)){
$content .=<<<END
<a href="http://jtest.stegenga.net/?table={$table_name}&subclass={$row}"></a>
END;
return $content;
echo "Content= $content";
}
[/code]
0.1.9 — BETA 5.18