SA-MP Forums Archive
MySQL - mysql_fetch_array? - 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)
+--- Thread: MySQL - mysql_fetch_array? (/showthread.php?tid=311060)



MySQL - mysql_fetch_array? - jamiesage123 - 14.01.2012

Hey,

I cant think of a way to display results from MySQL when querying something like this:

pawn Код:
mysql_query("SELECT * FROM people WHERE age = '15'");
mysql_store_result();

/*
Would i format it? or...
format(query, sizeof(query), "ID: %d | Name: %s | Age: %d | Gender: %s", id, name, age, gender);

I want to display the results like this:
-------------------------------------------¬
|ID: 1 | Name: Bob | Age: 15 | Gender: Male |
|ID: 2 | Name: Jay | Age: 15 | Gender: Male |
|ID: 3 | Name: Jim | Age: 15 | Gender: Male |
|ID: 4 | Name: Dan | Age: 15 | Gender: Male |
|ID: 5 | Name: Guy | Age: 15 | Gender: Male |
-------------------------------------------
*/


mysql_free_result();
Not really sure how to explain this, but in PHP it would be something like this:

PHP код:
$sql="SELECT * FROM people";
$result=mysql_query($sql);
while(
$rows=mysql_fetch_array($result)){
      
$age $rows['age'];
      echo 
$age;
}
mysql_close(); 
I'm currently using MySQL Plugin R6-2

Sorry if i didn't explain this clearly,

Thanks.


Re: MySQL - mysql_fetch_array? - Vince - 14.01.2012

It's a little more complicated in Pawn than it is in PHP. You would use mysql_fetch_row to - as the name implies - fetch an entire row. Then use a string splitting routine (like sscanf) to arrange the data in the designated variables. You can then use those variables for whatever purpose you'd like.


Re: MySQL - mysql_fetch_array? - jamiesage123 - 15.01.2012

Thanks for your help