To retrieve a string from a MySQL database without mysql_fetch_row_format?
#1

How would I do this, using G-StyleZzZ's plugin, I'm trying to get all the fields from a table where there's a certain name, the field is a string by the way. I tried mysql_fetch_field, but it returned the field structures' name. I thought the function worked differently, but hmm. Anyone have an idea, how to answer the subject?

Quote:
Originally Posted by Subject
To retrieve a string from a MySQL database without mysql_fetch_row_format?
Reply
#2

Use mysql_retrieve_row() to move between rows and mysql_get_field (mysql_fetch_field_row) to get specific field's value.
Reply
#3

Quote:
Originally Posted by $ЂЯĢ
Use mysql_retrieve_row() to move between rows and mysql_get_field (mysql_fetch_field_row) to get specific field's value.
Can you show me an example?
Reply
#4

sscanf
Reply
#5

Quote:
Originally Posted by nemesis99
sscanf
No.
Reply
#6

lmfao sscanf?
Reply
#7

Use mysql_fetch_row_format with sscanf. I can get 100 fields into 100 variables using 3 lines of code where it would take you 100 lines of code using mysql_fetch_field_row (granted this wasn't your question, sscanf is a powerful tool).

Serg is eager to help you though so I'll let him take it from here.
Reply
#8

Quote:
Originally Posted by nemesis99
Use mysql_fetch_row_format with sscanf. I can get 100 fields into 100 variables using 3 lines of code where it would take you 100 lines of code using mysql_fetch_field_row (granted this wasn't your question, sscanf is a powerful tool).

Serg is eager to help you though so I'll let him take it from here.
*sigh* please stop trying.. You're just throwing useless information.
Reply
#9

pawn Код:
//some query
mysql_store_result();
if(mysql_retrieve_row()) //there are actually any rows
{
   mysql_get_field("fieldname",wheretostorevalue); //macro for mysql_fetch_field_row
   mysql_get_field(...);
   mysql_get_field(...);
   mysql_get_field(...);
   mysql_get_field(...);
}
else //there aren't
{

}
mysql_free_result();
Upper example is when you operate only with one row (for example player login). If you expect many rows (for examples when you select something from vehicles table) you use while.

pawn Код:
//some query
mysql_store_result();
while(mysql_retrieve_row()) //it will be running until there are no more rows to be retrieved
{
   mysql_get_field("fieldname",wheretostorevalue); //macro for mysql_fetch_field_row
   mysql_get_field(...);
   mysql_get_field(...);
   mysql_get_field(...);
   mysql_get_field(...);
}
mysql_free_result();
Using this method rather than mysql_fetch_row_format + sscanf combination is better because if you add another field in the table you will need to modify that long sscanf line and it's easy to mix things up. With this method you just add another line to get new field's value and that's it. Also it's easier if you don't use all fields which you get because you just don't get them, while in sscanf you would need to use quiet function on them
Reply
#10

Quote:
Originally Posted by $ЂЯĢ
....
Thank you for the example, I used this and it worked.

pawn Код:
new wdata[TOTAL_RECORDS][50];
 for(new i = 0; i < TOTAL_RECORDS; i ++ ) {
      if(mysql_retrieve_row()) //there are actually any rows
      {
         mysql_get_field("WantedFor", wdata[i]);
         print(wdata[i]);
      }
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)