we've got an issue on our new test site that i'd like you to be able to solve;

we have product pages; example page:
http://www.printsmarter.co.uk/newPrinttest/34-Brochures.html

there is a selection of menus on the screen that you can change select different options to show you a price.

issue is as follows; i want to be able to create url's for every product in the database for google adword purposes; for example if they click on the google ad they come direct to the page/selection from the table/drop downs that is what they want. currently we have got as far as creating the below link;

this link will take you to the product, but the drop downs from the menus haven't changed, just the price and the quantity.

i need to know of a way of selecting from the database and it be able to change the drop downs from a specific url.

our problem is we need to populate a select option in order of the one we send.

possible?

hope that makes sense!

Dani AI

Generated

Short, practical plan to make ad URLs land on a product page with the dropdowns actually preselected.

As described, you want a single link a visitor can click from an ad that shows the exact options and price. is on the right track (read GET, pull DB values) — but do that with safer, modern patterns and one of two reliable flows: server-side render or client-side apply + trigger.

Server-side (best for ads/SEO)

  • Read and strictly validate GET params (cast IDs to integers; never interpolate raw strings).
  • Query options for that product with an ORDER BY column that defines display order.
  • Render the <option> elements so the matching option includes the selected attribute; output is the canonical state the page needs.
  • If price is calculated by JavaScript on change, run the same calculation on page load or ensure the page emits the same update after you set selected.

Client-side / AJAX (if options are built dynamically)

  • Parse the query string with URLSearchParams.
  • After the AJAX that populates the <select> completes, set select.value to the requested value and dispatch a change event so existing listeners recalc price:
    const params = new URLSearchParams(location.search);
    const wanted = params.get('paper'); 
    if (wanted) {
    const sel = document.querySelector('select[name="paper"]');
    if (sel) {
      sel.value = wanted;
      sel.dispatchEvent(new Event('change'));
    }
    }

Do this safely

  • Use prepared statements (PDO/mysqli) and map URL params to option IDs (not free-form labels).
  • Validate that the requested option exists for that product; if not, fall back to a default.
  • For Google Ads, decide if each variation should be indexed or use landing parameters + canonical to avoid duplicates.

These steps keep behavior deterministic (ads show the exact selection), avoid SQL injection, and ensure the UI actually updates to match the price shown.

Ok I think im getting you. By default you already have all the information saved within your db im assuming.

So why don't you try something long these lines;

<?php

$recordId = $_GET['id'];

$query="SELECT * FROM products WHERE id='$recordId'";
$result=mysql_query($query);
$num=mysql_numrows($result); 
mysql_close();


	$i=0;
	while ($i < $num) {
	
	$f1=mysql_result($result,$i,"data");
	$f2=mysql_result($result,$i,"data2");
	$f3=mysql_result($result,$i,"data3");
	$f4=mysql_result($result,$i,"data4");


++$i;
} 

	if ( empty($f1) ) $f1 = "";

?>

<select id="item3" name="item3" value="<?php echo $f1; ?>">
    <option value="'170gsm matt'">170gsm matt</option>
    <option value="'150gsm gloss'">150gsm gloss</option>
    <option value="'130gsm gloss'">130gsm gloss</option>
</select>
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.