Jump to content

Frederik

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Frederik's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have moved the Print_r outside the while loop.. The code is now: else { $to_str = ""; $navn_arr = $mail_arr = array(); while($row = mysql_fetch_assoc($query)) { $navn = $row['fornavn'] . " " . $row['efternavn']; $mail = $row['email']; $navn_arr [] = $navn; $mail_arr [] = $mail; $to_str .= ", $navn <$mail>"; } print_r ($navn_arr); print_r ($mail_arr); and I get the result: Array ( [0] => Name1 [1] => name2 [2] => name3 ) Array ( [0] => mail1@mail.com [1] => mail2@mail.com [2] =>mail3@mail.com ) As I see it, the code returns the correct code, but am I wrong about that??
  2. I have tried these combinations: else { $to_str = ""; $navn_arr = $mail_arr = array(); while($row = mysql_fetch_assoc($query)) { $navn = $row['fornavn'] . " " . $row['efternavn']; $mail = $row['email']; $to_str .= ", $navn <$mail>"; print_r ($navn_arr); print_r ($mail_arr); } This gives the error: Array ( ) Array ( ) Array ( ) Array ( ) Warning: array_combine(): Both parameters should have at least 1 element in ........ else { $to_str = ""; $navn_arr [] = $navn; $mail_arr [] = $mail; print_r ($navn_arr); print_r ($mail_arr); while($row = mysql_fetch_assoc($query)) { $navn = $row['fornavn'] . " " . $row['efternavn']; $mail = $row['email']; $to_str .= ", $navn <$mail>"; } This gives the error: Array ( [0] => ) Array ( [0] => ) Fatal error:........ I'm not sure how to fix this?
  3. I'm not that familiar with PHP, so it would be great if you could give an example. Should it be something like: } else { $to_str = ""; $navn_arr = $mail_arr = array(); while($row = mysql_fetch_assoc($query)) { $navn = $row['fornavn'] . " " . $row['efternavn']; $mail = $row['email']; $navn_arr [] = $navn; $mail_arr [] = $mail; $to_str .= ", $navn <$mail>"; Or is that wrong?
  4. So what should I do to fix it?? Delete that line?
  5. Great! Thank you all for helping me How can I mark the post as [solved]??
  6. Hello I have a problem with an array. I get this result: Array ( [0] => name1 ) Array ( [0] => mail1@mail.com ) Array ( [0] => name2 ) Array ( [0] => mail2@mail.com ) Array ( [0] => name3 ) Array ( [0] => mail3@mail.com ) Sent 1 messages where it should be something like this: Array ( [0] => name1 ) Array ( [0] => mail1@mail.com ) Array ( [1] => name2 ) Array ( [1] => mail2@mail.com ) Array ( [2] => name3 ) Array ( [2] => mail3@mail.com ) And then it will hopefully send 3 messages. My code is: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <?php if (isset($_SESSION['login'])){ if($_SESSION['login'] == true){ } ?> <html lang="da"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>title</title> </head> <body> <?php require("config.php"); if(!isset($_POST['theid'])){ echo "Intet ID er valgt. Prøv venligst igen."; } else { $ids = join(',',$_POST['theid']); $emne = $_POST['emne']; $besked = $_POST['besked']; $besked = nl2br($besked); mysql_connect($mysql_host, $mysql_user, $mysql_pw); mysql_select_db($mysql_db); $sql = "SELECT * FROM database WHERE id IN (" . $ids . ")"; $query = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($query) == 0){ echo ("Ingen elementer er valgt."); exit; } else { while($row = mysql_fetch_assoc($query)) { $to_str = ""; $navn_arr = $mail_arr = array(); $navn = $row['fornavn'] . " " . $row['efternavn']; $mail = $row['email']; $to_str .= ", $navn <$mail>"; $navn_arr [] = $navn; $mail_arr [] = $mail; print_r ($navn_arr); print_r ($mail_arr); } } require_once 'lib/swift_required.php'; //Create the Transport $transport = Swift_SmtpTransport::newInstance('domain', 25); //Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); //Create a message $message = Swift_Message::newInstance($emne) ->setFrom(array('email...test' => 'Test')) ->setBody( '<html>' . '<head></head>' . '<body>' . $besked . '<br>' . '<img src="http://www.test.test/mail.jpg" />' . '</body>' . '</html>', 'text/html'); //Send the message $failedRecipients = array(); $numSent = 0; $to = array_combine($mail_arr, $navn_arr); foreach ($to as $address => $name) { $message->setTo(array($address => $name)); $numSent += $mailer->send($message, $failedRecipients); } printf("Sent %d messages\n", $numSent); exit; } ?> <? } else { echo("Denne side kræver adminstrator rettigheder."); } ?> </body> </html> Thanks in advance! - Frederik
  7. The fields that can be empty is: "postnummer" and "town". So the code would be something like this: $sel = "SELECT * FROM brugergruppe WHERE "; if (!empty($postnummer)) $sel .= "postnummer = '$postnummer' "; if (!empty($town) and !empty($postnummer)): $sel .= "AND town = '$town' "; elseif (!empty($town) and empty($postnummer)): $sel .= "town = '$town' "; endif; if (!empty($koen) and !empty($town) and !empty($postnummer)): $sel .= "AND koen = '$koen' "; elseif (!empty($koen) and !empty($town) and empty($$postnummer)): $sel .= "AND koen = '$koen' "; elseif (!empty($koen) and empty($town) and !empty($postnummer)): $sel .= "AND koen = '$koen' "; elseif (!empty($koen) and empty($town) and empty($postnummer )): $sel .= "koen = '$koen' "; endif; if (!empty($region)) $sel .= "AND region = '$region' "; $sel .= "AND alder BETWEEN '$alder1' AND '$alder2' "; $sel .= "ORDER BY id"; Or is there a more appropriate way to do it?
  8. I'm not quite sure how to do that. Du you have any suggestions to solve it? The thing I need to do is use: if (!empty($town) and !empty($postnummer)): $sel .= "AND town = '$town' "; elseif (!empty($town) and empty($postnummer)): $sel .= "town = '$town' "; endif; and so on at the other fields?
  9. of course! I can get some results now.. But I'm still having problems... If I leave the "postnummer" field blank I get the error: SELECT * FROM brugergruppe WHERE AND town = 'test' AND koen = 'Kvinde' AND region = 'nordjylland' AND alder BETWEEN '1' AND '49' ORDER BY id You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND town = 'test' AND koen = 'Kvinde' AND region = 'nordjylland' AND alder BETWE' at line 1 The code: $sel = "SELECT * FROM brugergruppe WHERE "; if (!empty($postnummer)) $sel .= "postnummer = '$postnummer' "; if (!empty($town)) $sel .= "AND town = '$town' "; if (!empty($koen)) $sel .= "AND koen = '$koen' "; if (!empty($region)) $sel .= "AND region = '$region' "; $sel .= "AND alder BETWEEN '$alder1' AND '$alder2' "; $sel .= "ORDER BY id"; print $sel; $query = mysql_query($sel) or die(mysql_error());
  10. I have tried something else now. I read about the function empty() and now have this code instead: $sel = "SELECT * FROM brugergruppe WHERE"; if (!empty($postnummer) $sel .= "postnummer = '$postnummer' "; if (!empty($town) $sel .= "AND town = '$town' "; if (!empty($koen) $sel .= "AND koen = '$koen' "; if (!empty($region) $sel .= "OR region = '$region' "; $sel .= "AND alder BETWEEN '$alder1' AND '$alder2' "; $sel .= "ORDER BY id "; print $sel; $query = mysql_query($sel) or die(mysql_error()); I think that makes more sense, but I get the error: Parse error: syntax error, unexpected T_VARIABLE in ........ on line 37 line 37 is: if (!empty($postnummer) $sel .= "postnummer = '$postnummer' ";
  11. I tried to remove the () ind the BETWEEN statement but still getting the error: SELECT * FROM brugergruppe WHERE ((postnummer = '0000' AND alder BETWEEN '2' AND '69') ORDER BY id You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id' at line 1 My whole code is like this: <?php require("config.php"); $search = $_POST['search']; if(empty($search)) { echo "<br><a href='index.php?pageid=4'>"; echo "Fejl!Ingen indtastning i søgefeltet1.</a>\n"; } else { $fejl = false; foreach ($_POST as $nam => $val){ if (empty($nam)){ $fejl = true; break; } } if ($fejl){ echo "<font color='red'><b>Fejl!</b></font>"; echo "<br>Søgefeltet skal udfyldes.<br><br>"; echo "<a href='index.php?pageid=4'>"; echo "<b>Tryk her for at blive sendt til søgeformularen</b></a>\n"; exit; } $postnummer = $_POST['postnummer']; $town = $_POST['town']; $koen = $_POST['koen']; $alder1 = $_POST['alder1']; $alder2 = $_POST['alder2']; $region = $_POST['region']; mysql_connect($mysql_host, $mysql_user, $mysql_pw); mysql_select_db($mysql_db); $sel = "SELECT * FROM brugergruppe "; $sel .= "WHERE ((postnummer = '$postnummer' "; if(!isset($town)){ $sel .= "AND town = '$town' "; } else if(!isset($koen)){ $sel .= "AND koen = '$koen' "; } else if(!isset($region)){ $sel .= "OR region = '$region') "; } $sel .= "AND alder BETWEEN '$alder1' AND '$alder2') "; $sel .= "ORDER BY id "; print $sel; $query = mysql_query($sel) or die(mysql_error()); if (mysql_num_rows($query) == 0){ echo ("Søgningen gav desværre ingen resultater."); exit; } else{ echo <<<_END <div id='searchresult'> <form action="index.php?pageid=6" method="post"> _END; while($row = mysql_fetch_assoc($query)) { $navn = $row['fornavn'] . " " . $row['efternavn']; $mail = $row['email']; $theid = $row['id']; echo <<<_END <input type="checkbox" name="theid[]" value="$theid"> $navn, $mail <br/> _END; } echo <<<_END <input type="submit" value="Vælg"/> </form> </div> _END; } } ?>
  12. When I use print $sel; I get: SELECT * FROM brugergruppe WHERE ((postnummer = '0000' AND (alder BETWEEN '2' AND '77')) ORDER BY id You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id' at line 1 I have set the fields "town", "koen" and "region", but they are now shown?? and is it possible to make the search not case sensitive??
  13. Now I have this code: $sel = "SELECT * FROM brugergruppe "; $sel .= "WHERE ((postnummer = '$postnummer' "; if(!isset($town)){ $sel .= "AND town = '$town' "; } else if(!isset($koen)){ $sel .= "AND koen = '$koen' "; } else if(!isset($region)){ $sel .= "OR region = '$region') "; } $sel .= "AND (alder BETWEEN '$alder1' AND '$alder2')) "; $sel .= "ORDER BY id "; $query = mysql_query($sel) or die(mysql_error()); but I get the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id' at line 1. Do you know what to do?
  14. Hello I wonder if it is possible to make a search form with different fields where all conditions should be met if the field is set. I have this code: $sel = "SELECT * FROM database "; $sel .= "WHERE ((test1 = '$test1' "; $sel .= "AND test2 = '$test2' "; $sel .= "AND test3 = '$test3' "; $sel .= "ORDER BY id "; $query = mysql_query($sel) or die(mysql_error()); if (mysql_num_rows($query) == 0){ echo ("No result"); exit; When I use this and leave for example 1 field empty I get the error: No result. Is it possible to make smothing so the condition only should be met if the field is set? So If test1 and test3 are set these condition should be met.. I hope you can help! Thanks in advance! - Frederik
  15. I get this result: Array ( [1] => on ) When I select 1 mail from the searchresult. I have this code inde my emailSender.php: <?php require("config.php"); print_r($_POST); ?> Is it possible to display the chosen id's and then use a SELECT command with MySQL and get the values of firstname, lastname and so on at this page?
×
×
  • 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.