How to cehck unique numbers in database in R7 using mysql_function_query?
#1

Hello, I'm working on my platenumber and phonenumber system, as you may notice I'll need unique numbers for every palyers, I've made a random function that works well, but the problem is that my mysql function to read if there is any current numbers like that doesn't work.
How to check if there is any rows with mysql_function_query? as i do it now is:

pawn Код:
//i generate a random number here, then i use this function

format(query, sizeof(query), "SELECT carid FROM publiccars WHERE carplatenocolor = '%s'", string);
if(mysql_function_query(dbHandle, query, true, "CheckRows", "") == 0) return 0;//this returns that the number is availiable and else i return 1;

forward CheckRows();
public CheckRows(){
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows) return 1;
    else return 0;
}
but mysql_funcion_query dosen't seems to return anything, do anyone else know why or get better ideas on how to do this?

I'm thnkfull for every answer
Reply
#2

Put printf("Received %d rows and %d fields", rows, fields); under cache_get_data. What do you get in console?
Reply
#3

Make carid a unique value when you create the table structure:

PHP код:
CREATE TABLE `your_table_name`(
    
carid INT NOT NULL,                        // Create carid field
    
CONSTRAINT carid_key PRIMARY KEY(carid// Make carid the primary key
); 
Now any carid value will be unique, and it will auto increment, so you don't have to insert the value when creating new rows. Whenver you then check if the row exists you only need to check if it occurs once, as multiple rows with the same ID is impossible.

Like so:

PHP код:
SELECT COUNT(*) FROM `your_table_nameWHERE carid = `the_carid_to_check
Although this query would be useless when using unique keys.
Reply
#4

Quote:
Originally Posted by Sinner
Посмотреть сообщение
Make carid a unique value when you create the table structure:

PHP код:
CREATE TABLE `your_table_name`(
    
carid INT NOT NULL,                        // Create carid field
    
CONSTRAINT carid_key PRIMARY KEY(carid// Make carid the primary key
); 
Now any carid value will be unique, and it will auto increment, so you don't have to insert the value when creating new rows. Whenver you then check if the row exists you only need to check if it occurs once, as multiple rows with the same ID is impossible.

Like so:

PHP код:
SELECT COUNT(*) FROM `your_table_nameWHERE carid = `the_carid_to_check
Although this query would be useless when using unique keys.
Thanks for the fast answer, (sorry that i was so slow to answer xD)
I'm using PhPMyadmin to create the tables, how do i do this then, I don't see any function like that in phpMyAdmin?
Reply
#5

Go into your table, click 'Structure' tab at the top. To the right of the column you want to alter there is a button called 'Unique Value'. Click it.
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
Go into your table, click 'Structure' tab at the top. To the right of the column you want to alter there is a button called 'Unique Value'. Click it.
Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)