Jump to content

sql query results into array


want2php

Recommended Posts

Very newbie here.

 

My sql table:

Table name: user_types

  - user_type_id = autoincrement

  - user_types = varchar with 4 records (Admin, User, Guest, Staff)

 

 

how do i perform the query so that it displays the result into arrays, like:

 

[1] => Admin

[2] => User

....

 

 

thanks for all your help.

 

Link to comment
https://forums.phpfreaks.com/topic/179813-sql-query-results-into-array/
Share on other sites

in the array

 

[1] => Admin

[2] => User

 

is 1 the admin user_type_id?

 

if so..

you'd have somthing like this

 

$sql = @mysql_query("SELECT * FROM user_types");

while ($r = mysql_fetch_array($sql))
{
$userTypes[$r['user_type_id']] = $r['user_types'];
}

then you'd have an array with

$userTypes[1] = "Admin"

$userTypes[2] = "User" etc

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.