cry of war Posted March 7, 2008 Share Posted March 7, 2008 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? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 7, 2008 Share Posted March 7, 2008 well since in your example your defining the variable to be exploded I don't see an issue. Now if u showed us the source the data is really comming from we can help probably Quote Link to comment Share on other sites More sharing options...
cry of war Posted March 7, 2008 Author Share Posted March 7, 2008 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??????*/ } ?> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 7, 2008 Share Posted March 7, 2008 well why not build the database properly with fields??? Quote Link to comment Share on other sites More sharing options...
cry of war Posted March 7, 2008 Author Share Posted March 7, 2008 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 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 7, 2008 Share Posted March 7, 2008 read up on proper DB setup this can be done very easily Quote Link to comment Share on other sites More sharing options...
cry of war Posted March 7, 2008 Author Share Posted March 7, 2008 got a link all the ones i find just show me very very basic table set up i need something a little more beefy Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.