Jump to content

Recommended Posts

I have a list of variables with identical names except for the final character, BUT they are NOT in an array. I understand arrays, but I'm passing these variables from a form in a previous page. I'm trying to use the variable $count to change from $name1 to $name2 to $name3, etc... and $uname1 to $uname2 to $uname3, etc... for each loop. I have the most terrible feeling that this is an elementary problem with an elementary solution. Thanks for any help.

 

$link = mysql_connect("••••••","••••••","••••••") or die("Could not connect: ".mysql_error());
        mysql_select_db("ositoweb") or die("Could not select database: ".mysql_error());

          $query = "SELECT id, title, continent, orden, fname, lname, uname FROM vp_data ORDER BY continent, orden";
          $result = mysql_query($query) or die("Could not perform query: ".mysql_error());

          $count = 1;
        while ($row = mysql_fetch_array($result)) {
          
					$query1 = "Update vp_data SET uname = '$uname".$count."' WHERE title='$name".$count."'"; 
					$result1 = mysql_query($query1);
					print $query1."<br>";
					$count++;

				}

 

 

Link to comment
https://forums.phpfreaks.com/topic/94904-incrementing-variable-inside-quote/
Share on other sites

Change:

$query1 = "Update vp_data SET uname = '$uname".$count."' WHERE title='$name".$count."'"; 

 

to

$tmp_uname = {'uname' . $count};
$tmp_title = {'name' . $count};
$query1 = "UPDATE `vp_data` SET `uname` = '{$tmp_uname}' WHERE title={$tmp_title}";

GREAT! That seemed to work.

$link = mysql_connect("•••••","•••••","•••••") or die("Could not connect: ".mysql_error());

                  mysql_select_db("ositoweb") or die("Could not select database: ".mysql_error());

 

          $query = "SELECT id, title, continent, orden, fname, lname, uname FROM vp_data ORDER BY continent, orden";

          $result = mysql_query($query) or die("Could not perform query: ".mysql_error());

 

          $count = 1;

        while ($row = mysql_fetch_array($result)) {

         

          $tmp_uname = ${'uname' . $count};

$tmp_title = ${'name' . $count};

 

$query1 = "UPDATE vp_data SET uname = '{$tmp_uname}' WHERE title={$tmp_title}";

$result1 = mysql_query($query1);

print $query1."<br>";

 

$count++;

}

 

But the data isn't being stored in the database. The print $query1 line is properly displaying the data as it should:

UPDATE vp_data SET uname = 'jaandrws' WHERE title=VP Africa

UPDATE vp_data SET uname = 'jandrews' WHERE title=VP Central and Western Africa

UPDATE vp_data SET uname = 'aaslestad' WHERE title=VP India

UPDATE vp_data SET uname = 'George' WHERE title=VP Bangladesh and Pakistan

UPDATE vp_data SET uname = '2828' WHERE title=VP Japan

UPDATE vp_data SET uname = '2014' WHERE title=VP Asia Minor and Northern Africa

UPDATE vp_data SET uname = '3324' WHERE title=VP Southeast Asia

UPDATE vp_data SET uname = 'mzober' WHERE title=VP Pacific Coastal

UPDATE vp_data SET uname = '3701' WHERE title=VP Northeast Australia

UPDATE vp_data SET uname = 'rjhaddad' WHERE title=VP Southwest Australia

UPDATE vp_data SET uname = 'giianor' WHERE title=VP New Zealand

UPDATE vp_data SET uname = '1473' WHERE title=VP Great Britain and Ireland

UPDATE vp_data SET uname = '2141' WHERE title=VP Northern Europe

UPDATE vp_data SET uname = 'Labgal47' WHERE title=VP Scandinavia

UPDATE vp_data SET uname = 'adel' WHERE title=VP Germany

UPDATE vp_data SET uname = '2211' WHERE title=VP Southern Europe

UPDATE vp_data SET uname = 'kevinof' WHERE title=VP France

UPDATE vp_data SET uname = '3703' WHERE title=VP Central America and Mexico

UPDATE vp_data SET uname = '1587' WHERE title=VP Caribbean and Atlantic Islands

UPDATE vp_data SET uname = '841' WHERE title=VP South America

UPDATE vp_data SET uname = '3541' WHERE title=VP California USA

UPDATE vp_data SET uname = 'atalbot' WHERE title=VP Northwest USA

UPDATE vp_data SET uname = '3398' WHERE title=VP Plains USA

UPDATE vp_data SET uname = '3613' WHERE title=VP Southwest USA

UPDATE vp_data SET uname = '3493' WHERE title=VP Northeast USA

UPDATE vp_data SET uname = '3398' WHERE title=VP Midwest USA

UPDATE vp_data SET uname = 'zaleski' WHERE title=VP Southeast USA

UPDATE vp_data SET uname = '1783' WHERE title=VP Midsouth USA

UPDATE vp_data SET uname = 'George' WHERE title=VP Alaska USA

UPDATE vp_data SET uname = '2828' WHERE title=VP Canada

UPDATE vp_data SET uname = '2014' WHERE title=VP Eastern Canada

 

but it isn't storing the data. The database name is acurrate as are the titles. I'm puzzled.

 

 

 

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.