close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

recordset default to last record

Thread begun 4/16/2014 9:18 pm by Christopher West | Last modified 4/17/2014 8:20 am by Jason Byrnes | 1295 views | 5 replies |

Christopher WestCommunity Expert

recordset default to last record

Hello, I have a recordset which defaults to record 1 on first page load. However, how can I edit the below recordset so that it defaults to the last record in the database (the idea is so that the page will display the very latest blog entry and elsewhere on the same page a blog navigation so that why this recordset has a GET['BlogID'].

php:
$colname_rsBlog = "1";

if (isset($_GET['BlogID'])) {
  $colname_rsBlog = $_GET['BlogID'];
}
mysql_select_db($database_harropsdb, $harropsdb);
$query_rsBlog = sprintf("SELECT * FROM blog WHERE BlogID = %s", GetSQLValueString($colname_rsBlog, "int"));
$rsBlog = mysql_query($query_rsBlog, $harropsdb) or die(mysql_error());
$row_rsBlog = mysql_fetch_assoc($rsBlog);
$totalRows_rsBlog = mysql_num_rows($rsBlog);





Chris

Sign in to reply to this post

Jason ByrnesWebAssist

add an order by clause to order by the ID column in DESC order, that will cause the lat record in the table to be the first one returned:

ORDER BY BlogID DESC

the order by goes after the where clause.

Sign in to reply to this post

Christopher WestCommunity Expert

Hi Justin, I had already thought of that but it wont work.


here the adjust code with the ORDER BY that you suggested:

$colname_rsBlog = "-1";
if (isset($_GET['BlogID'])) {
$colname_rsBlog = $_GET['BlogID'];
}
mysql_select_db($database_harropsdb, $harropsdb);
$query_rsBlog = sprintf("SELECT * FROM blog WHERE BlogID = %s ORDER BY BlogID DESC", GetSQLValueString($colname_rsBlog, "int"));
$rsBlog = mysql_query($query_rsBlog, $harropsdb) or die(mysql_error());
$row_rsBlog = mysql_fetch_assoc($rsBlog);
$totalRows_rsBlog = mysql_num_rows($rsBlog);



The part I need to figure out it this code in the adove

$colname_rsBlog = "-1";



Since the -1 will return no records if there is not a URL variable being passed in I need to adjust the -1 so that it will return the last record in the database table. (obviously it works if I manually enter in the last record rather than using -1

when the user first goes to that page there would be no URL parameters (our-thoughts.php)

but on this page when the user selects from the right side navigation it will reenter this page with something like "our-thoughts.php?BlogID=15"

I hope this explains my situation further :)

The only way I can think of is to create some php code before creating the recordset and assigning a variable to the last record in the database using something like MAX

and then replacing the -1 in

$colname_rsBlog = "-1";

with something like

$colname_rsBlog = "MyVariableStoringLastRecord";



Chris

Sign in to reply to this post

Jason ByrnesWebAssist

Ok, I understand now.

you need to use advanced view to edit the recordset.

in advanced view the recordset will look like this:

SELECT * FROM blog WHERE BlogID = colname ORDER BY BlogID DESC

and in the variables section will be the colname variable as:

Name: colname
type: integer
Default Value: -1
runtime Value: $_GET['BlogID']


edit the recordset to:

SELECT * FROM blog WHERE (BlogID = colname) OR (colname2 = -1) ORDER BY BlogID DESC

and create another variable as:
Name: colname2
type: integer
Default Value: -1
runtime Value: $_GET['BlogID']

Sign in to reply to this post

Christopher WestCommunity Expert

Well that certainly did the trick! Thank you kindly Jason for fast response. You are a legend :)

and sorry earlier in my previous reply I called you Justin :-/
Chris

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome, and 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...