mendoz Posted December 14, 2006 Share Posted December 14, 2006 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 https://forums.phpfreaks.com/topic/30662-create-an-array-out-of-mysql-values-solved/ Share on other sites More sharing options...
craygo Posted December 14, 2006 Share Posted December 14, 2006 So let me get this straight, you want to create an array based on the values in the type field correct???Ray Link to comment https://forums.phpfreaks.com/topic/30662-create-an-array-out-of-mysql-values-solved/#findComment-141262 Share on other sites More sharing options...
mendoz Posted December 14, 2006 Author Share Posted December 14, 2006 Exactly Ray :) Link to comment https://forums.phpfreaks.com/topic/30662-create-an-array-out-of-mysql-values-solved/#findComment-141264 Share on other sites More sharing options...
craygo Posted December 14, 2006 Share Posted December 14, 2006 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 $typesRay Link to comment https://forums.phpfreaks.com/topic/30662-create-an-array-out-of-mysql-values-solved/#findComment-141272 Share on other sites More sharing options...
mendoz Posted December 14, 2006 Author Share Posted December 14, 2006 [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 $typesRay[/quote]I think you have a mistake here:$res = mysql_query([color=red]$res[/color]) or die (mysql_error());Thanks man! Link to comment https://forums.phpfreaks.com/topic/30662-create-an-array-out-of-mysql-values-solved/#findComment-141277 Share on other sites More sharing options...
mendoz Posted December 14, 2006 Author Share Posted December 14, 2006 This returnsFUNCTION control_site.DISTICT does not exist Link to comment https://forums.phpfreaks.com/topic/30662-create-an-array-out-of-mysql-values-solved/#findComment-141294 Share on other sites More sharing options...
marcus Posted December 14, 2006 Share Posted December 14, 2006 replace DISTICT with DISTINCT Link to comment https://forums.phpfreaks.com/topic/30662-create-an-array-out-of-mysql-values-solved/#findComment-141346 Share on other sites More sharing options...
mendoz Posted December 15, 2006 Author Share Posted December 15, 2006 Solved, thanks guys[code]<?php$types=array();$sql = "SELECT DISTINCT(type) as ctype FROM tablename";$res = mysql_query($sql) or die (mysql_error());while($r = mysql_fetch_assoc($res)){$types[] = $r['ctype'];}?>[/code] Link to comment https://forums.phpfreaks.com/topic/30662-create-an-array-out-of-mysql-values-solved/#findComment-141601 Share on other sites More sharing options...
craygo Posted December 15, 2006 Share Posted December 15, 2006 I type to fast sorry :) Link to comment https://forums.phpfreaks.com/topic/30662-create-an-array-out-of-mysql-values-solved/#findComment-141725 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.