Jump to content

mysql with explode


hansman

Recommended Posts

Hello,

 

i currently ran into major problems not thiking this scheme out and realized that its not possible, maybe someone could help me

 

I have a table "ad" with fields like, State, County, Name, Username, Passoword, City.

 

i have a drop down menu where a user can select their state, and a list of countys that have been entered for that state is listed. Once they click the county it shows all the names in the county. This works no problem.

 

However, when i insert the "County" with mutiple names such as "county1, county2), i can use the explode() function but i need to insert them into the "County" field and make sure it is not a duplicate.

 

I was thinking i would need to make another table with countys, states and then link it to the table "ad" by "name"

 

any ideas how i can do this?

Link to comment
https://forums.phpfreaks.com/topic/115416-mysql-with-explode/
Share on other sites

hi

use comma-separate-list or checkbox to insert,

<?
if (isset($insNumRows)) {
  for ($I=1; $I<=$insNumRows; $I++) {
    if (isset($_POST["county$I"]) && is_array($_POST["county$I"])) {
      $_POST["county$I"] = implode(",", $_POST["county$I"]);
      $HTTP_POST_VARS["county$I"] = $_POST["county$I"];
    }
  }
}
?>

 

regards

Link to comment
https://forums.phpfreaks.com/topic/115416-mysql-with-explode/#findComment-593323
Share on other sites

"county " specifying the name of the multiple selection element and ","  the delimiter to use.

<?
if (isset($insNumRows)) {
  for ($I=1; $I<=$insNumRows; $I++) {
    if (isset($_POST["county$I"]) && is_array($_POST["county$I"])) {
---------------------------^ name of your menu/list---------^
      $_POST["county$I"] = implode(",", $_POST["county$I"]);
-----------------^ name of your menu/list ------------^
         $HTTP_POST_VARS["county$I"] = $_POST["county$I"];
------------------------------^ name of your menu/list---^
    }
  }
}

?>

and in your form --> if the name of the filed is "county", you will change it as "county[]" otherwise php will recognize only one selection.

 

Link to comment
https://forums.phpfreaks.com/topic/115416-mysql-with-explode/#findComment-593397
Share on other sites

Does this make sense?

The form value is county[]

i tired it out and the valuse of county is set to "Array"

 

 

$state = $_SESSION['state']; 
$name=$_POST['name'];
$email=$_POST['email'];
$state=$_POST['state'];
$user=$_POST['user'];

if (isset($insNumRows)) {
  for ($I=1; $I<=$insNumRows; $I++) {
    if (isset($_POST["county$I"]) && is_array($_POST["county$I"])) {
      $_POST["county$I"] = implode(",", $_POST["county$I"]);
      $HTTP_POST_VARS["county$I"] = $_POST["county$I"];
    }
  }
}

$password=$_POST['password'];




$sql="INSERT INTO ad (name, email, county, state, user, password)VALUES('$name', '$email', '$county', '$state', '$user', '$password')";

Link to comment
https://forums.phpfreaks.com/topic/115416-mysql-with-explode/#findComment-593416
Share on other sites

  <form action="insertadnow.php" method="post">
      <p align="center">Company Name:<br />
      <input name="name" type="text" />
      <br />
      
      <p align="center">State:<br /> 
        <select name="state"> 
<option>AK</option>
<option>AL</option>
<option>AR</option>
<option>AZ</option>
<option>CA</option>
<option>CO</option>
<option>CT</option>
<option>DE</option>
<option>FL</option>
<option>GA</option>
<option>HI</option>
<option>IA</option>
<option>ID</option>
<option>IL</option>
<option>IN</option>
<option>KS</option>
<option>KY</option>
<option>LA</option>
<option>MA</option>
<option>MD</option>
<option>ME</option>
<option>MI</option>
<option>MN</option>
<option>MO</option>
<option>MS</option>
<option>MT</option>
<option>NC</option>
<option>ND</option>
<option>NE</option>
<option>NH</option>
<option>NJ</option>
<option>NM</option>
<option>NV</option>
<option>NY</option>
<option>OH</option>
<option>OK</option>
<option>OR</option>
<option>PA</option>
<option>RI</option>
<option>SC</option>
<option>SD</option>
<option>TN</option>
<option>TX</option>
<option>UT</option>
<option>VA</option>
<option>WA</option>
<option>WI</option>
<option>WV</option>
<option>WY</option>
        </select>
      <p align="center">County:<br />
        <input name="county[]" type="text" id="county[]" />
      <p align="center">Contact Email:	<br />
        <input name="email" type="text" />
                <p align="center">Username Desired:                
                <input name="user" type="text" id="user" />
                <p align="center">Password Desired:
                  <input name="password" type="text" id="password" />
<p align="center">
                  <label>
                  <input type="submit" name="submit" id="submit" value="Submit" />
                  </label>
                
    </form>

Link to comment
https://forums.phpfreaks.com/topic/115416-mysql-with-explode/#findComment-593580
Share on other sites

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.