SA-MP Forums Archive
[MySQL] - Extraction - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [MySQL] - Extraction (/showthread.php?tid=129901)



[MySQL] - Extraction - ErF - 24.02.2010

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 ?


Re: [MySQL] - Extraction - TTJJ - 24.02.2010

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


Re: [MySQL] - Extraction - ErF - 24.02.2010

Thanks, working


Re: [MySQL] - Extraction - Miguel - 24.02.2010

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();