Jump to content

Exploding DATA and Multiple Input with same Name


cry of war

Recommended Posts

i was wondering if i was doing this right and if there is a better way to do it because if someone puts a ";" ":" or "|" in the input im going to be in some trouble. I just came up with this and doubt it will work the way im thinking it will so I need you guys help to figure out a way to do this any help no matter how small it is would be great.

 

 

 

If (!isset($i)){ $i=1; }

$string="Name:Nathan;Age:18;Nikname:Nate;Nikname:Nat|Name:Logan;Age:19;Nikname:Logg;Nikname:Buckwheat"

$string= explode("|", $string);

 

 

echo $string['0'];/*=>Name:Nathan;Age:18;Nikname:Nate;Nikname:Nat*/

echo $string['1'];/*=>Name:Logan;Age:19;Nikname:Logg;Nikname:Buckwheat*/

 

 

foreach ($string as $string) {

$string= explode(";", $string);

}

 

 

echo $string['0']['0'];/*=>Name:Nathan*/

echo $string['0']['1'];/*=>Age:18*/

echo $string['0']['2'];/*=>Nikname:Nate*/

echo $string['0']['3'];/*=>Nikname:Nat*/

echo $string['1']['0'];/*=>Name:Logan*/

echo $string['1']['1'];/*=>Age:19*/

echo $string['1']['2'];/*=>Nikname:Logg*/

echo $string['1']['3'];/*=>Nikname:Buckwheat*/

 

foreach ($string as $string) {

$string= explode(":", $string);

}

 

echo $string['0']['0']['0'];/*=>Name*/

echo $string['0']['0']['1'];/*=>Nathan*/

echo $string['0']['1']['0'];/*=>Age*/

echo $string['0']['1']['1'];/*=>18*/

echo $string['0']['2']['0'];/*=>Nikname*/

echo $string['0']['2']['1'];/*=>Nate*/

echo $string['0']['3']['0'];/*=>Nikname*/

echo $string['0']['3']['1'];/*=>Nat*/

echo $string['1']['0']['0'];/*=>Name*/

echo $string['1']['0']['1'];/*=>Logan*/

echo $string['1']['1']['0'];/*=>Age*/

echo $string['1']['1']['1'];/*=>19*/

echo $string['1']['2']['0'];/*=>Nikname*/

echo $string['1']['2']['1'];/*=>Logg*/

echo $string['1']['3']['0'];/*=>Nikname*/

echo $string['1']['3']['1'];/*=>Buckwheat*/

 

 

 

And the other question i have is what happens if i have 1 or more

 

<input type="text" Name="blah"><input type="text" Name="blah"><input type="submit" name="Submit" value="Submit">

 

 

 

what happens to $_POST['blah'] on submit?

Link to comment
Share on other sites

Well the source is coming from a peice of data extracted from the Database i need to find a way to break the string into parts so i can display it correctly I would set up tables for this but they wont be able to be dynamic enough to hold all the info and would start to get really messy. The Code will go something like this.

 

<?php

$result=mysql_query("SELECT * FROM USERDATA WHERE ID=$_SESSION['ID']", $link);

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

echo "".$row['FirstName']."<br>";

echo "".$row['MiddleName']."<br>";

echo "".$row['LastName']."<br>";

 

echo "Friends";

 

If (!isset($i)){ $i=1; }

$string=$row['String'];/*Name:Nathan;Age:18;Nikname:Nate;Nikname:Nat|Name:Logan;Age:19;Nikname:Logg;Nikname:Buckwheat*/

$string= explode("|", $string);

 

foreach ($string as $string) {

    $string= explode(";", $string);

}

 

foreach ($string as $string) {

    $string= explode(":", $string);

}

 

/*Display the String info??????*/

 

}

?>

Link to comment
Share on other sites

because the information inside that string is always changing my database would look like this

 

UserTable

 

ID

Name

String

 

 

Or with setting up tables instead of the string

 

UserTable

ID

Name

Age

 

FriendTable

ID

FriendsID

 

NiknameTable

ID

Nikname

 

<?php

$result=mysql_query("Select * from FriendTable where 'ID'=$_SESSION['ID']", $link);

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

$FriendsID=array($row['FriendsID']);

$Friends=array_merge($array,$FriendsID);

}

 

foreach ($Friends as $Friends) {

$result=mysql_query("Select * from NikenameTable where 'ID'=$Friends", $link);

Echo "NikNames of friends with ID of:".$row['ID']."";

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

Echo "".$row['Nikname']."<br>";

}

echo "<hr>";

}

?>

 

 

Or is there a different way to do that Im only good at the logic of php not the backend stuff with this SQL and table set up  :P

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.