I am trying to pull information from a database within a while loop. I want a certain variable ($var) to be added to itself everytime the loop is processed. Example is the value of $var is "hello" the first time and "goodbye" the second time. I want a new variable ($varlist) that I can call from outside the loop to be "hello, goodbye". How would I go about doing this?

Sample Code:

$query = "select * from subscribervars where username='$username' order by id ASC";
$result = mysql_query($query) or die("Couldn't execute query");
while ($row = @mysql_fetch_array($result)) {
$var = $row["var"];

//this is where I am missing the definition of $varlist

$count++ ;}
echo $varlist;
$query = "INSERT INTO $username ($varslist) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')";

}

    Thanks for your help! I got the first part to work now I am having problems with the following:

    $username = @$GET['username'] ;
    $query = "select * from subscribervars where username='$username' order by id ASC";
    $result = mysql_query($query) or die("Couldn't execute query");
    while ($row = @mysql_fetch_array($result)) {
    $this->$var = $
    POST[$var];
    $varlist[] = $row["var"];
    $count++ ;}
    $list = implode(",",$varlist);
    $query = "INSERT INTO $username ($list) VALUES ()";
    $this->DB_executeQuery($query, $this->subscriberLink);
    $this->id = $this->DB_getRecordID();

    How do I get my posted values for each variables into the values (), they are posted from a form. Also is this correct ($this->$var = $_POST[$var]😉 above or do I need single quotes or anything else missing.

    Thanks.

      Write a Reply...