Jump to content

Update column with foreach


balkan7

Recommended Posts

I want to update empty columns in datebase, so i have this table:

 

category

- cid

- cname

- cparent

- cseo

Column cseo is empty i want update it with cname column with seo function.

This foreach doesn't work

 

code is:

<?php
$cats = mysql_query("SELECT * FROM category WHERE cparent ='4' ORDER BY cid DESC");
while ($data = mysql_fetch_array($cats)) {
if ($data['cseo'] == ""){
foreach ($data['cname'] as $seo_names) {
$seo_link = seo($seo_names);
$result = mysql_query("UPDATE category SET cseo='$seo_link' WHERE cid='".$data['cid']."'");
if ($result) { echo "Done!"; }
}
}
}

 

Link to comment
Share on other sites

Seems like this should work.

<?php
$cats = mysql_query("SELECT cid, cname FROM category WHERE cparent ='4' ORDER BY cid DESC");
while ($data = mysql_fetch_array($cats)) {
$cname = $data['cname'];
$seo_link = seo($cname);
$result = mysql_query("UPDATE category SET cseo='$seo_link' WHERE cid='".$data['cid']."'");
}
?>

Link to comment
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.