wwfc_barmy_army Posted December 18, 2006 Share Posted December 18, 2006 [code=php:0]<?php include ("dbconnect.php"); $showid = $_GET["showid"]; $season = $_GET["season"]; if ($showid == ""&&$season == ""){ print ""; } else if ($season == "") { print "<div align=center><a href=index.php>Back to Show list</a></div><br/>"; } else { print "<div align=center><a href=index.php?showid=$showid>Back to Episode list</a></div><br/>"; } ?> <?php if ($showid == ""&&$season == ""){ $result = @mysql_query("SELECT * FROM shows ORDER BY name ASC"); while ($qry = mysql_fetch_array($result)){ print "<a href=index.php?showid=$qry[ID]>$qry[name]</a> <br/>"; } } ?> <?php if ($showid == ""&&$season == ""){ print ""; } else if ($season == "") { $result = @mysql_query("SELECT DISTINCT season FROM showquery ORDER BY season"); while ($qry = mysql_fetch_array($result)){ print "<a href=index.php?showid=$showid&season=$qry[season]>Season $qry[season]</a> <br/>"; } } else { print ""; } ?> <?php if ($showid ==""&&$season == ""){ } else { $result = @mysql_query("SELECT * FROM showquery WHERE season='$season' ORDER BY name ASC"); while ($qry = mysql_fetch_array($result)) { ?> <?phpif ($qry['link'] == ""){……………………………. Etc…………………………..[/code]Ok, the above is what code i have (well cut off half way as the rest isn’t important. It’s probably a bit messy code but i'm pretty new to php and it currently it works and as i learn more i will get better. But anyways:I have a number of tables in a database, ‘shows’ is one of them and includes the table name for each show and is first queried around half way down the first page to display all the records. This bit works fine. But we need it to have the table name taken from what ever show is currently selected (using the showid) and put it into the second and third queries which it has ‘showquery’ in red. I tried just doing ‘$qry[db]’ but just get an SQL error (‘db’ is the name of the field that has the table name in).How can we do this?Thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 Sorry to say but this stinks of poor database design. You need to find yourself some tutorials on database normalization. Each show having its own table is just rediculous. Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted December 18, 2006 Author Share Posted December 18, 2006 point taken. We'll get it changed. Quote Link to comment Share on other sites More sharing options...
thepip3r Posted December 18, 2006 Share Posted December 18, 2006 [quote]I have a number of tables in a database, ‘shows’ is one of them and includes the table name for each show and is first queried around half way down the first page to display all the records. This bit works fine. But we need it to have the table name taken from what ever show is currently selected (using the showid) and put it into the second and third queries which it has ‘showquery’ in red. I tried just doing ‘$qry[db]’ but just get an SQL error (‘db’ is the name of the field that has the table name in).[/quote]did you mean column names in your "shows" table?? if so, that's a completely seperate story. If you do have a different table for each show, you need to make ONE table for all possible shows and build columns around the identifying information that will distinguish one show from another without having identical information in different sections of your DB. This is very easily accomplished in one table by using an auto-incrementing field in that table. I usually call it <tablename>_id. Then you reference the element by ID and if any of the information changes, you don't have to restructure your SQL queries around it because it's always referenced by a non-changing identifier. Look at database normalization. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.