Forums

This topic is locked

2 Queries from 1 URL Parameter

Posted 04 Feb 2003 06:06:49
1
has voted
04 Feb 2003 06:06:49 Jeremy Cornelius posted:
I want to figure out to make 2 queries (from two different in the same database) based off one URL Paramter.

url = mydomain.com/detialpage.php?id=1

The table that is queried has a field - venueid.
Using venueid I need to create a new query to put that related tables information on the detail page.

I'm not sure how to do this. I can make the initial query no problem, but how should/can I make a new query at the same time based on what the first one returns.

Using DreamweaverMX, PHP and MySQL

thanks

Replies

Replied 04 Feb 2003 10:21:29
04 Feb 2003 10:21:29 Vince Baker replied:
assuming recordset 1 is called rs1 and the second is rs2:

Build rs1 as normal filtered by url.

You must have a common field between the rs1 and rs2 to filter the second recordset.

rs2:

SELECT *
FROM TABLENAME
WHERE YOUR_LINK_FIELD_NAME = 'varLINK'

add a variable in the recordset builder window with the following 3 values

Name: varLINK
Default Value: 1
Runtime value: rs1.fields.item("YOUR_LINK_FIELD_NAME".value

and there you go, rs2 filtered on the common field in rs1 and rs2

Regards
Vince

Response.write("The best line of code you can ever use"

VBScript | ASP | HTML | SQL | Oracle | Hosting
Replied 05 Feb 2003 06:31:08
05 Feb 2003 06:31:08 Jeremy Cornelius replied:
Vince,

Thanks for the tip, but it didn't work here is the error I got when I ran the page from my browser :

Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE or '$' in /web/celebrat/public_html/events/events3.php on line 14

Here is the code at the begining of the page:

<?php
$colname_RSShow = "1";
if (isset($HTTP_GET_VARS['showcode'])) {
$colname_RSShow = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['showcode'] : addslashes($HTTP_GET_VARS['showcode']);
}
mysql_select_db($database_celebrat_shows, $celebrat_shows);
$query_RSShow = sprintf("SELECT * FROM shows WHERE showcode = '%s'", $colname_RSShow);
$RSShow = mysql_query($query_RSShow, $celebrat_shows) or die(mysql_error());
$row_RSShow = mysql_fetch_assoc($RSShow);
$totalRows_RSShow = mysql_num_rows($RSShow);

$varLINK_RSVenue = "1";
if (isset(RSShow.fields.item("venueid".value )) {
$varLINK_RSVenue = (get_magic_quotes_gpc()) ? RSShow.fields.item("venueid".value : addslashes(RSShow.fields.item("venueid".value );
}
mysql_select_db($database_celebrat_shows, $celebrat_shows);
$query_RSVenue = sprintf("SELECT * FROM venues WHERE venueid = %s", $varLINK_RSVenue);
$RSVenue = mysql_query($query_RSVenue, $celebrat_shows) or die(mysql_error());
$row_RSVenue = mysql_fetch_assoc($RSVenue);
$totalRows_RSVenue = mysql_num_rows($RSVenue);
?>

Reply to this topic