Jump to content

[SOLVED] Basic: How to disaplay a SINGLE RECORD and then the NEXT AVAILABLE RECORD?


webmaster1

Recommended Posts

Hi All,

 

I know how to display records in a php page using a loop.

 

??? Firstly I'm stuck on the basics of trying to display a single record.

 

??? Secondly I'd like to set a condition whereby only the next available record is displayed as a single record.

 


<?php
//INCLUDE DB CONNECTION INFO
include("dbinfo.php");

//CONNECT TO DATABASE
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

//DEFINE QUERY
$query="SELECT * FROM tablename where masterdataid =1";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();

//DEFINE QUERY RESULTS AS VARIABLES
$masterdataid=mysql_result($result,$i,"masterdataid");

echo "Master Data ID: ";
echo $masterdataid;

?>

Actually scratch that. It looks like fetching the next available record using an auto_increment or datestamp field can get fairly messy.

 

I'll probably just partially display all the records and let the user enter the full record using GET.

 

 

The problem is that if you're working in a multi-user environment (more than one person accesses the page), there is no way you can guarantee the next id is gonna be the same thing you initially looked up.  Easiest 'workaround' is to go ahead and do a preemptive table insert as a placeholder, so that if someone else comes along they don't grab it.  Problem with that solution though is that if it turns out you don't need it, it's taking up unnecessary space.  You can turn around and delete it no problem, but then you're going to have ids that skip sequence a lot, which may or may not be an issue to you. 

 

IMO your best option is to sit down and really think about whether you need to know the next id in the first place, and try to work it so you don't.

 

 

Thanks for the advice Crayon. I've broken it down to what processes are actually required rather than how I think it should work.

 

I'm using 'get' variable (a list of partially displayed records, each with a link) and passing it through the next page via the url to view the record by itself and in full.

 

Cheers!

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.