Jump to content

Archived

This topic is now archived and is closed to further replies.

simjay

add to all

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?

 

 

Table:

nameof

why

id

dateinput

imagedir

width

height

 

many thanks

Share this post


Link to post
Share on other sites
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

 

Share this post


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

Share this post


Link to post
Share on other sites

×

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.