Random MySQL Entry

free web hosting
Free Web Hosting > Computers & Tech > Programming > Programming General > SQL (Structured Query Language)

Random MySQL Entry

amit
I am tring to figure this out and I can't. When you set a primary key. Say something_id and it is defined as a int (12) auto_inc. I go and fill it up with 10 entries, meaning it is now set to be something_id entry 10, but say I go and delete entry 5. Why doesn't it take that 5 for the next number, but instead it does a 11 and leaves 5 blank.

How might I get it to where it fill's up the 5 instead of going to the next number or is that just one of the bad thing's of having a sql entry auto_inc ?

Also, the random part. The reason I ask this is I take the total mysql entries

num_of_mysql($result) and then randomize it and pull a random number from that. Now, take the above and I do that it pull's a 5 out which blank and it doesn't see entry number 11, because there is really only a total of 10 table entries.

So, another question is. Would it be better just to read the something_id 3's into an array then pull a random something_id # out of the array? I am thinking about doing this, but don't want to because I am thinking it will be to slow for me. I guess maybe?

Sorry if you can't understand what I am tring to say. Maybe someone will understand and can help me out with what I am tring to figure out.

 

 

 


Reply

miCRoSCoPiC^eaRthLinG
Supposing you have two tables - one containing usernames and some other details and another table containing the user's address, telephone number etc.

In table A, your primary key is the auto incrementing field - incresing by 1 for every new user added to the database. This field is also the foreign key to the table B - which stores the addresses. thus using this autoinc field you can map an username to it's corresponding postal address in table B.

Supposing you deleted record 5 and the index now starts from 6. This affects only table A - what happens to all those records after 5 in table B ?? They get linked to some new username which appears at location 6 - totally corrupting the data. Table B has no way of knowing that a record has been removed from A and that it should adjust it's own index values accordingly. This is why once the count reaches a certain number it stays there and doesn't go back to the last deleted index - no matter how many records you delete from in between.

This gives rise to another problem though.. All of a sudden you have a whole bunch of orphaned records in table B - addresses for which the original username have been removed from table A.. what do you do with these ?? Under these circumstances - you either delete the records with same index from both tables - or fill up the records with blanks in both. Either approach works.

As for your case - you can still pick a random value from num_of_mysql($result) - except that once you read that record - check whether the first field is blank or not. If blank, generate another random value and repeat the above step, till you reach a record that's not blank. This is a better approach than reading the whole thing into an array and running the random routine on it.

Regards,
m^e

 

 

 


Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. fill mysql - 80.93 hr back. (1)
  2. php insert random data at mysql - 83.14 hr back. (1)
  3. insert random numbers mysql - 83.15 hr back. (1)
  4. display random entry from table mysql - 88.13 hr back. (1)
  5. mysql return total entry - 90.85 hr back. (1)
  6. mysql php random entry - 92.12 hr back. (1)
  7. mysql random primary key - 99.05 hr back. (1)
  8. mysql insert "random number" - 100.16 hr back. (1)
  9. pick one recent entry in mysql - 102.23 hr back. (1)
  10. add random data in mysql table - 102.43 hr back. (1)
  11. randon mysql - 104.40 hr back. (1)
  12. how to get a random number in mysql - 124.73 hr back. (1)
  13. mysql random - 126.20 hr back. (1)
  14. pick random mysql entry php - 129.70 hr back. (1)
Similar Topics

Keywords : random, mysql, entry

  1. Mysql Overhead
    (3)
  2. What You Need Before You Can Create A Text-based Game..
    Using PHP, HTML and MySQL (7)
    Please comment and rate, after you finished reading! /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
    ################################################################# Change log: Aug 22 2008: The
    Tutorial Was Created. V1.0.0 Aug 30 2008: Added XHTML and a small CSS part. Also corrected some
    small things and added this change log. V2.0.0
    ################################################################# OK.. Many people here want to
    create text based games. Many of you ask us here on the forums: "how to create a text-based ....
  3. Mysql Multiple Tables
    (1)
    It is good practice to use multiple tables to sort out big amounts of data. But once you do that it
    becomes increasingly hard to cross reference the tables. Mysql has a little beautiful command
    structure that they have added. You can select multiple tables within one sql query. Example of a
    basic sql query CODE $sql = "SELECT * FROM table WHERE row=1"; If you noticed
    that I selected all of the rows in the table. Normally you will try to not select the entire table
    from the database unless you absolutely want all of the table. I would recommend against....
  4. Any Website Provide Free Host Mysql Host?
    (4)
    any website provide free host mysql host? i need it because i am using 000webhost.com now but it
    only provide 2 mysql database... can i know where or how can i get more databases regards....
  5. How To: Display A Members/user List.
    With PHP, Mysql, and HTML. (3)
    Alright, some of you might want to display your User's or Members on your site. Notes: 1.This
    is to fit in with Feelay's register and Log-in scripts you can find in the tutorial section. 2.I
    made this to show the members of my site who is a member and what their ID is. First off, we must
    set up a connection to our MySQL Database. CODE <?php $con =
    mysql_connect("localhost","database_username","database_username_password
    4;); if (!$con)   {   die('Could not connect: ' .
    mysql_error(....
  6. Php Random Selector
    whats the code (2)
    Is there a PHP script that randomly selects a string from a list? example, the list is: 1-Pie
    2-Balls 3-eggs The script would view a random
    word from those 3 every time i run it. Also is there a function that gives a random number between
    0 and a number i select?....
  7. Mysql On Computer
    XD (9)
    I posted PHP on computer? , but for some reason it doesn't show :/. Anyways I am wondering if
    there is MYSQL on my computer, meaning can i make a data base on my computer? that way i make what i
    want and upload it when i get hosted =)....
  8. Can You Link Game Maker With Mysql/php
    Title says it :D (0)
    Hello, I am new to this service and i think I am going to like it =). Anyway, my main question is
    can you link executable games made by gamemaker (i have pro) to a database? And can i use the php
    server i get here to transfer data to that game? If so i would appreciate a little help with it
    because I am new to both =). Also is there anyway to get a www.mywebsite.com via credits from
    astahost? Finally is there any group here that works with gamemaker? we might have small contests
    or so /tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /....
  9. Mysql Database Entry By Excel Sheets
    (2)
    Hello .. I would like to ask if i can use use Microsoft excel files in order to make entries to
    mysql database. Thanks....
  10. Mysql Database Management
    (1)
    Hi i am new, I have a problem in understanding the query decomposition in D-DB. Can anyone help me
    to understand the first question of the exercise 25.21 of Elmasri-Navath 4th edition? Consider the
    following relations: BOOKS (Book#, Primary_author, Topic, Total_stock, $price) BOOKSTORE
    (Store#, City, State, Zip, Inventory_value) STOCK (Store#, Book#, Qty) Consider a distributed
    database for a bookstore chain called National Books with 3 sites called EAST, MIDDLE, and WEST.
    Consider that BOOKS are fragmented by $price amounts into: B1:BOOK1:up to $20.....
  11. Mysql And User File_priv
    (0)
    HI, I've hit the grain while trying to import file to mysql database - I need to enable file
    permissions of the database user but this seems not possible with most of the hosting providers.
    The problem is to set file_priv of the database user to "Y" . This is done in the "user" table of
    the maintanance database named "mysql". cPanel doesn't allow this. Via the cPanel you can only
    allow privileges on table querries but you cannot grant host file privileges to the database user -
    which makes querries like: "LOAD DATA INFILE 'filename' INTO TABLE tablen....
  12. Mysql With My Own Server
    few questions (4)
    Hi, I've only just joined the forum Can you link the mysql database here to your own website?
    If so how would I go about it Thanks =D....
  13. Mysql Storage Engine Error 28
    (5)
    Hello, On my website and forum, SDeckNET, the mySQL database is not working. I get the error "mySQL
    error: Got error 28 from storage engine mySQL error code: Date: Wednesday 02nd 2008f July 2008
    05:33:53 AM" from my forum. From what I know, error 28 means I'm out of disk space, how can this
    be? I was never told of a mySQL space limitation and all these cases of downtime are destroying my
    site's memberbase. EDIT: It now seems PhpMyAdmin is down too, with the error: "Warning:
    session_write_close() : SQLite: session write query failed: database is full in /usr/l....
  14. Php And Mysql Extension Installation
    (0)
    /** * $Author: pgeric $ * $Revision: 8 $ * $Date: 2008-06-30
    19:40:52 +0800 (Mon, 30 Jun 2008) $ * $Id: php_mysql_install.txt 8 2008-06-30 11:40:52Z
    pgeric $ */ Installing newer version of php and enable mysql connection. (As of this writing
    will be targeted at php 5.2.5 and above) Because of a change on newer version of php. Some files
    have been moved around within the default folder structure of php package. The result was when try
    working with mysql. It surprise you a lot. (The dicussion on this was based-on zip....
  15. I Have An Error With My Mysql Connection
    mysql connection error (7)
    ok so here's my web page... http://lacrossems.t35.org/ it only lags cause its trying to
    connect to the my sql server...i followed this guide
    http://forum.ragezone.com/showthread.php?t=387249 and when i edit my config.php to my host and
    login info i always get the error cannot connect to the database here is my config.php if you can
    help me CODE <?php $host['naam'] =
    'CENSORED';                // my host $host['gebruikersnaam'] =
    'righto';       // my database username $host['wach....
  16. Mysql - So Hard
    Come in here if you think MySQL is soo hard! (14)
    Doesn't anybody think MySQL is so hard to code? I mean think about it, you need loads of
    databases just for one little script and you have to type things in like ;Host-Username:
    (blahblah) ;Host-Password: (blahblah) ;Host-DatabaseName: (blahblah) Ok, that MySQL code was
    random, and it is alot harder than that. If you have expierenced it being hard, you are free to
    post right in here, mate.....
  17. Login System Using A Mysql Db
    How do i do this? (5)
    Hi guys, ive got a registration system that looks something like the one below: Firstname:
    Lastname: Then i have inset.php, which looks like the following: $con =
    mysql_connect("localhost","autobot","abc123"); if (!$con) { die('Could not connect:
    ' . mysql_error()); }mysql_select_db("my_db", $con);$sql="INSERT INTO person
    (username, password) VALUES ('$_POST ','$_POST ')";if
    (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record
    added";mysql_close....
  18. Php Tutorial: Making A Shoutbox
    Requirements: PHP, MySQL (11)
    Hi everyone, I'm going to tell you how to make a simple shoutbox using PHP and MySQL. To start
    off, open up mysql in the command line, or phpmyadmin, and create a database called shoutbox. Next,
    enter the following sql into the command line, or the phpmyadmin sql box, while using the shoutbox
    database: CODE create table messages(author varchar(30), message text, time
    timestamp, mid int auto_increment, primary key(mid)); This creates the table we need
    to store the messages, note the "mid" column, this gives each message a seperate id nu....
  19. Qupis : Free Cpanel Web Hosting (one Line Text Ad At Bottom)
    150 MB space, 10000 MB Bandwidth, php, mysql, CPanel (10)
    Hello Members, We are proud to introduce a new member to Xisto group of sites.
    Qupis : Free Web Hosting 150 MB space, 5000 MB Bandwidth, php,
    mysql, CPanel (Latest). Emails, FTP, Addon domains, Parked Domains etc.
    http://www.Qupis.com
    Feel free to add your reviews and comments about it. -AstaHost
    Management ....
  20. Navcat For MySQL
    is Navcat any good? (9)
    Hello all, i ve recently come across NavCat (GUI tool) for MySQL. I have not bought a copy yet, just
    played around with the demo. Has any one used it beore, if so please let me know if its worth
    buying. I already have PhpMyadmin, Just wanna know if NavCat is better than PhpMyAdmin in usibility
    and functionality. Regards....
  21. PHP & MySQL: Displaying Content From A Given ID
    (6)
    Okay so I got this sample link (not working): http://www.acosta.com/joo.asp?id=654 Now suppose
    I have a PHP file that would use MySql in order to get all values in the row where id 654 is found.
    Here's a sample DB: Table: demnyc ______________________________________ | id |
    Name | Age | Email | *----------------------------------------------------* | 1
    | Albert | 17 | no email |
    *----------------------------------------------------* | 2 | YaPow | 888 |
    no email | |__________....
  22. MySQL, Multiple Tables
    (24)
    Ok, I'm coding a project which is a leap than what I'd normally do. Before, I've always
    learned ONE table... put EVERYTHING in one database table. I'm making a profile system so there
    needs to be at least two tables: 1 for users, 1 for content. My problem is, how do I link the two
    together? I could probably figure this out faster if someone explained and posted sample SQL code
    that shows how the two are linked together. Thanks!! F....
  23. Important: Basics Of Using PHP And MySQL
    (10)
    I generally notice confusion with new users to PHP and or MySQL and first of all I believe that
    unlike HTML which is automatically associated with a IE browser in a Microsoft system. HTML is
    automatically rendered with whatever browser is the default browser, be it Internet Expolrer Firefox
    Netscape or any other browser that has been set. PHP is a different matter to view the output of a
    PHP file it must be run on a webserver, and if you do not have one set up on your local PC it simply
    will not work. (Note serverside langauge requies a server) HTML is client side and ....
  24. MySQL Output Database Question
    (18)
    I am new to MySql and have just created a database after using a script. My problem is not the
    script, but what it says about putting it into the output file. I cant figure out the right terms
    to put it in, I keep getting errors. I try using; SELECT*FROM 'database name' WHERE
    'location' but it isnt working. I'm lost with this stuff, I really am. Can someone
    please help me out?....
  25. [PHP + MySQL] Encrypting Data
    To protect the password of your DB, for example. (11)
    Hi! This is my 2nd code of PHP + MySQL. This code is VERY simple: it encript the data in the
    MySQL DB. Here we go! ------------------------------------------------------------------------
    CODE <?php $password = "abc"; $new_password = md5($password);
    echo $new_password; ?> The password "abc" was codfied using md5() This will be:
    900150983cd24fb0d6963f7d28e17f72 CODE <?php $normal_pass = "abc";
    $encripted_pass = "900150983cd24fb0d6963f7d28e17f72"; if(md5($norm....
  26. Need Help With A PHP - MySQL Registration Script
    Wont INSERT into the database (13)
    hey well can some one helpme make this code work it won't INSERT INTO THE DATABSE CODE
    <?php # register1.php # common include file to MySQL include("DB.PHP");
    $Username=$_POST['Username'];
    $Password=$_POST['Password'];
    $Name=$_POST['Name']; $Last=$_POST['Last'];
    $Sex=$_POST['Sex']; $Month=$_POST['Month'];
    $Day=$_POST['Day']; $Year=$_POST['Year&....
  27. Mirror My MySQL Database To Another Mysql Server
    (4)
    Hi..I want to ask if its possible to automatically mirror my mysql databases into another mysql
    server?or create a small php script to do this? The reason is because, we all know that database is
    very improtant if we have dynamic website. I have my forum hosted and i want to automatically
    mirror this or backup into another mysql server(free). Like in freesql.org. So that im not afraid
    that i forgot to backup my database..also i have one central backup database. Thanks for the
    help..Im looking forward for this posibility.....
  28. Recover Tables From A MySQL .frm File
    (8)
    I have a couple of .frm files with no corresponding data or index files. Is it possible to recover
    the table structure (field names, types, sizes, rows,col, etc) from these files? The table type is
    innodb....
  29. MySQL Realtime Replication
    how to replicate mysql in realtime (4)
    i dont know if this might be useful to ppl here, but this is a very good knowledge for serious
    siteadmins. while i was digging for mysql backup techniques, i've found that mysql is able to
    do realtime replication. the idea is that there are master server and slave server. both are having
    the same version of mysql installed. the data flows; Master >copy> Slave ( in realtime!)
    you'll never have to manually copy the database file of wasting your time to manually use the
    mysqldump command. here are the links; http://dev.mysql.com/doc/mysql/en/Replication_HOW....
  30. MySQL - Trouble With Bulk Insert Statements
    (3)
    I'm trying to insert about 500 rows into mysql, but I keep getting errors. If I copy and paste
    too many (about 50) insert statements at a time I get errors sometimes. I sometimes even get errors
    but then the row is skipped so I don't know there was an error (I'm using linux and SSH).
    What's the best way to get my insert statements to put the data in MySQL? Is there anyway that I
    can have it tell me if there where any errors all the statements are executed? Thanks for your
    help.....

    1. Looking for random, mysql, entry

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for random, mysql, entry
advertisement




Random MySQL Entry



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE