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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.