Jump to content

How would i modify this


prcollin

Recommended Posts

I had a version of this question up before but i cant find it.  I know how to fetch arrays, but how do i get the results to populate in a drop down selection box.  I have the code for the fetch array.

 

  
mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM clients");while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";

  }mysql_close($con);
?>

Link to comment
Share on other sites

Something like....

 

<?php

  if ($result = mysql_query("SELECT * FROM clients")) {
    if (mysql_num_rows($result)) {
      echo "<form>";
      echo "  <select name=\"clients\">";
      while($row = mysql_fetch_array($result)) {
        echo "    <option value=\"{$row['id']}\">{$row['FirstName']} {$row['LastName']}</option>";
      }
      echo "  </select>";
      echo "</form>";
    }
  }

?>

Link to comment
Share on other sites

Something like....

 

<?php

  if ($result = mysql_query("SELECT * FROM clients")) {
    if (mysql_num_rows($result)) {
      echo "<form>";
      echo "  <select name=\"clients\">";
      while($row = mysql_fetch_array($result)) {
        echo "    <option value=\"{$row['id']}\">{$row['FirstName']} {$row['LastName']}</option>";
      }
      echo "  </select>";
      echo "</form>";
    }
  }

?>

 

THis shows up on the screen

 

"; while($row = mysql_fetch_array($result)) { echo " {$row['client_fname']} {$row['client_lname']}"; } echo " "; echo ""; } } ?> 

 

This is the code i used modified for my names

 

<?php

include "clientconnect.php";

  mysql_select_db('greencut_customercenter', $con);


  if ($result = mysql_query("SELECT * FROM clients")) {
    if (mysql_num_rows($result)) {
      echo "<form>";
      echo "  <select name=\"clients\">";
      while($row = mysql_fetch_array($result)) {
        echo "    <option value=\"{$row['client_lname']}\">{$row['client_fname']} {$row['client_lname']}</option>";
      }
      echo "  </select>";
      echo "</form>";
    }
  }
?>

 

and my last questions would be how to get the form to perform an action.  Can i just change

echo "<form>";

to

echo "<form action = "updateclient.php method="post">";

 

and how do i add the button for submitting here?

Link to comment
Share on other sites

THis shows up on the screen

 

"; while($row = mysql_fetch_array($result)) { echo " {$row['client_fname']} {$row['client_lname']}"; } echo " "; echo ""; } } ?> 

 

it shouldn't.

 

As for the rest of your question, seems you need some basic tutorials. theres a link in my signiture to a free book (Hudzilla), within that is an entire chapter devoted to php and forms.

Link to comment
Share on other sites

 

and my last questions would be how to get the form to perform an action.  Can i just change

echo "<form>";

to

echo "<form action = "updateclient.php method="post">";

 

and how do i add the button for submitting here?

 

Like this

echo "<form action=\"updateclient.php\" method=\"post\">";

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.