Answer the question
In order to leave comments, you need to log in
How to change mysql field values?
Good morning.
There was a following task.
There are many images in the gallery (more than 1000), and everyone needs to change the value of the
alttext field in the database according to the pattern qw-000#
qw - section name, # - sequence number (1, 2, 3...)
galleryid = 3
That is, I need to run each line with a certain galleryid and change the alttext to qw-000
# , it won’t be fun to fill it with your hands
)
Logic: we request the filename of images from the gallery with a certain id (the only thing that was unique there), we create an array from them. After we sort through all the values and change the alttext to the one generated where the filename matched
<?php
mysql_connect("localhost", "root", "") or die (mysql_error ());
mysql_select_db("dbname") or die(mysql_error());
function changeAltText($galleryId, $galleryName) {
$query = mysql_query("SELECT filename FROM pictures WHERE galleryid='$galleryId'");
$i=1;
$fileName = array();
while($row = mysql_fetch_array($query, MYSQLI_ASSOC)) {
$fileName[$i]=$row['filename'];
$i++;
}
$k = count($fileName)+1;
for ($i=1; $i<$k; $i++) {
$fileNameI = $fileName[$i];
$name = $galleryName.sprintf("%'.05d\n", $i);
mysql_query("UPDATE pictures SET alttext='$name' WHERE galleryid='$galleryId' AND filename='$fileNameI'");
echo $fileNameI."<br>";
echo $name."<br>";
}
}
changeAltText(1, 'ar-');
changeAltText(2, 'ak-');
Answer the question
In order to leave comments, you need to log in
how can this be implemented, at least in which direction to digWrite a simple script in php (since you have it in the tags). If you don't know how to do it - break your task into small steps and look for information in a search engine or ask specific questions here.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question