Jump to content

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


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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.