Jump to content

Array problem


rockinaway

Recommended Posts

$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?

Link to comment
https://forums.phpfreaks.com/topic/42034-array-problem/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/42034-array-problem/#findComment-203827
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/42034-array-problem/#findComment-203854
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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