Jump to content

Recommended Posts

I have a table and i have just added a new row, "imagedir". I have set it so by defult it says "pic/c.png". But it has not put "pic/c.png" in all the old data rows. Is there a quick way in which i can add id to each one?

297531[/snapback]

 

You could do it in a short loop:

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php

$q [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"select imagedir,id form yourtable where imagedir != \'pic/c.png\'\"[/span][span style=\"color:#007700\"];

[/span][span style=\"color:#0000BB\"]$rs [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$q[/span][span style=\"color:#007700\"]) or die([/span][span style=\"color:#DD0000\"]\'Problem with query: \' [/span][span style=\"color:#007700\"].[/span][span style=\"color:#0000BB\"]$q[/span][span style=\"color:#007700\"].[/span][span style=\"color:#DD0000\"]\'<br>\'[/span][span style=\"color:#007700\"]. [/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]());

while ([/span][span style=\"color:#0000BB\"]$rw [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_fetch_assoc[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$rs[/span][span style=\"color:#007700\"])) {

   [/span][span style=\"color:#0000BB\"]$qu [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"update yourtable set imagedir = \'pic/c.png\' where id = \'\" [/span][span style=\"color:#007700\"]. [/span][span style=\"color:#0000BB\"]$rw[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'id\'[/span][span style=\"color:#007700\"]] . [/span][span style=\"color:#DD0000\"]\"\'\"[/span][span style=\"color:#007700\"];

   [/span][span style=\"color:#0000BB\"]$ru [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$qu[/span][span style=\"color:#007700\"]) or die([/span][span style=\"color:#0000BB\"]Problem with update query[/span][span style=\"color:#007700\"]: [/span][span style=\"color:#DD0000\"]\' . $qu . \'[/span][span style=\"color:#007700\"]<[/span][span style=\"color:#0000BB\"]br[/span][span style=\"color:#007700\"]>[/span][span style=\"color:#DD0000\"]\' . mysql_error());

   echo \'[/span][span style=\"color:#0000BB\"]ID[/span][span style=\"color:#007700\"]: [/span][span style=\"color:#DD0000\"]\' . $rw[\'[/span][span style=\"color:#0000BB\"]id[/span][span style=\"color:#DD0000\"]\'] . \'[/span][span style=\"color:#0000BB\"]Updated successfully[/span][span style=\"color:#007700\"]<[/span][span style=\"color:#0000BB\"]br[/span][span style=\"color:#007700\"]>\'[/span][span style=\"color:#0000BB\"].\"\n\";

   }

?>[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

 

Add your appropriate database initializations to the beginning of the file.

 

Ken

 

Link to comment
https://forums.phpfreaks.com/topic/2545-add-to-all/#findComment-8440
Share on other sites

simply this should do:

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?

mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"UPDATE yourtable SET imagedir=\'pic/c.png\'\"[/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]?>[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

this will set all imagedir to pic/c.png

 

The UPDATE statement updates columns in existing table rows with new values. The SET  clause indicates which columns to modify and the values they should be given. The WHERE clause, if given, specifies which rows should be updated. Otherwise, all rows are updated.
Link to comment
https://forums.phpfreaks.com/topic/2545-add-to-all/#findComment-8444
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.