Prank Posted July 3, 2006 Share Posted July 3, 2006 Hi Guys,I am building a site which is going to utilise a 'settings' table in mysql which will effect the site depending on the value of certain fields.. does that make sense?So, I have a 3 field table (id, name & value). Then the rows would be (for example; 1, is_feature_turned_on, Y). So then a simple if statement will display or hide that feature. Now, what I want to know is, whats the best way to reference these names and values? I could be stupid and simple write a new query for each row that I want to reference (SELECT * FROM settings WHERE name = is_feature_turned_on) but thats silly. I dont know how else I can easily access these values, so I thought I must be able to put them into an array somehow and access them like so (name['is_feature_turned_on']) but I simply cannot get my head around how to do this. It might be really simple and something I have just not yet considered.Anyway, I would greatly appreciate any help at all on this.Thanks in advance,Christian Quote Link to comment https://forums.phpfreaks.com/topic/13522-returning-mysql-rows-into-an-array-i-think/ Share on other sites More sharing options...
.josh Posted July 3, 2006 Share Posted July 3, 2006 do you want to select all the rows where the value = something? or do you want to select all the information in all of the rows and then be able to manipulate that info with php? Quote Link to comment https://forums.phpfreaks.com/topic/13522-returning-mysql-rows-into-an-array-i-think/#findComment-52367 Share on other sites More sharing options...
Prank Posted July 3, 2006 Author Share Posted July 3, 2006 [quote author=Crayon Violent link=topic=99267.msg390886#msg390886 date=1151909295]do you want to select all the rows where the value = something? or do you want to select all the information in all of the rows and then be able to manipulate that info with php?[/quote]I dont need to be able to manipulate it as it should be fine in its current state. I just need to select all and then refer to itThanks! Quote Link to comment https://forums.phpfreaks.com/topic/13522-returning-mysql-rows-into-an-array-i-think/#findComment-52371 Share on other sites More sharing options...
.josh Posted July 3, 2006 Share Posted July 3, 2006 [code]<?php//connect to sql and selected your db//select everything from your table$sql = "select * from settings";$result = mysql_query($sql);//loop through each rowwhile ($list = mysql_fetch_array($result)) { //option 1: //if you are just wanting it to display the list one time, simply echo it here //example echo'd format: echo $list['id'] . " " . $list['name'] . " " . $list['value'] . "<br>"; //option 2: //if you need to be able to access these results for later, like //passing it to another script eventually, or something, make //an array of the results: $info[] = $list;} //end while loop//examples for accessing $info data://dump everything out:foreach($info as $key => $val) { echo $key . " : " . $val . "<br>";}//access a specific row://echos the name in the 3rd row..remember arrays start at 0 not 1echo $info[2]['name']; ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13522-returning-mysql-rows-into-an-array-i-think/#findComment-52376 Share on other sites More sharing options...
Prank Posted July 3, 2006 Author Share Posted July 3, 2006 Sweet, I'll give that a go, thanks!! :) Quote Link to comment https://forums.phpfreaks.com/topic/13522-returning-mysql-rows-into-an-array-i-think/#findComment-52381 Share on other sites More sharing options...
Prank Posted July 3, 2006 Author Share Posted July 3, 2006 Worked a treat, thanks heaps! Quote Link to comment https://forums.phpfreaks.com/topic/13522-returning-mysql-rows-into-an-array-i-think/#findComment-52385 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.