catri3l Posted August 6, 2008 Share Posted August 6, 2008 Hey guys. I have this function: if(isset($_POST['itemOrder'])){ $items = explode(";",$_POST['itemOrder']); for($no=0;$no<count($items);$no++){ mysql_query("UPDATE groups SET article1 = '$no' WHERE group_id ='".$group['group_id']."'"); } } im trying to explode the following: article1;article2;article3;article4;article5 All im getting inserted/submitted is the number 4. My question is. Do i need one row for each "article"? Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/ Share on other sites More sharing options...
.josh Posted August 6, 2008 Share Posted August 6, 2008 You're not getting your articles inserted because $items isn't in your query. Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609089 Share on other sites More sharing options...
catri3l Posted August 6, 2008 Author Share Posted August 6, 2008 Ok. where should i put it though? '".$items['$no']."' i think is the code i need? But where should i put it? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609094 Share on other sites More sharing options...
.josh Posted August 6, 2008 Share Posted August 6, 2008 well I don't know how your table is setup so how should I know where to put it? Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609118 Share on other sites More sharing options...
catri3l Posted August 6, 2008 Author Share Posted August 6, 2008 Hey. I have a table named groups Inside that table i have the following fields: group_id, group_email, group_name, article1 I have only those 4 fields. Is the data inserted like "article1;article2;article3;article4;article5" in only one field? Or do i need to make 5 different fields for each one of the articles? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609124 Share on other sites More sharing options...
.josh Posted August 6, 2008 Share Posted August 6, 2008 Okay well I'm just kind of feeling in the dark here, because I don't know anything about your situation or what kind of content you are working or any of that sort of thing, but offhand, I would say that you should at the very least have two tables, one for your articles and one for that other info. But articleX (replace the X with any of those numbers) doesn't really mean a whole lot to me, being some random Joe who doesn't know anything about your business, so it's pretty hard for me to suggest a decent table(s) structure for you. Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609131 Share on other sites More sharing options...
catri3l Posted August 6, 2008 Author Share Posted August 6, 2008 ok. Well. I have a site where users can create groups. Im using this mod: http://www.dhtmlgoodies.com/index.html?showDownload=true&whichScript=arrange-nodes-2 I want users to arrange their tables in their groups. (Something like faceb00k). I have a table for the groups. I just wanted to put the explode data in one field inside the group table. Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609144 Share on other sites More sharing options...
.josh Posted August 6, 2008 Share Posted August 6, 2008 Well if you just want the data inside one field of the table then why use explode at all? Just update the field (or insert or whatever). if(isset($_POST['itemOrder'])){ $itemOrder = mysql_real_escape_string($_POST['itemOrder']); mysql_query("UPDATE groups SET article1 = '$itemOrder' WHERE group_id ='".$group['group_id']."'"); } Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609148 Share on other sites More sharing options...
catri3l Posted August 6, 2008 Author Share Posted August 6, 2008 I did try that before. The problem is that whenever your rearrange a table (here is the demo: http://www.dhtmlgoodies.com/scripts/arrange-nodes-2/arrange-nodes-2-demo2.html ) and hit "save" it will read the position of each table and display them in this order: table1;table2;table3... etc. Now when saving the arrangement of the tables into the DB, i think you need to explode "table1;table2;table3" to separate it. I just don't understand if you need to have different fields for each one of them (table1;table2;table3) or you it is supposed to submit like it is (table1;table2;table3). Thanks and Im really sorry I just never saw how this function works and is saved into the DB. Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609171 Share on other sites More sharing options...
catri3l Posted August 6, 2008 Author Share Posted August 6, 2008 any more help please? Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609697 Share on other sites More sharing options...
.josh Posted August 6, 2008 Share Posted August 6, 2008 If you want all the information in one field then you don't need to explode anything. The point of explode is to separate data....and yet you want to have it all in one field in your table, so again I tell you, why are you trying to use explode? Does the script that's arranging your stuff need the variables separated? Even if it does, you could keep it in the database as one string and explode it when you retrieve it from the database. Is that the best way to go about it? Maybe, maybe not. In the end, that's up to you. Maybe you need a fresh set of eyes and ears on this because I kind of feel we're just going around in circles here. Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609770 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 For the record, you shouldn't have more than one value per column (i.e: you should never explode). Have a table with a one-to-many relationship with your other table. One user has many friends, and it gets its own table, rather than 31,41,42,16,48,8,1,4,2 in one column. You honestly should never explode() MySQL results if you are trying to follow database normalization. >_> Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609783 Share on other sites More sharing options...
.josh Posted August 6, 2008 Share Posted August 6, 2008 Yeah that's kinda what I mentioned to him earlier, but from what I gather, what he has is a script that he gets to move around articles on a page (like physically order them different with js or whatever) and what he is storing is the order in which the articles appear on the page, not the articles themselves. So I was thinking that he could just use one column of enum type or hell just a varchar or somethin' Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609802 Share on other sites More sharing options...
catri3l Posted August 6, 2008 Author Share Posted August 6, 2008 I do understand what you guys are telling me to do, and i did it. The problem is that i think the js file will read the order straight from the database like this: <? $res = mysql_query("SELECT * FROM groups ORDER BY article1"); while($inf = mysql_fetch_array($res)){ // Output HTML for your boxes here. } ?> Now. If i were to use the explode function to explode article1 It would be like this: <? $res = $group['article1 ']; $inf = explode(";", $res); // Output HTML for your boxes here. } ?> The js won't be able to read the order? Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609843 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 You'd need an order indicator in the article_associations table (assuming that's what it was named). Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609847 Share on other sites More sharing options...
.josh Posted August 6, 2008 Share Posted August 6, 2008 Okay let me ask you this: What format does js want your list order to be in? some semicolon separated string? Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609853 Share on other sites More sharing options...
catri3l Posted August 6, 2008 Author Share Posted August 6, 2008 The js reads the position of the tables and puts them like this: article1;article2;article3 then i was supposed to use the explode function to separate the order and put them into IDs. I believe each ID represents a table and the order on where articles should be arranged like this: ID Articles 0 article1 1 article2 2 article3 Now the problem is that every group will put their articles in different order. So i was thinking about saving it in the group table as one single string, and then fetch that string it and explode it. and separate it. Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609867 Share on other sites More sharing options...
catri3l Posted August 6, 2008 Author Share Posted August 6, 2008 I was thinking maybe i could explode it and then give it an order? Quote Link to comment https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/#findComment-609882 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.