40esp Posted June 9, 2008 Share Posted June 9, 2008 Alright, here it goes lol. I have a database table that keeps track of email newsletter sign ups. each record looks like: TABLE: newsletter_signups ID email newsletters_signed_up Active 1 [email protected] [2] [3] [4] Y The numbers in newsletters_signed_up represent specific newsletter ID's displayed like: TABLE: newsletters newsletter_id title 1 Title1 2 Title2 3 Title3 4 Title4 in a seperate table. What I need to do is create an array from "newsletters" with the specific ID's, I have the connection as so: <?php mysql_select_db($database_sw, $sw); $query_practice_groups = "SELECT * FROM newsletters ORDER BY title ASC"; $practice_groups = mysql_query($query_practice_groups, $sw) or die(mysql_error()); $row_practice_groups = mysql_fetch_assoc($practice_groups); $totalRows_practice_groups = mysql_num_rows($practice_groups); ?> How would I make an array using data given from this connection? my next question is, how do I compare all of the values from that array, with a variable lets say its called: $is_subscribed = $row_email_record['newsletters_signed_up']; Where the value is being retrieved from a POST variable, and checked against the table newsletter_signups, then returning the specific record based on the "email" field. The connection is as so: <?php mysql_select_db($database_sw, $sw); $query_email_record = sprintf("SELECT * FROM newsletter_signups WHERE email = %s", GetSQLValueString($_POST['email'], "text")); $email_record = mysql_query($query_email_record, $sw) or die(mysql_error()); $row_email_record = mysql_fetch_assoc($email_record); $totalRows_email_record = mysql_num_rows($email_record); ?> if the newsletters_signed_up result is [2] [3] [4] I want to check the array built and if any of these numbers match the [2] and [4] in newsletters_signed_up I want it to do something like this: [1] [2] SUBSCRIBED [3] SUBSCRIBED [4] SUBSCRIBED I hope I've explained this well enough. Thanks to everyone that takes a stab at this Link to comment https://forums.phpfreaks.com/topic/109468-solved-help-with-array-and-comparisons/ Share on other sites More sharing options...
Barand Posted June 9, 2008 Share Posted June 9, 2008 I suggest you make life easier for yourself and normalise your data, putting the signed_up data in a separate table. Link to comment https://forums.phpfreaks.com/topic/109468-solved-help-with-array-and-comparisons/#findComment-561522 Share on other sites More sharing options...
40esp Posted June 9, 2008 Author Share Posted June 9, 2008 The problem is, theres over 300 pre existing records in the database im working with. Im stuck with what I got. Link to comment https://forums.phpfreaks.com/topic/109468-solved-help-with-array-and-comparisons/#findComment-561527 Share on other sites More sharing options...
40esp Posted June 9, 2008 Author Share Posted June 9, 2008 anyone? Link to comment https://forums.phpfreaks.com/topic/109468-solved-help-with-array-and-comparisons/#findComment-561551 Share on other sites More sharing options...
moselkady Posted June 9, 2008 Share Posted June 9, 2008 You can read newsletters into an array like this: <?php mysql_select_db($database_sw, $sw); $query_practice_groups = "SELECT * FROM newsletters ORDER BY title ASC"; $practice_groups = mysql_query($query_practice_groups, $sw) or die(mysql_error()); $totalRows_practice_groups = mysql_num_rows($practice_groups); while ($row_practice_groups = mysql_fetch_assoc($practice_groups)) { $newsletter[$row_practice_groups['newsletter_id']] = $row_practice_groups['title']; } ?> So, $newsletter will be an array of the titles with the keys are their id numbers. Then, you can check the newsletters_signed_up field against those keys like this: <?php foreach($newsletter as $key=>$title) { if (strstr($is_subscribed, "[$key]")) echo "[$key] SUBSCRIBED\n"; else echo "[$key]\n"; } ?> Hope this is what you're looking for. Link to comment https://forums.phpfreaks.com/topic/109468-solved-help-with-array-and-comparisons/#findComment-561559 Share on other sites More sharing options...
40esp Posted June 9, 2008 Author Share Posted June 9, 2008 YES! THANK YOU!!!!! Link to comment https://forums.phpfreaks.com/topic/109468-solved-help-with-array-and-comparisons/#findComment-561564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.