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

Recommended Answers

All 2 Replies

Please define your problem more precisely and with example.

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 ? :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.