0

i have a database and it has a column thats id its auto incrementing and one called download_link
i want to have that autofill with a url thats concatinated with my id
so localhost/upload/downloadtest.php?id=
adds the id and becomes
localhost/upload/downloadtest.php?id=1
localhost/upload/downloadtest.php?id=2
localhost/upload/downloadtest.php?id=3

etc

how could i do that be done

3
Contributors
2
Replies
5
Views
8 Years
Discussion Span
Last Post by nav33n
0

i have a database and it has a column thats id its auto incrementing and one called download_link
i want to have that autofill with a url thats concatinated with my id
so localhost/upload/downloadtest.php?id=
adds the id and becomes
localhost/upload/downloadtest.php?id=1
localhost/upload/downloadtest.php?id=2
localhost/upload/downloadtest.php?id=3

etc

how could i do that be done

First, query the table and select all records.

$query = "select * from table";
$result = mysql_query($query);

Then for every id, concat $id to a string and store it in the array.

$data = array();
while($row = mysql_fetch_array($result)) {
 $id = $row['id'];
$string = "http://localhost/upload/downloadtest.php?id=".$id;
$data[$id] = $string;
}

By the end of execution of this while loop, you will have an array called data with the urls and ids as array indices.
Then use foreach loop to update the table.

foreach($data as $key => $value) {
  $update_query = "update table set download_link = '".$value."' where id=".$key;
mysql_query($update_query);
}

Thats it! Clear enough ? :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.