0

I'd like to search this before asking a question but I'm not sure exactly what to search for. Posting for help is always a last resort for me.

What I'd like to find is I think it's called a loop? or foreach? I think..

What I want to do is the following. I have a mailing list that I use at work that we can add a company to at anytime. Which I have setup and working to a point. Once I add the company in it will add a new table for them which works. But how do I make it so that when I go to that page I will see their company name without having to do new code for newcompany1 newcompany2 etc..

So example of my page is

Name Company Email Company 1 Company 2 etc
Person1 Companyx test@test.com no no

Where it says company 1 no that means person1 isn't on that mailing list for that company/topic.

I'm not exactly sure what to search for.

If anyone can direct me what to look/search for that would be great.

Thanks in advance,

Sean

2
Contributors
9
Replies
11
Views
4 Years
Discussion Span
Last Post by LastMitch
0

@SeanKann

What I want to do is the following. I have a mailing list that I use at work that we can add a company to at anytime. Which I have setup and working to a point. Once I add the company in it will add a new table for them which works. But how do I make it so that when I go to that page I will see their company name without having to do new code for newcompany1 newcompany2 etc..

Are you talking about a email forms?

Here is 3 links of foreach () function that has a form I think you are talking about:

http://www.freecontactform.com/email_form.php

http://bbrown.spsu.edu/papers/php2.html

http://www.hostmysite.com/support/linux/programming/phpmail/

You can test out each code from those sites.

0

No not email forms. I'm using PHP Mailer for my emailing and that is working fine.

That I can work out fine with selecting where value = yes to email people.

It's more where I view where everyone is for the list.

I have a div where I can add a new company. So example I want to add a new company to the database. I add it and it gets inserted into the database.

It will add to my table mailing_lists at the end of the database. Where I already have id, name, email address. So when it gets inserted into the database at the end of the table. I will have company_name then it defaults no. So that when someone new is added they won't be on the mailing list.

Now I want to have an array which I already have setup where it shows name and email. Then I want it to show the companies that have been added to the database with out having to redo the code for the new companies that are added.

0

Ignore the email part.....

Click Here

See the picture attached.

Name, Company. Email are all standard.. But NP and EC can be added by a form I have.

How do I code it so that I don't have to manually add the code in when a new company is added. So when It goes to the page that has the lists of people I don't have to re-code the new companies in. It will automatically do it.

//example of my current code

<?
include_once('db.php');

$query_list = mysql_query("SELECT * from table");

echo "<table>";
echo "<tr>";
//now I need my standard headers
echo "<th>Name</th><th>Company</th><th>Email</th>";
//next part is I need something to check the DB for all the other headers I have

while($mlist=mysql_fetch_array($query_list)){

echo "<tr>";
echo "<td>" .$mlist['name']. "</td>";
echo "<td>" .$mlist['company']. "</td>";
echo "<td>" .$mlist['email']. "</td>";

//than again something to check the other headers I have in my table
echo "</tr>";
}
echo "</table>";
?>
0

Are you using a CMS for this?

The code that you wrote is not going to work.

I don't think this will work.

while($mlist=mysql_fetch_array($query_list)){

Plus do you have a table?

The code is more than that. You need to used the $_GET function to get the id.

$query_list = mysql_query("SELECT column_name(s) FROM table_name WHERE column_name= operator value");

$row = mysql_fetch_array($query_list);
$id      = $row['id']; 
$name    = $row['name']; 
$company = $row['company']; 
$email   = $row['email']; 
$NP      = $row['NP']; 
$EC      = $row['EC'];

UPDATE table_name SET column1=value, column2=value2 WHERE some_column=some_value

echo "<table>";
echo "<tr><td>$name</td><td>$company</td><td>$email</td><td>$NP</td><td>$EC</td></tr>"
echo "</table>";

This is just a guideline. So you can start learn it. This is all I can help you for now.Try to modify it to your code. If you show some efforts and results then maybe I'll assist you more. For you are on your own.

Edited by LastMitch: grammer

0

Maybe it's the way I'm wording it wrong or something but this isn't what I'm looking for..

I'm not using a CMS.

How do I echo out new field that is added to the database with out having to re-write the code. I have my standard fields. id, name, company, email. Any other ones ie with my above code are EC NP. If I didn't echo them out manaully how would I do it with my code so that if I have 2 or 50 new fields it will echo out automatically. I don't want to update my php file everytime a new field is added.

Hope this clarifies it more.

0

How do I echo out new field that is added to the database with out having to re-write the code. I have my standard fields. id, name, company, email. Any other ones ie with my above code are EC NP. If I didn't echo them out manaully how would I do it with my code so that if I have 2 or 50 new fields it will echo out automatically. I don't want to update my php file everytime a new field is added.

OK, EC & NP did you create spot for those EC & NP in your table?

You need a form you do submit it, so it will automatically update in the database.

Once the form is submited then it will appear on the next page.

You are not doing this manually.

Edited by LastMitch: grammer

0

Honestly.. I'm not sure what else I can say here...

My standard fields are

id,name, company and email.

Those I will have coded in manually into my page. BUT if I add a new field into that table.. how do i get that to automatically show on my page with out having to manually add php code for it. I know there is some type of foreach or loop or something that will do this. I just don't know how to search for it correctly.

So if I make a new field called company1 it will show beside my other fields that I have.. I don't want to code my page every time I add a new company in. I'd like to have something that will automatically show it on the page rather then going in and adding it manually on the page. I don't want to go in and do a echo new companyname in each time.

0

Those I will have coded in manually into my page. BUT if I add a new field into that table.. how do i get that to automatically show on my page with out having to manually add php code for it. I know there is some type of foreach or loop or something that will do this. I just don't know how to search for it correctly.

So if I make a new field called company1 it will show beside my other fields that I have.. I don't want to code my page every time I add a new company in. I'd like to have something that will automatically show it on the page rather then going in and adding it manually on the page. I don't want to go in and do a echo new companyname in each time.

Then Try This:

http://pear.php.net/manual/en/package.database.mdb.intro-fetch.php

I really don't know what else to tell you. I spend too much time explaining and write code.

You need to download that package in order for it to work.

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.