Jump to content


Photo

add to all


  • Please log in to reply
2 replies to this topic

#1 simjay

simjay
  • Members
  • Pip
  • Newbie
  • 1 posts

Posted 20 September 2005 - 08:59 PM

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
Low Price Hosting HaveWebHosting

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 20 September 2005 - 09:44 PM

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?

View Post


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


#3 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 20 September 2005 - 11:07 PM

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.


Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users