Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
wiz
Involved
Involved



Joined: Oct 09, 2006
Posts: 413
Location: UK

PostPosted: Wed Aug 05, 2009 9:16 am Reply with quote

Hi Guys
Im trying to write a module to edit clan members details. So to start with, i need a dropdown box containing the members names. this works, however then i want the selection to be passed as a variable, so that then i can use that selection to do many other things, such as more SQL queries.
So far i have........
Code:
  <tr >

  <form action="<? echo $_SERVER['PHP_SELF'];?>"  method="post">
    <select name="mem">
    <option value="New Member">New Member<br />
     <? echo $optionName ?>
    </option>
    </select><br /><br />
    <input name="Sub" type="submit" value="Fetch Info" /></form></tr>
<?
$member = $_POST["mem"];
?>


Where $optionName is my SQL array. Then i can do things like.......
Code:
<tr>

  <td background="../../themes/SAS2009/images/menu_bg.gif" height= "25" class="style1"> <? echo "Now Editing--->> " .$member; ?>
    </td>
  </tr>

Except, on clicking, it still navigates to modules.php, even though ive tried telling it to reload this script.
Rolling Eyes Rolling Eyes Rolling Eyes
 
View user's profile Send private message Visit poster's website AIM Address
fkelly
Former Moderator in Good Standing



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

PostPosted: Wed Aug 05, 2009 3:42 pm Reply with quote

Assuming that you are retrieving your users names from a MYSQL table, you need to be echoing out the option statements within the context of a while loop for each member found. You can force the first record to be "new member" by doing it outside the while loop but then each succeeding one has to be within the while loop with something like

Code:
echo '<option value="'.$row['membername'] . '">$row['membername']</option>'



Note the use of single quotes and double. The doubles are needed surrounding the values. [I edited the post several times and without having it in a PHP editor can't be sure I have it right].

Look around through the code that comes with your distribution and you will see how the option statements are formatted within while loops.

Personally, I prefer to echo almost everything instead of constantly breaking into and out of PHP but that's an individual choice.

When your form is submitted the select will have a value of whatever member name is selected.

Also, look at your code again. When you say echo $optionName what value do you intend to have in the variable $optionName? That's really the key here. You'll see a lot of Nuke code that unnecessarily assigns the value of a field to a variable as:

$optionName = $row['mydatabasefield'] or even
$optionName = somefilter($row['mydatabasefield'])

it is really unnecessary and a waste of resources unless you are need to do some fancy filtering and intend to reuse the variable at several places in the program.
 
View user's profile Send private message Visit poster's website
wiz







PostPosted: Thu Aug 06, 2009 9:59 am Reply with quote

Thanks Fkelly

The array works fine, in terms of populating the dropdown, but not when it comes to using the variable. I do intend to do lots of work with the variable, such as echo'ing who you are editing and of course the various SQL work that surrounds that user.
Here is the code for getting the value of $optionName............
Code:
 //Lets array the member

$sql="SELECT memName FROM sas_members ORDER by memName ASC";
$result=mysql_query($sql);

$optionName="";

while ($row=mysql_fetch_array($result)) {

   
    $memName=$row["memName"];
    $optionName.= "<OPTION VALUE= >".$memName;
}
// end array


hope this helps Wink
 
fkelly







PostPosted: Thu Aug 06, 2009 2:20 pm Reply with quote

Wiz. In your OPTION VALUE= statement you have the closing > before the value is echoed. You need something in the order of:

$optionName.='<option value="'.$memName.'">'

Attributes should be lowercase. You need to get your head around use of single and double quotes. The doubles are needed in html statements surrounding the value of attributes and the singles are used to force PHP to interpret the statement they surround literally.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

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 ©