PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I need a little bit of help with a peace of code. I have a drop-down box with gametitles, and want to open a infopage when I select a title. The code contain errors, but I cant find anyone.
What does the script output now? Do you see a blank screen or can you view the HTML output? What does 'view page source' from the browser show?
Does it show the SELECT element but not the values from the database?
Does the script fail with an error message?
Do you have any error handling built into the class that instantiates your $db object?
It would appear as though the code is meant to send the user to the script 'produkt.php', with a GET string spill and the value in the `sid` column, is this correct? Is the receiving script setup to handle the incoming GET string?
The page functions like before, but the pop-up does not function. I get the drop-down, but when I click on the "open"-button does nothing happens.
$db is a part of mye CPG, and the script with the drop-down func great. Its just the script to get av pop-up page that not function.
produkt = product
spill = game
sid = unique id for each line in the db table.
The drop-down box is a part of a newsscript, and I want this script to open the games info page for the author, to get information about the game quick. When I click on the button I want to go to http://www.gamersmix.no/produkt.php?spill=$sid ($sid = uniqe ID for game).
Ok, well let's take a look at just the window.open code (although this is JS, not PHP). When I build a script like this, I like to take each element and output on it's own line, so it's easier to spot problems, and easier to edit code. So here's my rendition of your code, with a potential JS fix:
Changed the string passed to the URL to simply the value of document.catForm.assotop, I see no reason to utilize getElementById here. Also used a semicolon at the end of window.open to end the statement.
Did you test with databasequery, or just "offline". I have test the original without query for db, and it function then. Its when I want to fetch the list for my DB i get problems.
1) Copied the script and dropped the DB query. It works.
Source:
<?php
echo '<form id="catForm">';
echo '<SELECT style="WIDTH: 313px" name=assotop width="80%">';
echo "<OPTION value=0 selected>Hent spill fra databasen</OPTION><OPTION value=310>187 Ride or Die [310]</OPTION> <OPTION value=628>2006 FIFA World Cup [628]</OPTION> <OPTION value=201>24: The Game [201]</OPTION> <OPTION value=226>25 to Life [226]</OPTION> <OPTION value=580>50 Cent Bulletproof [580]</OPTION> <OPTION value=405>7 sins [405]</OPTION> <OPTION value=241>Ace Combat 5: Squadron Leader [241]</OPTION> <OPTION value=649>Ace Combat X: Skies of Deception [649]</OPTION> <OPTION value=679>Ace Combat Zero: The Belkan War [679]</OPTION> <OPTION value=145>Act of War: Direct Action [145]</OPTION> <OPTION value=60>Advent Rising [60]</OPTION> <OPTION value=256>Age of Conan: Hyborian Adventures [256]</OPTION> <OPTION value=162>Age of Empires III: Age of Discovery [162]</OPTION> <OPTION value=732>Age of Empires: The Age of Kings [732]</OPTION> <OPTION value=450>Age of Pirates: Captain Blood [450]</OPTION> <OPTION value=448>Alan Wake [448]</OPTION> <OPTION value=733>Alex Rider Stormbreaker [733]</OPTION> <OPTION value=61>Alexander the Great [61]</OPTION> <OPTION value=491>All Points Bulletin [491]</OPTION>";
echo "</select> <button name=click OnClick=\"window.open('produkt.php?spill='+document.getElementById('catForm').assotop.value)\">Produktside!</button></font></form>";
?>
Is it the db connection that is wrong?
2) Scriptsource
<form id="catForm"><SELECT style='WIDTH: 313px' name='assotop' width='80%'><option value='0'> Hent spill fra databasen </option><option value='310'>187 Ride or Die [310]</option>
<option value='628'>2006 FIFA World Cup [628]</option>
<option value='201'>24: The Game [201]</option>
<option value='226'>25 to Life [226]</option>
<option value='580'>50 Cent Bulletproof [580]</option>
</select><button name='click' OnClick="window.open('produkt.php?spill='+document.catForm.assotop.options.selectedIndex);">Produktside!</button></font></form>
Last edited by Trash2000 on Sat Jun 03, 2006 8:15 pm, edited 2 times in total.
Trash2000, first of all edit your posts and wrap [ syntax="php"][/syntax] & [ syntax="html"][/syntax] tags around your php code & html output respectively and secondly swearing is seriously discouraged as these are public fourms. People from all age groups visit these forums.
As for your question, can you point to a live one somewhere online?