Jump to content

Linking two recordsets


jamjam

Recommended Posts

Hi

 

To better explain my problem and hopefully find a solution I have decide to explain the backstory.

 

I am building a database driven website with PHP and MySQL using Dreamweaver CS5.

 

One of the pages on site is called programme, and it access by query string like this

 

www.domain.com/programme/?id=10000000

 

Depending on the value of the query string, programme data is retrieved from the database and is displayed on the page. All this is working without any problems.

 

In addition to the main programme information, I also want to display related ‘programmes’ on the bottom of the page.

 

To achieve this I have created two ‘record sets’ in Dreamweaver.

 

The first recordset retrieves  the main programme and the second recordset will retrieves the related programmes.

 

These are the fields in the database.

 

Id, programme, episode, date, time

 

 

Recordset 1 : SQL

 

$programme_Programme = "-1";
if (isset($_GET['id'])) {
  $programme_Programme = $_GET['id'];
}
mysql_select_db($database_main, $main);
$query_Programme = sprintf("SELECT * FROM main WHERE id = %s", GetSQLValueString($programme_Programme, "int"));
$Programme = mysql_query($query_Programme, $main) or die(mysql_error());
$row_Programme = mysql_fetch_assoc($Programme);
$totalRows_Programme = mysql_num_rows($Programme);

 

 

I have had great difficulty in the SQL for the second recordsets.

 

I think the solution involves in taking $programme defined in first recodset  and using in the second recordset SQL somehow.

 

Something like

 

 

$related_Related = "-1";
if (isset($_GET['programme'])) {
  $related_Related = $_GET['programme'];
}
mysql_select_db($database_main, $main);
$query_Related = sprintf("SELECT * FROM main WHERE %s = programme", GetSQLValueString($related_Related, "text"));
$Related = mysql_query($query_Related, $main) or die(mysql_error());
$row_Related = mysql_fetch_assoc($Related);
$totalRows_Related = mysql_num_rows($Related);

 

But, this does work.

 

I know this is totally messed-up

So I would really appreciate if someone can let me know what I should be doing to get this to work.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/208627-linking-two-recordsets/
Share on other sites

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.