SQL Select
#1

Alright so its quite simple, but I dont know how to do it.
What im trying to achieve is simple, read the SQL and print all the results, I want to read all rows that match the ID
PHP код:
new query[512];
    
mysql_format(mysqlquerysizeof(query),"SELECT `ID`,`Model` FROM `furniture` WHERE `MasterID`=%i",AccInfo[playerid][HouseOwner]);
     
mysql_tquery(mysqlquery);
     print(
query); 
Reply
#2

Although I recommend phpMyAdmin to browse the MySQL database (while on development, having it hosted on production can be a security risk, once (& if) breached
PHP код:
forward OnHouseStripHouseData(playerid);
 
public 
OnPlayerConnect(playerid) {
    new 
query[512];
    
GetPlayerName(playeridpnamesizeof(pname));
  
mysql_format(mysqlquerysizeof(query),"SELECT `ID`,`Model` FROM `furniture` WHERE `MasterID`=%i",AccInfo[playerid][HouseOwner]); 
  
mysql_tquery(mysqlquery"OnHouseStripHouseData"); 
    return 
1;
}
 
public 
OnHouseStripHouseData() {
  new 
      
dest[128], // we will store the field data here 
      
rows=cache_num_rows(), // get number of rows in the result
      
fields=cache_get_field_count(); // get the number of fields in the result
  // Loop through all the existing rows in the result
  
for(new x=0;x<rows;x++) {
    
// Loop through all the fields on the specific row
    
for(new y=0;y<fields;y++) {
      
// Get data from row X and field number Y from left to right
      
cache_get_row(xydest);
      
// Print it !
      
printf("| %s"dest);
    } 
  }
  return 
1;

inb4, untested.
Don't have anything to test with, its improvised.
Reply
#3

Quote:
Originally Posted by Kaperstone
Посмотреть сообщение
Although I recommend phpMyAdmin to browse the MySQL database (while on development, having it hosted on production can be a security risk, once (& if) breached
PHP код:
forward OnHouseStripHouseData(playerid);
 
public 
OnPlayerConnect(playerid) {
    new 
query[512];
    
GetPlayerName(playeridpnamesizeof(pname));
  
mysql_format(mysqlquerysizeof(query),"SELECT `ID`,`Model` FROM `furniture` WHERE `MasterID`=%i",AccInfo[playerid][HouseOwner]); 
  
mysql_tquery(mysqlquery"OnHouseStripHouseData"); 
    return 
1;
}
 
public 
OnHouseStripHouseData() {
  new 
      
dest[128], // we will store the field data here 
      
rows=cache_num_rows(), // get number of rows in the result
      
fields=cache_get_field_count(); // get the number of fields in the result
  // Loop through all the existing rows in the result
  
for(new x=0;x<rows;x++) {
    
// Loop through all the fields on the specific row
    
for(new y=0;y<fields;y++) {
      
// Get data from row X and field number Y from left to right
      
cache_get_row(xydest);
      
// Print it !
      
printf("| %s"dest);
    } 
  }
  return 
1;

inb4, untested.
Don't have anything to test with, its improvised.
Not results at all. Nothing printed
PHP код:
YCMD:test(playerid,params[],help) {
    new 
query[512];
     
mysql_format(mysqlquerysizeof(query),"SELECT `ID`,`Model` FROM `furniture` WHERE `MasterID`=%i",AccInfo[playerid][HouseOwner]);
      
mysql_tquery(mysqlquery"OnHouseStripHouseData");
    return 
true;
}
forward OnHouseStripHouseData(playerid);
public 
OnHouseStripHouseData(playerid) {
      new
      
dest[128], // we will store the field data here
      
rows=cache_num_rows(), // get number of rows in the result
      
fields=cache_get_field_count(); // get the number of fields in the result
      
    
for(new x=0;x<rows;x++) {
        for(new 
y=0;y<fields;y++) {
              
cache_get_row(xydest);
              
printf("| %s"dest);
        }
     }
      return 
1;

EDIT: Nevermind, the problem was in my format, works!! thanks!
Reply
#4

There is 1 problem tho, sorry for double post, but it prints the stuff this way
PHP код:
[20:09:15] | 6
[20:09:15] | 2290
[20:09:15] | 7
[20:09:15] | 2290
[20:09:15] | 8
[20:09:15] | 2290
[20:09:15] | 9
[20:09:15] | 2290
[20:09:15] | 10
[20:09:15] | 2290
[20:09:15] | 11
[20:09:15] | 2290
[20:09:15] | 12
[20:09:15] | 2290 
I want to print 2 variables in the same line. Ie:

2290 || 7
Reply
#5

use strcat to push each field to the array, after the field loop ends (which means - end of row) print the array.
Reply
#6

Ah, mind just showing me how? I know what you mean but im not sure how to push them multiple into 1 line
Reply
#7

Bump
Quote:

Ah, mind just showing me how? I know what you mean but im not sure how to push them multiple into 1 line

Reply
#8

pawn Код:
forward OnHouseStripHouseData();
public OnHouseStripHouseData()
{
    new id,model,rows = cache_num_rows(); // get number of rows in the result

    for(new i=0; i < rows; i++)
    {
        id = cache_get_field_content_int(i, "ID");
        model = cache_get_field_content_int(i, "Model");
        printf("%d|%d", id, model);
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
forward OnHouseStripHouseData();
public OnHouseStripHouseData()
{
    new id,model,rows = cache_num_rows(); // get number of rows in the result

    for(new i=0; i < rows; i++)
    {
        id = cache_get_field_content_int(i, "ID");
        model = cache_get_field_content_int(i, "Model");
        printf("%d|%d", id, model);
    }
    return 1;
}
Thanks
Reply
#10

There is 1 problem, it sorta creates an infinite loop. It keeps telling all players the furniture ID after they buy one afterwards.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)