Jump to content

How to use a Dynamic Drop Box Results?


mark s

Recommended Posts

Hopefully the answer will help others too.

Function for the Dynamic Drop box taken from. [a href=\"http://www.phpfreaks.com/quickcode/Building-a-Dynamic-Form-Select-Menu/2.php?higlight=dynamic\" target=\"_blank\"]Click Me[/a]

How can i pass the results?

My Goal :
I have a Newsletter page.
Which shows the Dates from a database of past Newsletters.
Along with the dates i have in the database the full HTML code (Newsletter) for viewing.
I want to be able to...
Select a Date hit a button (Submit).
And the value be used to show the News letter Requested. (Same URL Just diffrent output).

Drop Box shows April 2004 with a value of 1 as its index.
So if i select April 2004 a value of 1 can be passed back for my function
to show that Newsletter.

At the moment i would just be happy to see in my URL the address + the Vaue. (1)
or what ever value is against the date selected.
And from there hopefully i can work out the rest.

[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--][i]Mod Note : I did start another topic but its just too messy please close. [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=87467\" target=\"_blank\"]Click Me[/a][/i][!--colorc--][/span][!--/colorc--]

My Working Code so Far :This is only the Dynamic Drop Box
Non of my Newsletter functions have been included.
One step at a time.

===============================================
[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]<?[!--colorc--][/span][!--/colorc--]

function catlist(){
require('connect.inc'); [!--coloro:#FF9900--][span style=\"color:#FF9900\"][!--/coloro--]// Make Connection.[!--colorc--][/span][!--/colorc--]

$mysql_link = mysql_connect( "$db_host", "$db_username", "$db_password") or die( "Unable to connect to database server");
@mysql_select_db( "$db_name") or die( "Unable to select database");
[!--coloro:#FF9900--][span style=\"color:#FF9900\"][!--/coloro--]// pull the info from cw_00 = Auto inc (1 to 25)[!--colorc--][/span][!--/colorc--]
[!--coloro:#FF9900--][span style=\"color:#FF9900\"][!--/coloro--]// Pull the info from cw_02 = Newsletter in Html[!--colorc--][/span][!--/colorc--]

$sql = mysql_query("SELECT cw_02, cw_00 FROM `cw_newsletter` WHERE `cw_06` = '1' ORDER BY `cw_00` DESC ");
echo "<select name='category_name'>";
while(list($category_name, $category_id)=mysql_fetch_array($sql)){
$category_name = stripslashes($category_name);
[!--coloro:#FF6600--][span style=\"color:#FF6600\"][!--/coloro--]// I have added $category_id to show with $category_name to show that the correct value its picked up.[!--colorc--][/span][!--/colorc--]
echo "<option value='$category_id'>$category_id $category_name</option>";
}
echo "</select>";
[!--coloro:#FF9900--][span style=\"color:#FF9900\"][!--/coloro--]// not sure what this does?[!--colorc--][/span][!--/colorc--]
mysql_free_result($sql);
}

[!--coloro:#FF9900--][span style=\"color:#FF9900\"][!--/coloro--]// The Form:[!--colorc--][/span][!--/colorc--]

echo "<form method='post' action''>
Select:";
catlist();
echo "<input type='Submit' Value='Submit'>
</form>";

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]?>[!--colorc--][/span][!--/colorc--]
=======================================

Any help on this would be appreciated,
I have spent day's going in circles and becoming more confused.

How do i pass a vaule from the drop list to be used?
I need it to show a ?value=1 after my URL so my function can use it to show that Newsletter.
[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]Thank You :)[!--colorc--][/span][!--/colorc--]
Link to comment
Share on other sites

Ive got it working :)

I have had to use some Java Script, which i really didnt want to do,
but it may be the only way to achive the results i need.

So if you have a Sigle Drop Box.
And you need the value to be used in the URL you can do this.

=====================================================
<HTML>
<body>

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]<script language="JavaScript">[!--colorc--][/span][!--/colorc--]<!--
function goto_URL(object) {
window.location.href =
object.options[object.selectedIndex].value;
return false;
}
//-->[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]</script>[!--colorc--][/span][!--/colorc--]

<form name="formName6">
<select name="selectName6">

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]<?php[!--colorc--][/span][!--/colorc--]
require('dbconnect.inc');
$mysql_link = mysql_connect( "$db_host", "$db_username", "$db_password") or die( "Unable to connect to database server");
@mysql_select_db( "$db_name") or die( "Unable to select database");

$sql = mysql_query("SELECT cw_02, cw_00 FROM `cw_newsletter` WHERE `cw_06` = '1' ORDER BY `cw_00` DESC ");


while(list($category_name, $category_id)=mysql_fetch_array($sql)){
$category_name = stripslashes($category_name);
$category_name = date("F Y", strtotime($category_name)); [!--coloro:#FF9900--][span style=\"color:#FF9900\"][!--/coloro--]// re format the output.[!--colorc--][/span][!--/colorc--]

[!--coloro:#FF9900--][span style=\"color:#FF9900\"][!--/coloro--]// I need a line output as follow to invoke a second function to display current news letter.[!--colorc--][/span][!--/colorc--]
echo "<option value='http://yourpageurl.com/index.phpaction=newsletter&id=$category_id'>$category_name</option>";
}
echo "</select>";
mysql_free_result($sql);

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]?>[!--colorc--][/span][!--/colorc--]

<input name="submitName6" type="submit" value="Go" onClick="return goto_URL(this.form.selectName6)">
</form>

==============================================================
It still needs a tidy but its working :)

If anyone knows how it can be done or if it can be done with just php ?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.