[MySQL] - Extraction
#1

Hi. I would like to download all data from MySQL and assign them to the appropriate variable. in PHP it would look something like this:
Код:
$query = mysql_query("SELECT * FROM test");
while($row = mysql_fetch_array($query))
{
  echo $row['field1']'.<br />'.$row['field2'];

}
In samp ?
Reply
#2

Hi ErF,

The best way I found to do this, is to fetch the returned row then explode it by it's seperator which is uually "|"


Let me give you an example:

Код:
new query[256], result[1024], row[10][64];
format(query,sizeof(query),"SELECT * FROM `tablename` WHERE `columnname` = '%s'",VARIABLE);
mysql_query(query);
mysql_store_result();
mysql_fetch_row_format(result);
explode(row,result,"|");
Variable1 = strval(row[1]);
mysql_free_result();
Thats the easiest way I found of doing it, BTW you can find the explode function here: http://forum.sa-mp.com/index.php?topic=110557.0

Hope this helped you out,

TJ
Reply
#3

Thanks, working
Reply
#4

You can use sscanf aswell:
pawn Код:
new
  line[1], // this depends on how much data are you storing there
  query[70];

format(string, sizeof(string), "SELECT * FROM `tablename` WHERE `columnname` = '%s'", VARIABLE);
mysql_query(query);
mysql_store_result();
mysql_fetch_row_format(line, "|");
sscanf(line, "p|dsf", variable1, variable2, variable3); // This is gonna place all the data delimited by a | into those variables, note there are just 3.
mysql_free_result();
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)