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
https://forums.phpfreaks.com/topic/117004-how-would-i-modify-this/
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>";
    }
  }

?>

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?

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.

 

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\">";

 

Archived

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

×
×
  • 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.