MySQL - mysql_fetch_array?
#1

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.
Reply
#2

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.
Reply
#3

Thanks for your help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)