close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

search returns same result each time

Thread begun 1/31/2010 1:14 pm by jeffmg279672 | Last modified 2/01/2010 2:31 pm by Jason Byrnes | 2445 views | 6 replies |

jeffmg279672

search returns same result each time

Firstly - apologies for this being a real newbie question/problem: been banging my head against this for so long I can't see what's what. I have two pages - one lists a group of artists pulled from a MySQL db table. That bit works fine. What I'm trying to do is have these click through to the appropriate detail in the db, but what's happening each time is that the same record (the first in the table) gets returned. The first page is pre-test.php and the code is as follows:

-------------------------
<?php require_once('Connections/album.php'); ?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_album, $album);
$query_rsListing = "SELECT * FROM albumlist";
$rsListing = mysql_query($query_rsListing, $album) or die(mysql_error());
$row_rsListing = mysql_fetch_assoc($rsListing);
$totalRows_rsListing = mysql_num_rows($rsListing);
$query_rsListing = "SELECT artist FROM albumlist";
$rsListing = mysql_query($query_rsListing, $album) or die(mysql_error());
$row_rsListing = mysql_fetch_assoc($rsListing);
$totalRows_rsListing = mysql_num_rows($rsListing);
?><?php
// RepeatSelectionCounter_1 Initialization
$RepeatSelectionCounter_1 = 0;
$RepeatSelectionCounterBasedLooping_1 = false;
$RepeatSelectionCounter_1_Iterations = "4";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Album Auction</title>
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>
</head>

<body>
<form action="test.php" name="albumselect" id="albumselect">
<table width="600" align="left" cellpadding="6">
<?php do { ?>
<tr>
<?php
// RepeatSelectionCounter_1 Begin Loop
$RepeatSelectionCounter_1_IterationsRemaining = $RepeatSelectionCounter_1_Iterations;
while($RepeatSelectionCounter_1_IterationsRemaining--){
if($RepeatSelectionCounterBasedLooping_1 || $row_rsListing){
?>
<td><div align="center"><a href="test.php" class="style1"><?php echo $row_rsListing['artist']; ?></a> </div></td>
<?php
} // RepeatSelectionCounter_1 Begin Alternate Content
else{
?>
<td>&nbsp;</td>
<?php } // RepeatSelectionCounter_1 End Alternate Content
if(!$RepeatSelectionCounterBasedLooping_1 && $RepeatSelectionCounter_1_IterationsRemaining != 0){
if(!$row_rsListing && $RepeatSelectionCounter_1_Iterations == -1){$RepeatSelectionCounter_1_IterationsRemaining = 0;}
$row_rsListing = mysql_fetch_assoc($rsListing);
}
$RepeatSelectionCounter_1++;
} // RepeatSelectionCounter_1 End Loop
?>
</tr>
<?php } while ($row_rsListing = mysql_fetch_assoc($rsListing)); ?>
</table>
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($rsListing);

mysql_free_result($rsListing);
?>

-------------------------

and the "results" page is called test.php and the code for this is as follows:

-------------------------
<?php require_once('Connections/album.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_album, $album);
$query_rsAlbums = "SELECT DISTINCT artist, title, `description`, signedby, certification, reserveprice, insurance, smallphoto, largephoto, mtTitle, mtKeywords, mtDescription FROM albumlist";
$rsAlbums = mysql_query($query_rsAlbums, $album) or die(mysql_error());
$row_rsAlbums = mysql_fetch_assoc($rsAlbums);
$totalRows_rsAlbums = mysql_num_rows($rsAlbums);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Record Auctions | <?php echo $row_rsAlbums['mtTitle']; ?> Fundraising Auction Prize To Use At Your Fundraising Event</title>
<meta name="description" content="<?php echo $row_rsAlbums['mtDescription']; ?>" />
<meta name="keywords" content="<?php echo $row_rsAlbums['mtKeywords']; ?>" />
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 12px;
}
.style4 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
.style6 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 14px; color: #FF0000; }
-->
</style>
</head>

<body>
<table width="100%">
<tr>
<td width="50%" rowspan="7"><a target="_blank"></a><a href="<?php echo $row_rsAlbums['largephoto']; ?>" target="_blank"><img src="<?php echo $row_rsAlbums['smallphoto']; ?>" border="0" /></a></td>
<td width="50%"><div align="center" class="style6"><?php echo $row_rsAlbums['artist']; ?></div></td>
</tr>
<tr>
<td><div align="center"><?php echo $row_rsAlbums['title']; ?></div></td>
</tr>
<tr>
<td><div align="center"><?php echo $row_rsAlbums['description']; ?></div></td>
</tr>
<tr>
<td><div align="center"><span class="style1">Personally signed by: </span><?php echo $row_rsAlbums['signedby']; ?></div></td>
</tr>
<tr>
<td><div align="center"><?php echo $row_rsAlbums['certification']; ?></div></td>
</tr>
<tr>
<td><div align="center"><?php echo $row_rsAlbums['reserveprice']; ?></div></td>
</tr>
<tr>
<td><div align="center"><?php echo $row_rsAlbums['insurance']; ?></div></td>
</tr>
<tr>
<td><div align="center" class="style4"><a href="<?php echo $row_rsAlbums['largephoto']; ?>" target="_blank">click to enlarge</a> </div></td>
<td><div align="center"></div></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsAlbums);
?>

-------------------------

It's probably glaringly obvious to anyone what I'm doing wrong here but for the life of me I can't see it. Any assistance appreciated... thanks in advance.
Jeff

Sign in to reply to this post

neilo

Hiya Jeff,

I'm a complete novice as far as PHP goes, so nothing is glaringly obvious to me. The easiest thing to have done would have been to use the DataAssist wizard to create your results and detail pages, then place the code in context in your own pages.

But from what I can see, the problem with your link in pre-test.php is that it isn't passing any session data through to the second page (test.php), it is only using the artist variable to link to the page.

You can pass this on (apparently) as a session variable in the URL:

<a href="test.php?artist=<?php echo $row_rsListing['artist']; ?>"><?php echo($row_rsListing['artist']); ?></a>


and to prevent the URL from being mangled (according to php.net and DataAssist pages), encode (rawurlencode) the URL, so:

<a href="test.php?artist=<?php echo(rawurlencode($row_rsListing['artist'])); ?>" ><?php echo($row_rsListing['artist']); ?></a>


would be your whole link in pre-test.php.

From here on I'm just comparing your second page with one of my DataAssist detail pages, and it seems as if your test.php page is all there apart from:

php:
<?php

if (!session_id()) session_start(); 
?>
<?php
$Paramartist_rsAlbums 
"-1";
if (isset(
$_GET['artist'])) {
  
$Paramartist_rsAlbums = (get_magic_quotes_gpc()) ? $_GET['artist'] : addslashes($_GET['artist']);
}
$ParamSessionartist_rsAlbums "-1";
if (isset(
$_SESSION['rs_Insert_listing'])) {
  
$ParamSessionartist_rsAlbums = (get_magic_quotes_gpc()) ? $_SESSION['rs_Insert_listing'] : addslashes($_SESSION['rs_Insert_listing']);
}
$Paramartist2_rsAlbums "-1";
if (isset(
$_GET['artist'])) {
  
$Paramartist2_rsAlbums = (get_magic_quotes_gpc()) ? $_GET['artist'] : addslashes($_GET['artist']);
}


Which - if my tootling round php.net wasn't a totally wasted journey - means that firstly it's checking for a session id and then creating (resuming?) a session, and assigning the parameters for it according to the variable passed from the previous page. That's what I have struggled to make of it, but I may be talking rubbish. Hopefully someone will explain why. I have just transposed your info into it.

So your second page in its entirety would look (I think) pretty much like the page that I've attached. I'm entirely lazy about learning this stuff. I meant to get down to serious learning, but as DataAssist just does it all my motivation disappeared, and there's so much other cooler stuff to play with.

Some of the above might make some sense, and you can try it, but I wouldn't hold my breath. The bright young things will be in soon, and will help out.

Sign in to reply to this post

jeffmg279672

search returns same result each time

Hi Neilo

thanks for the suggestions, going to check them out now and see what happens...

Jeff

Sign in to reply to this post

Jason ByrnesWebAssist

Jeff,

on the test.php you have not set the rsAlbums recordset to have a filter.


In Dreamweaver, double click the rsAlbums recordset. In simple view set the filtering options to filter the artist column
Select URL variable from the filter type and type in artist for the variable name.

Sign in to reply to this post

Jason ByrnesWebAssist

Neilo,

Since your code was generated by the data assist wizard, the detail page was alredy set to filter the recordset.

In data assist pages, the detail page will loaded in three conditions:
1) from a link on the Results page

2) After Inserting a record.

3) After updating a record.

The Querystring variables are used when going from the results page.

The session variables are created to hold the id of the updated or inserted record to filter the correct record after insert or update.


In Jeff's case, he only needs to filter the record based on the query string variable since the results page he is creating will not be loaded after insert or update.

Sign in to reply to this post

neilo

Jason,

Many thanks for taking the time to explain these things to me, I really appreciate it.

Sign in to reply to this post

Jason ByrnesWebAssist

No worries.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...