Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
Dawg
RavenNuke(tm) Development Team


Joined: Nov 07, 2003
Posts: 910

PostPosted: Fri Feb 22, 2008 3:57 pm Reply with quote

Greetings All,
I am having a problem with an "Edit" form I created. Here is the deal....

When I hit edit....I call the DB and and pull the values for that ID. Those values are droped into a Form to be edited....

One of those values is TID (Town ID#)
When I hit the edit for TID I make another call to the DB to pull all the availible towns into a dropdown to be selected.

My question is How do I preselect one of those (I want it preset to the existing TID) I know how to do this with a simple form and I am guessing that I need to explode TID,Value and then do something....that is where I lose it. HEre is my existing code....

TID is already set before this is called....

Code:
     

echo "<select name=\"tid\">";
$querystr = "SELECT tid,town_name FROM ".$prefix."_towns";
   $resultboats = sql_query($querystr, $dbi)
   or die ("Invalid query in cselect");
   for ($m=0; $m < sql_num_rows($resultb, $dbi); $m++)
   {
      list($tid,$town_name) = sql_fetch_row($resultb, $dbi);
    echo "$tid,$town_name";

echo "<option name=\"tid\" value='$tid'>$town_name</option>";
     }
echo "</select><br><br>";


My small little brain implodes when I try to think this one through....

HELP!

Thank You for your time!!

Dawg
 
View user's profile Send private message
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Fri Feb 22, 2008 4:30 pm Reply with quote

Use the "selected" parameter inside whichever option you want as the default.

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Gremmie
Former Moderator in Good Standing


Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Fri Feb 22, 2008 4:47 pm Reply with quote

Yeah, one way to do it is to add code inside the loop that tests the $tid you just pulled out of the database. If it is the one you want selected, then add selected="selected" (for XHTML compliance) to your <option> tag.

Code:


$selected = ($tid == $target) ? 'selected="selected"' : '';
echo "<option name=\"$tid\" value=\"$tid\" $selected>$town_name</option>";

_________________
Only registered users can see links on this board! Get registered or login! - An Event Calendar for PHP-Nuke
Only registered users can see links on this board! Get registered or login! - A Google Maps Nuke Module 
View user's profile Send private message
fkelly
Former Moderator in Good Standing


Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Fri Feb 22, 2008 4:52 pm Reply with quote

There are many examples of what Evaders referred to in your RN distribution. I know it always helps me to have an example. For instance from /admin/modules.php at about line 281:

Code:
      while(list($gid, $gname) = $db->sql_fetchrow($groupsResult)) {

         if(in_array($gid,$ingroups)) { $sel = ' selected="selected"'; } else { $sel = ''; }
         echo '<option value="'.$gid.'"'.$sel.'>'.$gname.'</option>';
      }


Note that you need the double quotes around the attribute selected ... I'd highly recommend both looking at the view source and running the screen thru the W3C validator since it is easy to make a syntax mistake dealing with quotes like that.
 
View user's profile Send private message Visit poster's website
Dawg
PostPosted: Fri Feb 22, 2008 5:26 pm Reply with quote

Sweet Guys THANK YOU!

I was stuck there. I knew about selected.....but not how I get it to come out in the right place.

fkelly, You are right about examples. I have to have them. It is the only way I learn well.

Thank You all again!

Dawg
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©