rockinaway Posted March 9, 2007 Share Posted March 9, 2007 $form_array = array('title', 'entry', 'comment', 'rating'); foreach ($form_array as $cs) { $query = mysql_query('SELECT value FROM prefix_config WHERE name = "'.$cs.'"'); $test = mysql_fetch_array($query); $cs = $test['value']; } What I am wanting to do is get the value for each thing in the array with a select, and then I want to update the array value with the new value from the query. This isn't working.. what should I do? Quote Link to comment https://forums.phpfreaks.com/topic/42034-array-problem/ Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Try this: $form_array = array('title', 'entry', 'comment', 'rating'); foreach ($form_array as $cs) { $query = mysql_query("SELECT value FROM prefix_config WHERE name = '".$cs."'"); $test = mysql_fetch_array($query); $cs = $test['value']; } MySQL only supports Single-quotes in it's queries. And to debug I would do this: $form_array = array('title', 'entry', 'comment', 'rating'); foreach ($form_array as $cs) { $query = mysql_query("SELECT value FROM prefix_config WHERE name = '".$cs."'") or DIE(mysql_error()); $test = mysql_fetch_array($query); $cs = $test['value']; } --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42034-array-problem/#findComment-203827 Share on other sites More sharing options...
rockinaway Posted March 9, 2007 Author Share Posted March 9, 2007 But then that means the variable is not read as a variable.. Quote Link to comment https://forums.phpfreaks.com/topic/42034-array-problem/#findComment-203833 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 What do you mean, that statement just confused me? <?php $x = "test test '" . $b . "' test test"; //is the same as $x = 'test test "' . $b . '" test test'; ?> --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42034-array-problem/#findComment-203836 Share on other sites More sharing options...
rockinaway Posted March 9, 2007 Author Share Posted March 9, 2007 Doesn't work that way around and I have been doing the same all through my other files and works fine.. I just see the problem in the updating of the array value Quote Link to comment https://forums.phpfreaks.com/topic/42034-array-problem/#findComment-203840 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Maybe your version of php and mysql would help diagnose the problem. Because as far as my knowledge goes, and every line of code that I have written what I posted above holds true. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42034-array-problem/#findComment-203850 Share on other sites More sharing options...
rockinaway Posted March 9, 2007 Author Share Posted March 9, 2007 It is doing the query fine.. just the array values aren't changing.. Quote Link to comment https://forums.phpfreaks.com/topic/42034-array-problem/#findComment-203852 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Ohhh my bad, mis-read the question. Try this: <?php $form_array = array('title', 'entry', 'comment', 'rating'); foreach ($form_array as $key => $cs) { $query = mysql_query('SELECT value FROM prefix_config WHERE name = "'.$cs.'"'); $test = mysql_fetch_array($query); $form_array[$key] = $test['value']; } ?> --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42034-array-problem/#findComment-203854 Share on other sites More sharing options...
rockinaway Posted March 10, 2007 Author Share Posted March 10, 2007 Thanks.. I had a think last night and I got something like that. I will try it later on . Quote Link to comment https://forums.phpfreaks.com/topic/42034-array-problem/#findComment-204176 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.