Jump to content

Please help, problems with FOREACH and how to remember selected?


SaLing007

Recommended Posts

Hello guys,

 

Maybe someone can help me to sort this out with my code please?

Well, first of all I have got FOREACH and it doesn't work well.

 

What I am trying to do is, I have some rows receiving from mysql. Sample: from table Users, rows>Name, Email, Id and Ip. I am getting it displayed, whatsoever when I opened foreach as a row from Name to Ip I need to include another foreach inside the one I just wrote. The other foreach has to get results from anoter table in db.

Here like a tiny sample:

 

$result = $db->get_results("SELECT * FROM Users WHERE UserId = '$link_id'");

foreach($result as $row) {

$nm = $row->Name;

$eml = $row->Name;

$id = $row->UserId;

$ip = $row->Ip;

 

*Here is html table and displaying all info

<td>' . $id . '</td>

 

$result2 = $db->get_results("SELECT * FROM Groups WHERE Group_ID = '$link_id'");

foreach($result2 as $row) {

$something = $row->Group_NAME;

<table>

<tr><td>' . $something . '</td></tr>

</table>

}

<td>' . $ip . '</td>

}

 

But this way it does not work. What I am doing wrong?

 

And the second thing is that I have this code between html:

 

$result2 = $db->get_results("SELECT * FROM Groups ORDER BY Group_ID");

foreach($result2 as $row) {

$grp_id = $row->Group_ID;

$grp_nm = $row->Group_NAME;

$value = 'subscribe_view.php?group=' . $grp_id;

 

$option = '<option value="' . $value . '">' . $grp_nm . '</option>';

 

echo $option;

}

 

So as you noticed I need to get drop down options as a rows. This is the way I can have exact names of groups from table. For the values I have javascript which transfers me selection to the value link (maybe there is another way to do this with php?). But When I click for example on one of those options aka. Sounding, it refreshes the page {as it has to be on the same page} and the selected option has not been assigned.

Does anyone of you guys know how can I have <selections> html drop down list to remember selection?

 

 

Please help me so I can continue with my coding. I am desperate  with that :) And massive THANK YOU to those who have their say.

 

All your help are really appreciated. Thank you all!

 

S

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.