Jump to content

Create an array out of mysql values [solved]


mendoz

Recommended Posts

My boss is going to pay me I'm stuck working all day long  :-[

Anyway, I want to create an a little array and let's see if I can explain:

In my famous table I have a column called 'type'.
Currently there are 3 different values for it: [laptop,pc,hardware]

I want the array to go through all the table and take those different values.

While writing this I think I found the solution,
THE RACE IS ON PLACE YOUR BETS ?>?<?>?<?>?<>

im going crazy
OK

[code]<?php
$types=array();
$sql = "SELECT DISTICT(type) as ctype FROM tablename";
$res = mysql_query($res) or die (mysql_error());
while($r = mysql_fetch_assoc($res)){
$types[] = $r['ctype'];
}
?>[/code]

Now your type field is in an array called $types

Ray
[quote author=craygo link=topic=118628.msg484948#msg484948 date=1166119762]
OK

[code]<?php
$types=array();
$sql = "SELECT DISTICT(type) as ctype FROM tablename";
$res = mysql_query($res) or die (mysql_error());
while($r = mysql_fetch_assoc($res)){
$types[] = $r['ctype'];
}
?>[/code]

Now your type field is in an array called $types

Ray
[/quote]

I think you have a mistake here:
$res = mysql_query([color=red]$res[/color]) or die (mysql_error());

Thanks man!

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.