FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PMA dilemma





Zombie
Hi,
I'm using phpmyadmin and I have about 1,000 records in one category... here's the problem: I need a few letters added to the title of every single record in that category. Am I going to have to edit each record individually or is there an easier way?
Diablosblizz
I don't know the table structure, but you may be able to do something with PHP:

Code:

$select = mysql_query("SELECT * FROM `wherever`);
$array = mysql_fetch_array('$select');
$title = $array['title'] + "WHATEVER HERE";
$update = mysql_query("UPDATE `whatever` SET `title` = '$title');


You may want a bit of knowledge of PHP and MySQL before continuing. I'm not entirely sure if you can do it within PMA, but this would work nonetheless. Good luck.
kv
Or you can run sql directly from phpmyadmin using sql window

Code:

UPDATE `<tablename>` SET `title` = concat('<letters to add>', title);
Diablosblizz
Yes that will work, sorry I wasn't aware of how to do it in PMA. Thank you for that kv.
rvec
you'd probably also want a while loop to just add it to all in one scriptrun instead of changing the title for each row individually.

Quote:
Code:
$select = mysql_query("SELECT * FROM `wherever`);
$array = mysql_fetch_array('$select');
$title = $array['title'] + "WHATEVER HERE";
$update = mysql_query("UPDATE `whatever` SET `title` = '$title');

That'll change it on only one row and would be more recourse intensive than needed. Also I think that would generate some errors (forgot closing ", using '' around a variable and using ``).

try this instead:
Code:
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Could not connect: " . mysql_error());
mysql_select_db("database");

$select = mysql_query("SELECT title FROM your_table WHERE category='yourcat'");
while ($row = mysql_fetch_array($select, MYSQL_ASSOC)) {
   $title = $row['title'] . 'the text you want added';
   mysql_query("UPDATE your_table SET title = '$title' WHERE title='{$row['title']}'");
}
?>

if you want the text in front of the title instead of after it you can use this line instead of the $title = line.
Code:
$title ='the text you want added' . $row['title'];
Related topics
best booke in your mind
online / offline image dilemma
When dating a new girl, how long do you wait before you kiss
Dilemma
Just a question
The Insider
I have a dilemma....
Justification for War in Iraq
Tibia
Do you like bush? Or do you hate bush?
Is the death penalty wrong?
I want to kill/slay/erase/get rid of cpanel
Love - Fantasy or REAL?
Prisoner's Dilemma
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.