View Full Version : Jump Menu
Blue Moose Aaron
08-03-2004, 07:19 PM
I want to create a jump menu that will display the id and name of all the records in a certain table. I figured out how to do it with my individual php file, but now Im trying to get it to work with vB and templates.
Any ideas?
Revan
08-03-2004, 08:52 PM
This will most likely not work, but you can try this:
In your vb php file put summit like this:
$options .= "<option value='".$row[contents]."'>".$row[contents]."</option>";
$options .= "<option value='".$row[contents2]."'>".$row[contents2]."</option>";
Then in your template put summit like this:
<select name="selection">$options</select>
hopefully ye get the picture.
if not, then in plain words if you put .= infront of a variable you add it to the var instead of overwriting current value.
Hopefully this wasnt just me talking bs ? ;)
Blue Moose Aaron
08-04-2004, 04:27 AM
I originally had it set up like this and it displays all the records (http://www.thekryptonian.com/smallville.php)
<select onChange="location=options[selectedIndex].value;">
<option selected> Choose an Ep </option>
<?
$result = mysql_query("SELECT * FROM smallville_episode_guide ORDER BY id ASC",$db);
$php_self = $_SERVER['PHP_SELF'];
while ($myrow = mysql_fetch_array($result)) {
printf("<option value=\"%s?action=episodeguide&episode=%s\">---%s - %s</option> \n", $php_self, $myrow['id'], $myrow['id'], $myrow['episode_name']);
}
?></select>
I just need to find out how to make that code work with vB cause its not!
Revan
08-04-2004, 02:45 PM
If it works in another php file then it works with vB as well, so your problem is to ave it echo in the template.
maybe summit like this:
In your template:
<select onChange="location=options[selectedIndex].value;">
<option selected> Choose an Ep </option>
$options
</select>
In your php file:
$result = mysql_query("SELECT * FROM smallville_episode_guide ORDER BY id ASC",$db);
$php_self = $_SERVER['PHP_SELF'];
while ($myrow = mysql_fetch_array($result)) {
$options = "<option value='%s?action=episodeguide&episode=%s'>---%s - %s</option> \n", $php_self, $myrow['id'], $myrow['id'], $myrow['episode_name'];
}
Basically just stick all your episode query results into a variable, and have this echo in the template....
Blue Moose Aaron
08-04-2004, 08:44 PM
I get an error with that The , coma on this line gets me "<option value='%s?action=episodeguide&episode=%s'>---%s - %s</option> \n", $php_self, $myrow['id'], $myrow['id'], $myrow['episode_name'];
Revan
08-04-2004, 10:47 PM
Hm well then just look at other hacks/vb itself and see how they do it.
Take a look at the forumjump stuff for example, this is similar to your issue in the way that its a <select>, and its <option>'s is dynamic ;)
Blue Moose Aaron
08-04-2004, 11:16 PM
I am, but I'm having a time finding where forumjumpbits is...
Thanks for your help so far, maybe someone will come along with some idea.
On a positive note I have got it to display, the only problem left is that it is only diplaying one record rather than all of them.
Revan
08-04-2004, 11:39 PM
Did you try the .= to print all the results into the variable?
This SHOULD work because its the same concept that saved my ass in the RPG convertion ;)
AN-net
08-05-2004, 12:06 AM
you should not hardcode such things;)
here is the html:
<select onChange="location=options[selectedIndex].value;">
<option selected> Choose an Ep </option>
$options
</select>
here is php
eval('$options .= "' . fetch_template('templatename') . '";');
in that template put:
<option value="$variable1">$variable2</option>
Blue Moose Aaron
08-05-2004, 12:43 AM
Well that worked, but its only displaying one record rather than all of them. Any suggestions?
Blue Moose Aaron
08-05-2004, 12:46 AM
Here is my code
// ######################### EPISODE JUMP ############################
$ep = $DB_site->query_first("SELECT * FROM smallville_episode_guide ORDER BY id ASC");
$php_self = $_SERVER['PHP_SELF'];
$jump[id] = $ep[id];
$jump[episode_name] = $ep[episode_name];
eval("\$episodejumpbits = \"".fetch_template('smallville_episodejumpbits')."\";");
AN-net
08-05-2004, 02:05 AM
// ######################### EPISODE JUMP ############################
$ep = $DB_site->query("SELECT * FROM smallville_episode_guide ORDER BY id ASC");
$php_self = $_SERVER['PHP_SELF'];
while($jump= $DB_site->fetch_array($ep))
{
eval("\$episodejumpbits = \"".fetch_template('smallville_episodejumpbits')."\";");
}
Blue Moose Aaron
08-05-2004, 03:38 AM
Its still only showing one record
AN-net
08-05-2004, 01:15 PM
how many episodes do you have in the database?
Blue Moose Aaron
08-05-2004, 04:30 PM
its going to change as entries are added. somewhere around 65 though at the moment
AN-net
08-05-2004, 07:19 PM
if you have only one entry in that table than it will only display that entry;)
Blue Moose Aaron
08-05-2004, 07:34 PM
Yea i know, but I just said I have 65 in the table
AN-net
08-05-2004, 07:39 PM
oh, hmmm. that code should work. well i give up, ill think on it but most likely im stuck lol!
CarCdr
08-05-2004, 08:23 PM
You are overwriting the result every time with this straight assignment:
$episodejumpbits = stuff
you want to append each new bit, so use ".=" (dot equals):
$episodejumpbits .= stuff
which is the shortcut for "concatenation assignment".
Blue Moose Aaron
08-05-2004, 08:34 PM
Thank you very much. I appreciate it!
AN-net
08-05-2004, 08:42 PM
oh woops i missed that lol
CarCdr
08-05-2004, 09:10 PM
Pas de probeme. Ain't the internet great. :)
ps: AN-net -- I figured you'd gringe at missing that. :):)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.