SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: Id

  1. #1
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Id

    Query:

    I have 8 jokes in database, i delete joke no 1, i then add a new joke but new joke is assigned no 9. Those this mean that as long as i keep adding and deleting jokes the index will just grow and grow and isnt this a waste of space in my database.

    also if i only want a max of eight jokes in the database at a given time how would i go about doing this. I had thought to do something like

    if id ='8'; then

    but if the id no for first joke is 10 then the above will not have any effect.

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yer but mySQL (and other databases for that matter) will 'get around' to using those auto_increment values at some point later that were actually deleted records.

    You only have a few records though you'll notice what I mean once you've got a lot of data - i.e. thousands of records.

    Nothing to worry about really 8)

  3. #3
    SitePoint Addict sojomy's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Yer but mySQL (and other databases for that matter) will 'get around' to using those auto_increment values at some point later that were actually deleted records.
    Are you sure? It will re-use deleted auto-increment IDs? What if you're tracking orders and you delete an order? Won't you end up (some time in the future) with a NEW order with an already used Order Number? Isn't that bad. Real Bad?

  4. #4
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It will not reuse the deleted auto-increment id's but it will reuse the space that was left behind. One can actually see this after a while when you do a select statement (without 'ORDER BY') you will notice that some 'newer data' will apear 'earlier on' then you'd expect in the resultset. That's were a gap was filled.

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by choltas
    Query:
    also if i only want a max of eight jokes in the database at a given time how would i go about doing this. I had thought to do something like

    if id ='8'; then

    but if the id no for first joke is 10 then the above will not have any effect.
    Do you *really* only want to store a maximum of 8 jokes at any one time? How about having an unlimited amount of jokes, but only 8 that can have a status of 'live' at any one time? Anyway, to only have a max of 8 jokes at any time in your Db:

    1) Count the number of of existing joke records:
    "SELECT COUNT(*) from tbl_jokes_table"

    2) If the number returned is <= 8, add the record, otherwise, alert the user/do something else:
    PHP Code:
    if($count <= 8){
    // insert new joke record
    } else {
    // do not insert the new record
    // perhaps output warning msg


  6. #6
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    o.k. thanks for the replys now heres a question that has me puzzled

    the following returns a image from my database,
    <?
    $sql = "SELECT FileData
    FROM filestore WHERE ID = '30'";
    $result = @mysql_query($sql);
    if (!$result) die('Database error: ' . mysql_error());

    $file = mysql_fetch_array($result);
    if (!$file)
    die('File with given ID not found in database!');
    $filedata = $file['FileData'];

    echo($filedata);
    exit();

    <?
    but if i want to center the image and i do the following
    <?
    echo"<center>";
    echo($filedata);
    echo"</center>";
    ?>
    i dont get the image back just a load of binary data. Can anyone tell me why this is so.

  7. #7
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What excactly are you storing in 'filedata'? And a question the side... are you reading Kevin's book?

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  8. #8
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Zoef
    What excactly are you storing in 'filedata'? And a question the side... are you reading Kevin's book?

    Rik
    the code comes from chapter 11 of kevins book, and i am storing an image in filedata.
    what i did was uploaded an image to the database, and used the above code to retrieve the actual picture

  9. #9
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, most probably you're not sending the proper headers. So your data is being send as text, not as an image.

    Read Chapter11 pages 153 ->155 again.

    About centering the image, you can not do that this way.

    If you want to center the image I think (never done this) you have to put the url for the page with your above script in a html img tag on an other page. Something like this:
    Code:
    <center>
    <img src="image.php?id=10" />
    </center>
    Like I said I've never done this...

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •