Jump to content

Array problems


Xiode

Recommended Posts

It seems I have had the hardest time understanding arrays... and foreach.. I have been working on a project and have come to a certain spot and now I am stuck... let me explain..

I have a while loop that prints out my check boxes

[code]while (blah) {
  $checkboxes .= "<input type='checkbox' name='var_name[]' value='".$varid."' /> <span style='font-weight:bold;'>".$var."</span><br />";
}[/code]

Now I am a little confused on how I get this in the DB as "1, 3, 5, 8"

best I have seen so far is

[code]foreach($var_name as $k => $v){
$newvar .= "$v, ";
}
$newvar = substr($memsquad, 0, -2);[/code]


and then $newvar is what goes in the DB.....

Somewhere something is wrong.. I can get something in the DB.. But it is only 1 #.... Where am I going wrong...
Link to comment
https://forums.phpfreaks.com/topic/34453-array-problems/
Share on other sites

That works.

Now that I have say 3, 5 how do I can i define each of these.. these refer to another DB. These are the IDs of the names of the options... Now I am drained of thought on how to define them... I guess I would need to split them up and then define the IDs and paste them back together.... right?
Link to comment
https://forums.phpfreaks.com/topic/34453-array-problems/#findComment-162266
Share on other sites

The 3, 5 is in DB1 as col_vars
In DB2 3, 5 are the IDs(col2_id) of what I want to display(col2_name)..
How can I tear them apart and define them...

I have an SQL JOIN for my query. and I can define a single one.

[code]$sql = mysql_query("SELECT db1.col_vars, db2.table_name
FROM $db_table AS db1
LEFT JOIN $db_table2 AS db2 on db2.col2_id=db1.col_vars
");[/code]
Link to comment
https://forums.phpfreaks.com/topic/34453-array-problems/#findComment-162297
Share on other sites

I overcame that with the help of the join()..

I got them in the DB seperated with a comma.. Like I wanted.. These are the IDs of some values I want to display in another table... I just don't know how to do it using an array... I could do it with a single just fine.. trying to do this with more than one is killin me...
Link to comment
https://forums.phpfreaks.com/topic/34453-array-problems/#findComment-162377
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.