MySQL retrieve data from column?
#5

Don't use a wildcard(*) when you want to select a whole collumn of data. Wildcard selects every collumn, i.e waste of memory.

Код:
SELECT collumn_name FROM `watchlist`
Replace "collumn_name" with whatever collumn you're trying to return, and that query will return every thing in the specified collumn.

To access it, here is an example.
pawn Код:
CMD:watchlist(playerid, params[])
{
    mysql_query("SELECT * FROM `watchlist`"); // select all from watchlist
    mysql_store_result(); // store the result
   
    new
        result[24];

    while(mysql_retrieve_row())
    {
        mysql_fetch_field_row(result, "player");  
        printf("Result: %s", result); // Attempting to display the result (which only displays the first row)
    }
    mysql_free_result();
    return 1;
}
Since result is only one string, you'll need to store the results into a 2d array.
pawn Код:
CMD:watchlist(playerid, params[])
{
    mysql_query("SELECT * FROM `watchlist`"); // select all from watchlist
    mysql_store_result(); // store the result
   
    new
        result[mysql_num_rows()][24],
        i=0;
   
    while(mysql_retrieve_row())
    {
        mysql_fetch_field_row(result[i], "player");  
        printf("Result: %s", result); // Attempting to display the result (which only displays the first row)
        i++;
    }
    mysql_free_result();
    return 1;
}
Reply


Messages In This Thread
MySQL retrieve data from column? - by DBan - 05.07.2012, 02:38
Re: MySQL retrieve data from column? - by iGetty - 05.07.2012, 02:45
Re: MySQL retrieve data from column? - by DBan - 05.07.2012, 03:10
Re: MySQL retrieve data from column? - by Sinner - 05.07.2012, 06:44
Re: MySQL retrieve data from column? - by ReneG - 05.07.2012, 09:37

Forum Jump:


Users browsing this thread: 1 Guest(s)