March 7, 201214 yr 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.
March 8, 201214 yr 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.
March 8, 201214 yr 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.
March 8, 201214 yr 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 March 8, 201214 yr by stjohn
March 9, 201214 yr 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 March 9, 201214 yr by Gibson
March 9, 201214 yr 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
March 22, 201214 yr 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 March 22, 201214 yr by stjohn
March 30, 201214 yr 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