Jump to content

Archived

This topic is now archived and is closed to further replies.

ivan2234

Enter db from help needed...

Recommended Posts

Hello everyone. I've been having trouble with this one issue for a while now so i decided to ask here and see if someone could help me. I have a form on my site which i use for entering info into a mysql databse. And on the form i have a drop down list where i can chose which search engine someone used to find the site. Now it all works ok and it enteres the data into the database allright. But the problem is when i go to edit this info the drop down list jumps back to showing it's default value instead of showing the value entered in the databse. Now to illustrate. Let's say the box has the following info:
Google
Yahoo
MSN
and now i chose let's say Yahoo and it gets entered in the databse. Now when i got back to that page the drop down box doesn't show Yahoo anymore but goes back to it's default value Google. Here is the code i use:

[code]<select name="search_engine">
    <option value="<a href="http://www.google.com">Google</a>">Google</option>
    <option value="<a href="http://www.yahoo.com">Yahoo</a>">Yahoo</option>
    <option value="<a href="http://www.msn.com">MSN</a>">MSN</option><?php echo $search_engine ?>
  </select>[/code]

Share this post


Link to post
Share on other sites
Where is the part of the code that performs the query to retrieve the data? Where in your code do you specify that depending on the query results, that option will be the selected option in the dropdown?

Share this post


Link to post
Share on other sites
It's easier to handle drop-downs if the options are in an array ... but basically what you need to do is use the selected='selected' option attribute when the search engine in the database is the same as the search engine option in the dropdown.  For the Yahoo selected option, you need your rendered html to look like

[code]<option value="<a href="http://www.yahoo.com">Yahoo</a>" selected='selected'>Yahoo</option>[/code]

Share this post


Link to post
Share on other sites
So how would i put html code into an array? I have so far only managed to make a drop down list from an array with normal text but not with html code.

[code]$options = array('Google', 'Yahoo', 'MSN');[/code]

This is what i manage how would i feed the html code into an array?

Share this post


Link to post
Share on other sites
[code]<?php
$search_engine = "Yahoo"; // example - your selected record

$options = array('Google', 'Yahoo', 'MSN');
$urls = array('www.google.com','www.yahoo.com','www.msn.com');

echo "<form>\n";
echo "<select name='search_engine'>\n";
for ($i=0;$i<count($options);$i++) {
echo "<option value=\"<a href=\'http:". $urls[$i]. "'". "</a>\"";
if ($options[$i]==$search_engine) {
echo " selected='selected'";
}
echo ">". $options[$i]. "</option>\n";
}
echo "</select>\n";
echo "</form>";
?>[/code]

Share this post


Link to post
Share on other sites
Thnx for helping me out however the code you gave me doesn't seem to work correctly. It inputs in the database per example if yahoo is selected:
[code]<a href=\'http:www.yahoo.com'</a>[/code] instead of [code]<a href="http://www.yahoo.com">Yahoo</a>[/code]

Share this post


Link to post
Share on other sites
Just on this line....

echo "<option value=\"<a href=\'http:". $urls[$i]. "'". "</a>\"";

change to...

echo "<option value=\"<a href=\'http:". $urls[$i]. "'>" . $options[$i] . "</a>\"";

Share this post


Link to post
Share on other sites
Now it shows:

[code]<a href=\'http:www.yahoo.com'>Yahoo</a>[/code]

SOrry for being such a pain but if you cold help... Thnx

Share this post


Link to post
Share on other sites
try this: this will add the 2 slashes i think
echo "<option value=\"<a href=http:\/\/". $urls[$i]. ">" . $options[$i] . "[/url]\"";

if not use this
echo "<option value=\"<a href=http:". $urls[$i]. ">" . $options[$i] . "[/url]\"";

Share this post


Link to post
Share on other sites
Well today doesn't seem to be my day nothing seems to work. But let's just dump all of that <a href="....
How do i change this:

echo "<option value=\"<a href=\'http:". $urls[$i]. "'". "</a>\"";

so that the value includes only $urls[$i] without the <a href etc. stuff?

Share this post


Link to post
Share on other sites
hmm... um you should proably get a book or something (no offense) but maybe you should go over the basics abit more...


heres the code anyways

[code]echo "<option value=\"$urls[$i]">;[/code]

Share this post


Link to post
Share on other sites
I guess i could, but i decided to scratch this code altogether and make up something else. Only problem i have with this is that it takes ages for it to be processed. So what i am asking for now is, is there a way to speed up this script execution. And again thnx for the help. The code is bellow:

[code]<?php





$b[0][0] = "TOS/toseny1.jpg";
$b[0][1] = "TOS Ensign Yellow";
$b[1][0] = "TOS/tosenr1.jpg";
$b[1][1] = "TOS Ensign Red";
$b[2][0] = "TOS/tosenb1.jpg";
$b[2][1] = "TOS Ensign Teal";
$b[3][0] = "TOS/tosltjgy2.jpg";
$b[3][1] = "TOS Lieutenant Jg. Yellow";
$b[4][0] = "TOS/tosltjgr2.jpg" ;
$b[4][1] = "TOS Lieutenant Jg. Red";
$b[5][0] = "TOS/tosltjgb2.jpg";
$b[5][1] = "TOS Lieutenant Jg. Teal";
$b[6][0] = "TOS/toslty3.jpg";
$b[6][1] = "TOS Lieutenant Yellow";
$b[7][0] = "TOS/tosltr3.jpg";
$b[7][1] = "TOS Lieutenant Red";
$b[8][0] = "TOS/tosltb3.jpg";
$b[8][1] = "TOS Lieutenant Teal";
$b[9][0] = "TOS/tosltcy4.jpg" ;
$b[9][1] = "TOS Lt. Commander Yellow";
$b[10][0] = "TOS/tosltcr4.jpg" ;
$b[10][1] = "TOS Lt. Commander Red";
$b[11][0] = "TOS/tosltcb4.jpg";
$b[11][1] = "TOS Lt. Commander Teal";
$b[12][0] = "TOS/toscmdry5.jpg";
$b[12][1] = "TOS Commander Yellow";
$b[13][0] = "TOS/toscmdrr5.jpg";
$b[13][1] = "TOS Commander Red";
$b[14][0] = "TOS/toscmdrb5.jpg";
$b[14][1] = "TOS Commander Teal";
$b[15][0] = "TOS/toscmdry51st.jpg";
$b[15][1] = "TOS Commander 1st Class Yellow";
$b[16][0] = "TOS/toscmdrr51st.jpg";
$b[16][1] = "TOS Commander 1st Class Red";
$b[17][0] = "TOS/toscmdrb51st.jpg";
$b[17][1] = "TOS Commander 1st Class Teal";
$b[18][0] = "TOS/toscpty6.jpg";
$b[18][1] = "TOS Captain Yellow";
$b[19][0] = "TOS/toscptr6.jpg";
$b[19][1] = "TOS Captain Red";
$b[20][0] = "TOS/toscptb6.jpg";
$b[20][1] = "TOS Captain Teal";
$b[21][0] = "TOS/toscoy8.jpg" ;
$b[21][1] = "TOS Commodore Yellow";
$b[22][0] = "TOS/toscor8.jpg";
$b[22][1] = "TOS Commodore Red";
$b[23][0] = "TOS/toscob8.jpg";
$b[23][1] = "TOS Commodore Teal";
$b[24][0] = "TOS/tosya1.jpg";
$b[24][1] = "TOS Rear Admiral";
$b[25][0] = "TOS/tosya2.jpg";
$b[25][1] = "TOS Vice Admiral";
$b[26][0] = "TOS/tosya3.jpg";
$b[26][1] = "TOS Admiral";
$b[27][0] = "TOS/tosya4.jpg";
$b[27][1] = "TOS Fleet Admiral";
$b[28][0] = "TOS/tosya5.jpg";
$b[28][1] = "TOS Commander Star Fleet";
$b[29][0] = "TOS/tosw4.jpg";
$b[29][1] = "TOS Crewman";
$b[30][0] = "TOS/tosw5.jpg";
$b[30][1] = "TOS Petty Officer Second Class";
$b[31][0] = "TOS/tosw6.jpg";
$b[31][1] = "TOS Petty Officer First Class";
$b[32][0] = "TOS/tosw7.jpg";
$b[32][1] = "TOS Chief Petty Officer";
$b[33][0] = "TOS/tosw8.jpg";
$b[33][1] = "TOS Chief Petty Officer First Class";
$b[34][0] = "TOS/tosw9.jpg";
$b[34][1] = "TOS Master Chief Petty Officer";
$b[35][0] = "enterprise/yensign.jpg";
$b[35][1] = "Enterprise Ensign Yellow";
$b[36][0] = "enterprise/rensign.jpg";
$b[36][1] = "Enterprise Ensign Red";
$b[37][0] = "enterprise/tensign.jpg";
$b[37][1] = "Enterprise Ensign Teal";
$b[38][0] = "enterprise/yltjg.jpg";
$b[38][1] = "Enterprise Lieutenant Jg. Yellow";
$b[39][0] = "enterprise/rltjg.jpg";
$b[39][1] = "Enterprise Lieutenant Jg. Red";
$b[40][0] = "enterprise/tltjg.jpg";
$b[40][1] = "Enterprise Lieutenant Jg. Teal";
$b[41][0] = "enterprise/ylt.jpg";
$b[41][1] = "Enterprise Lieutenant Yellow";
$b[42][0] = "enterprise/rlt.jpg";
$b[42][1] = "Enterprise Lieutenant Red";
$b[43][0] = "enterprise/tlt.jpg";
$b[43][1] = "Enterprise Lieutenant Teal";
$b[44][0] = "enterprise/yltcmdr.jpg";
$b[44][1] = "Enterprise Lt. Commander Yellow";
$b[45][0] = "enterprise/rltcmdr.jpg";
$b[45][1] = "Enterprise Lt. Commander Red";
$b[46][0] = "enterprise/tltcmdr.jpg";
$b[46][1] = "Enterprise Lt. Commander Teal";
$b[47][0] = "enterprise/ycmdr.jpg";
$b[47][1] = "Enterprise Commander Yellow";
$b[48][0] = "enterprise/rcmdr.jpg";
$b[48][1] = "Enterprise Commander Red";
$b[49][0] = "enterprise/tcmdr.jpg";
$b[49][1] = "Enterprise Commander Teal";
$b[50][0] = "enterprise/ycmdr1st.jpg";
$b[50][1] = "Enterprise Commander 1st Class Yellow";
$b[51][0] = "enterprise/rcmdr1st.jpg";
$b[51][1] = "Enterprise Commander 1st Class Red";
$b[52][0] = "enterprise/tcmdr1st.jpg";
$b[52][1] = "Enterprise Commander 1st Class Teal";
$b[53][0] = "enterprise/ycpt.jpg";
$b[53][1] = "Enterprise Captain Yellow";
$b[54][0] = "enterprise/rcpt.jpg";
$b[54][1] = "Enterprise Captain Red";
$b[55][0] = "enterprise/tcpt.jpg";
$b[55][1] = "Enterprise Captain Teal";
$b[56][0] = "enterprise/flecpt.jpg";
$b[56][1] = "Enterprise Commodore";
$b[57][0] = "enterprise/flagcomm.jpg";
$b[57][1] = "Enterprise Rear Admiral";
$b[58][0] = "enterprise/flagradm.jpg";
$b[58][1] = "Enterprise Vice Admiral";
$b[59][0] = "enterprise/flagviceadm.jpg";
$b[59][1] = "Enterprise Admiral";
$b[60][0] = "enterprise/flagadm.jpg";
$b[60][1] = "Enterprise Fleet Admiral";
$b[61][0] = "enterprise/flagfadm.jpg";
$b[61][1] = "Enterprise Commander Star Fleet";
$b[62][0] = "enterprise/macoo1.jpg";
$b[62][1] = "Enterprise Marine 2nd Lieutenant";
$b[63][0] = "enterprise/macoo2.jpg";
$b[63][1] = "Enterprise Marine 1st Lieutenant";
$b[64][0] = "enterprise/macoo3.jpg";
$b[64][1] = "Enterprise Marine Captain" ;
$b[65][0] = "enterprise/macoo4.jpg";
$b[65][1] = "Enterprise Marine Major";
$b[66][0] = "enterprise/macoo5.jpg";
$b[66][1] = "Enterprise Marine Lieutenant Colonel";
$b[67][0] = "enterprise/macoo51st.jpg";
$b[67][1] = "Enterprise Marine Lieutenant Colonel 1st Class";
$b[68][0] = "enterprise/macoo6.jpg";
$b[68][1] = "Enterprise Marine Colonel";
$b[69][0] = "ensignred.jpg";
$b[69][1] = "Ensign Red";
$b[70][0] = "ensignteal.jpg";
$b[70][1] = "Ensign Teal";
$b[71][0] = "ensignyellow.jpg";
$b[71][1] = "Ensign Yellow";
$b[72][0] = "ensignwhite.jpg";
$b[72][1] = "Ensign White";
$b[73][0] = "ltjgred.jpg";
$b[73][1] = "Lieutenant Jg. Red";
$b[74][0] = "ltjgteal.jpg";
$b[74][1] = "Lieutenant Jg. Teal";
$b[75][0] = "ltjgyellow.jpg";
$b[75][1] = "Lieutenant Jg. Yellow";
$b[76][0] = "ltjgwhite.jpg";
$b[76][1] = "Lieutenant Jg. White";
$b[77][0] = "lieutred.jpg";
$b[77][1] = "Lieutenant Red";
$b[78][0] = "lieutteal.jpg";
$b[78][1] = "Lieutenant Teal";
$b[79][0] = "lieutyellow.jpg";
$b[79][1] = "Lieutenant Yellow";
$b[80][0] = "lieutwhite.jpg";
$b[80][1] = "Lieutenant White";
$b[81][0] = "ltcmdrred.jpg";
$b[81][1] = "Lt. Commander Red";
$b[82][0] = "ltcmdrteal.jpg";
$b[82][1] = "Lt. Commander Teal";
$b[83][0] = "ltcmdryellow.jpg";
$b[83][1] = "Lt. Commander Yellow";
$b[84][0] = "ltcmdrwhite.jpg";
$b[84][1] = "Lt. Commander White";
$b[85][0] = "cmdrred.jpg";
$b[85][1] = "Commander Red";
$b[86][0] = "cmdrteal.jpg";
$b[86][1] = "Commander Teal";
$b[87][0] = "cmdryellow.jpg";
$b[87][1] = "Commander Yellow";
$b[88][0] = "cmdrwhite.jpg";
$b[88][1] = "Commander White";
$b[89][0] = "cmdr1red.jpg";
$b[89][1] = "Commander 1st Class Red";
$b[90][0] = "cmdr1teal.jpg";
$b[90][1] = "Commander 1st Class Teal";
$b[91][0] = "cmdr1yellow.jpg";
$b[91][1] = "Commander 1st Class Yellow";
$b[92][0] = "cmdr1white.jpg";
$b[92][1] = "Commander 1st Class White";
$b[93][0] = "captainred.jpg";
$b[93][1] = "Captain Red";
$b[94][0] = "captainwhite.jpg" ;
$b[94][1] = "Captain White";
$b[95][0] = "commodore.jpg" ;
$b[95][1] = "Commodore Red";
$b[96][0] = "commodorewhite.jpg" ;
$b[96][1] = "Commodore White";
$b[97][0] = "rearadm.jpg Rear";
$b[97][1] = "Admiral Red";
$b[98][0] = "rearadmwhite.jpg" ;
$b[98][1] = "Rear Admiral White";
$b[99][0] = "viceadm.jpg" ;
$b[99][1] = "Vice Admiral Red";
$b[100][0] = "viceadm.jpg";
$b[100][1] = "Vice Admiral White";
$b[101][0] = "admiral.jpg";
$b[101][1] = "Admiral Red";
$b[102][0] = "admiralwhite.jpg";
$b[102][1] = "Admiral White";
$b[103][0] = "fleetadm.jpg";
$b[103][1] = "Fleet Admiral Red";
$b[104][0] = "fleetadmwhite.jpg";
$b[104][1] = "Fleet Admiral White";
$b[105][0] = "sectadm.jpg";
$b[105][1] = "Section Admiral Red";
$b[106][0] = "sectadmwhite.jpg";
$b[106][1] = "Section Admiral White";
$b[107][0] = "m2ndlt.jpg";
$b[107][1] = "Marine 2nd Lieutenant";
$b[108][0] = "m1stlt.jpg";
$b[108][1] = "Marine 1st Lieutenant";
$b[109][0] = "mcapt.jpg";
$b[109][1] = "Marine Captain";
$b[110][0] = "major.jpg";
$b[110][1] = "Marine Major";
$b[111][0] = "mltcol.jpg";
$b[111][1] = "Marine Lieutenant Colonel";
$b[112][0] = "mcol.jpg";
$b[112][1] = "Marine Lieutenant Colonel 1st Class";
$b[113][0] = "mfcol.jpg";
$b[113][1] = "Marine Colonel";
$b[114][0] = "msgtmajorgen.jpg";
$b[114][1] = "Marine Brigadier";
$b[115][0] = "mbgen.jpg";
$b[115][1] = "Marine Brigadier General";
$b[116][0] = "mMajGen.jpg";
$b[116][1] = "Marine Major General";
$b[117][0] = "mLtgen.jpg";
$b[117][1] = "Marine Lieutenant General";
$b[118][0] = "mgen.jpg";
$b[118][1] = "Marine General";
$b[119][0] = "mFMar.jpg";
$b[119][1] = "Marine Field Marshall";
$b[120][0] = "Civil1.jpg" ;
$b[120][1] = "Civilian Rating 1";
$b[121][0] = "Civil2.jpg" ;
$b[121][1] = "Civilian Rating 2";
$b[122][0] = "Civil3.jpg" ;
$b[122][1] = "Civilian Rating 3";
$b[123][0] = "Civil4.jpg";
$b[123][1] = "Civilian Rating 4";
$b[124][0] = "Civil5.jpg" ;
$b[124][1] = "Civilian Rating 5";
$b[125][0] = "Civil6.jpg" ;
$b[125][1] = "Civilian Rating 6";
$b[126][0] = "Civil7.jpg";
$b[126][1] = "Governor Civilian Rating 7";
$b[127][0] = "Ambas1.jpg" ;
$b[127][0] = "Ambassador Rating 1";
$b[128][0] = "Ambas2.jpg" ;
$b[128][0] = "Ambassador Rating 2";
$b[129][0] = "Ambas3.jpg" ;
$b[129][0] = "Ambassador Rating 3";
$b[130][0] = "Ambas4.jpg" ;
$b[130][0] = "Ambassador Rating 4";
$b[131][0] = "Ambas5.jpg" ;
$b[131][0] = "Ambassador Rating 5";
$b[132][0] = "Ambas6.jpg";
$b[132][0] = "Ambassador Rating 6";

echo "<select name=\"rank_image\">";//uncomment this line when you want it to work
foreach ($b as $bb1)
{

echo "<pre>b = ",var_dump($b),"</pre><br>\n";
echo "<pre>bb1 = ",var_dump($bb1),"</pre><br>\n";


echo "bb1 = ",var_dump($bb1),"<br>\n";
echo "bb2 = ",var_dump($bb2),"<br>\n";
echo "<pre>\$rank_image = ",var_dump($rank_image),"</pre><br>\n";
if ($bb1[0] == $rank_image) //$state holds a two-letter acronym (i.e: "AL")

{
$sel_text1 = " selected ";
}
else
{
$sel_text1 = " ";
}
echo "<option value=$bb1[0]".$sel_text1.">".$bb1[1]."</option>";


}
echo "</select>";
?>[/code]

Share this post


Link to post
Share on other sites

×

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.