Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Test if next 'page' is empty

Featured Replies

Hi all,

as the title describes, my setup in the database is not exactly the best, and as a result I have to work around a few problems. at the moment I am recalling products using a 'product_id'.

 

While i was inputting into the db, I was leaving gaps here and there between id ( 9 might jump to 11 and skip 10 for example) just so I could input an additional product if the client required. I know this isnt exactly good, or even ok practise, but I havnt gone through the whole ordering of db entries yet...

 

So now that I am trying to insert a previous and next option, of course i return errors for the empty pages.

 

So my question is is there a quick way to work with this? I was trying to test the id of the next page, to see if it was NULL, but i couldnt get it working. This was the code although if there is a more sensible way to achieve this I am all ears, bearing in mind that this is one of the last features to go in, and I dont want to rewrite alot of code, for now. :

 

<?php 
$test_id= 0;
$count = $product_id + 1;
if ( $count < 150){           //only this many products
	$test_set = mysql_query("SELECT * FROM products WHERE id='" . $count. "'")   //select everything from that db entry
	or die('Blah ' . mysql_error());
	while($test_row = mysql_fetch_array($test_set)){        
		$test_id=$row['id'];
	}
	if( ($test_id == NULL)){
		$count++; }
	else  
	{ $product_id = $count;}
}
?>

 

Many thanks.

  • Author

so i went through the database and arranged them sequentially, which all in all wasnt such hard task, its only tough when I i try to save entries of a certain ID to somewhere with the same ID...even if I change both at the same time.

 

I should add that I do have an ordering / position id, I just havnt got around to working out how to work with all of that info effectively.

so i went through the database and arranged them sequentially, which all in all wasnt such hard task, its only tough when I i try to save entries of a certain ID to somewhere with the same ID...even if I change both at the same time.

 

I should add that I do have an ordering / position id, I just havnt got around to working out how to work with all of that info effectively.

Why would you want a record to have the same ID as another anyway?

ID = Identification.

 

Your ID field has to be unique. I'd suggest you auto increment your ID field instead, so you don't face collisions in future.

  • Author

im sorry i dont think you got what i meant. they are unique. but when they are being recalled they are in a certain order. my problem is in ordering them

 

 

edit: or should i say my problem is in my ineptitude in programming php to order them :)

Edited by stjohn

I've noticed that some on here disagree with this but you've set your "WHERE id = ''" in the sql statement so that you have single quotes round the id, which is an integer. I find this throws an exception for me, for integer values, don't wrap them in quotes as they are not a string. Could be wrong about this, I'm not on my work machine to double check it.

 

It could be it considers it a bad statement and therefore you get the error.

 

When you say it returns an error, does it return "Blah " then the error, or just the error? If it's "Blah" then chances are that it's what I said above, otherwise if it doesn't then it could be soemthing to do with checking it has some rows before cycling through the rows (your "while" statement).

 

Also, check that $product_id and $count indeed do have values at this point, otherwise you end up with "WHERE id =" and then that's the end of the statement, which it'll consider a bad query and chucketh the dummy oot the pram.

Edited by Gibson

im sorry i dont think you got what i meant. they are unique. but when they are being recalled they are in a certain order. my problem is in ordering them

 

 

edit: or should i say my problem is in my ineptitude in programming php to order them :)

um if ur trying to order them you may try adding

 ORDER BY `id` DESC

with in ur query this should list ur data from the newest record to the oldest

  • 2 weeks later...
  • Author

um if ur trying to order them you may try adding

 ORDER BY `id` DESC

with in ur query this should list ur data from the newest record to the oldest

 

ah really helpful thanks.

I will have to back track a few steps then it seems, because as it is, I'm just jumping from id to id.. as per here (prev/next)

 

http://www.georgianwines.ie/product.php?id=0

 

so im guessing i will have to scan the dB and insert everything into an array and call it from there?? :)

Edited by stjohn

ah really helpful thanks.

I will have to back track a few steps then it seems, because as it is, I'm just jumping from id to id.. as per here (prev/next)

 

http://www.georgianwines.ie/product.php?id=0

 

so im guessing i will have to scan the dB and insert everything into an array and call it from there?? :)

 

 

just been look at the site and it seems if I go to

http://www.georgianwines.ie/product.php?id=233

for example. Errors everywhere not pretty to see maybe sort this out to users don't see this.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.