Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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