Jump to content

Recommended Posts

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"?

Link to comment
https://forums.phpfreaks.com/topic/118352-solved-explode-function-problem/
Share on other sites

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!

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. 

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.

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']."'");
}

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.

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.

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. >_>

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'

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?

 

 

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.

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.