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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
mendoz Posted December 14, 2006 Author Share Posted December 14, 2006 Exactly Ray :) Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
marcus Posted December 14, 2006 Share Posted December 14, 2006 replace DISTICT with DISTINCT Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
craygo Posted December 15, 2006 Share Posted December 15, 2006 I type to fast sorry :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.