Jump to content

[SOLVED] Bit of code i need help with..


wwfc_barmy_army

Recommended Posts

[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))
{
?>
      <?php
if ($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.
Link to comment
https://forums.phpfreaks.com/topic/31167-solved-bit-of-code-i-need-help-with/
Share on other sites

[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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.