Page 1 of 1

txt Array, Loading images before each line.

Posted: Thu Aug 13, 2009 2:30 am
by elmr09
Hi all,

I'm working on a form, I loaded the array from a txt file. That works perfect.
I got like 30 lines now. But what I now want is a image before each line.
But the image have to be the image of the product from the line..
The image can be the same name as the array line.

Is that posible? and how?
So:
  • [ array ]
image1 [product1]
image2 [product2]
image3 [product3]

Here the code:

Code: Select all

<?php
$aProducten = file("../content/novaa_content.txt");
 
function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :
                stripslashes($value);
 
    return $value;
}
 
$aProducten = stripslashes_deep($aProducten);
$aBesteld = array();
$wanneer_dag = $_POST['wanneer_dag'];
$wanneer_maand = $_POST['wanneer_maand'];
$opmerking = $_POST['opmerkingen'];
$mail = $_POST['adres'];
$naam = $_POST['naam'];
$sex = $_POST['sex'];
$aan = "mail@tentyproductions.nl";
$onderwerp = "Bestelling Novotel Amsterdam Airport";
$aan2 = "".$mail."";
$onderwerp2 = "Uw Bestelling";
$pattern = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/";
 
echo '<form method="post" action="'.$_SERVER['REQUEST_URI'].'">';
echo '<table border="0" class="bestel" cellspacing="0" width="470px">';
foreach($aProducten as $iKey => $sValue) {
echo '<tr><td class="randje"><input size="20" type="text" name="aantal_'.$iKey.'" id="aantal" class="textInput" /> <font size="1" color="#e2007a">ex.</font></td><td class="randje"> <td><td class="randje">'.$sValue.'</td></tr>';
}
 
echo '</table><p><div id="lijn"></div></p><p><table class="bestel" border="0">';
echo '<tr><td align="right"><font color="#e2007a">*</font> Naam: <input type="text" name="naam" id="naamblok" class="textInput" /></td>';
echo '<td align="right"><font color="#e2007a">*</font> <input type="radio" name="sex" value="Dhr. " />Dhr. <input type="radio" name="sex" value="Mvr. " />Mvr.</td></tr>';
echo '<tr><td align="right"><font color="#e2007a">*</font> Email: <input type="text" name="adres" id="mail" class="textInput" /></td></tr>';
echo '<tr><td align="right"><font color="#e2007a">*</font> Dag: <select name="wanneer_dag" id="wanneer" />
 
 
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select> <font color="#e2007a">*</font> Maand: <select name="wanneer_maand" id="wanneer" />
<option>januari</option>
<option>februari</option>
<option>maart</option>
<option>april</option>
<option>mei</option>
<option>juni</option>
<option>juli</option>
<option>augustus</option>
<option>september</option>
<option>oktober</option>
<option>november</option>
<option>december</option>
</select><td>&nbsp;Gewenste leverdatum</td><td>';
 
echo '<tr><p><td>Opmerkingen:</td></tr>';
echo '<tr><td><textarea name="opmerkingen" cols="40" rows="7"></textarea></td></p></tr>';
echo '<tr><td height="20px"><div id="lijn"></div><tr></td><td colspan="2"><input type="submit" value="Bestel" /> <input type="reset" value="Opnieuw" /></td></tr>';
echo '</table></p></form>';
 
 
 
 
if($_SERVER['REQUEST_METHOD'] == "POST") {
  for($i=0;$i<=count($aProducten);$i++) {
    if(isset($_POST['aantal_'.$i]) && is_numeric($_POST['aantal_'.$i])) {
      $aBesteld[] = array($i, $_POST['aantal_'.$i]);
    }
  
}
 
 
 
if (empty($_POST['aantal_'.$iKey.'']) || '')  {
   echo '<font color="#e2007a" size="3">U heeft geen aantal ingevuld.</font><br />';
}
 
if (empty($_POST['naam']) || '')  {
   echo '<font color="#e2007a" size="3">U heeft geen naam ingevuld.</font><br />';
}
 
if ( !isset($_POST['adres']) or !preg_match( '~^[a-z0-9][a-z0-9_.\-]*@([a-z0-9]+\.)*[a-z0-9][a-z0-9\-]+\.([a-z]{2,6})$~i', $_POST['adres'] ) ) {
         echo '<font color="#e2007a" size="3">U heeft geen email ingevuld.</font><br />';
         }
 
 
else{
 
    
$aan = "mail@tentyproductions.nl";
$onderwerp = "Bestelling Novotel Amsterdam Airport";
$bericht = "Beste Stephan,\n\n Hier onder staat de bestelling van Amsterdam Airport.\n\n";
 
    
    foreach($aBesteld as $aProduct) {
    list($iProduct, $iAantal) = $aProduct;
    $bericht .= "• ".$iAantal." ex - ".$aProducten[$iProduct]." ";
    }
    $bericht .= "\n Aanleverdatum: ".$wanneer_dag." ".$wanneer_maand."\n\n Opmerking:\n ".$opmerking." \n\n Met vriendelijke groet,\n ".$sex." ".$naam."";
 
 
$aan2 = "".$mail."";
$onderwer2p = "Uw Bestelling";
$bericht2 = "Beste ".$sex." ".$naam.",\n\n Hier onder staat uw bestelling.\n\n";
 
    
    foreach($aBesteld as $aProduct) {
    list($iProduct, $iAantal) = $aProduct;
    $bericht2 .= "• ".$iAantal." ex - ".$aProducten[$iProduct]." ";
    }
    $bericht2 .= "\n Aanleverdatum: ".$wanneer_dag." ".$wanneer_maand."\n\n Opmerking:\n ".$opmerking." \n\n Met vriendelijke groet,\n het Tenty team";
 
 
    mail($aan, $onderwerp, $bericht, "FROM: $mail");
    mail($aan2, $onderwerp2, $bericht2, "FROM: mail@tentyproductions.nl");
    echo "<script type='text/javascript'>window.location='../dank.php';</script>";
     
}
}
 
?>
Can someone help me :)
THANKS

Re: txt Array, Loading images before each line.

Posted: Tue Aug 18, 2009 6:09 am
by elmr09
Nobody can point me the right direction? or say its even posible?

me is a php nooby...

THANKS

Re: txt Array, Loading images before each line.

Posted: Tue Aug 18, 2009 6:21 am
by jackpf
I don't really know what you mean.

You want to display images based on the keys of an array?

Re: txt Array, Loading images before each line.

Posted: Tue Aug 18, 2009 7:14 am
by elmr09
I'm now working with a foreach.. Uhm I have a list of things from a array. Now I want a image before each line. every image is the same. But later every image must have a own link..

This what i now have:

foreach($aProducten as $iKey => $sValue) {
foreach($aProducten as $image => $sValue) {

echo '<tr><td class="randje"><input size="20" type="text" name="aantal_'.$iKey.'" id="aantal" class="textInput" /> <font size="1" color="#e2007a">ex.</font></td><td class="randje"><td class="randje">'.$image.'</td><td class="randje">'.$sValue.'</td></tr>';
}
}

But now he puts for every new line a number from 1 till 28.. but after that he loops like 4 more times so i get the same thing over and over again..

$ikey1 $image1 $value1
$ikey2 $image2 $value2
$ikey3 $image3 $value3
$ikey4 $image4 $value4

Thanks!

Re: txt Array, Loading images before each line.

Posted: Tue Aug 18, 2009 7:49 am
by jackpf
You've got two foreach loops.

Try this:

Code: Select all

foreach($aProducten as $iKey => $sValue) {
 
echo '<tr><td class="randje"><input size="20" type="text" name="aantal_'.$iKey.'" id="aantal" class="textInput" /> <font size="1" color="#e2007a">ex.</font></td><td class="randje"><td class="randje">'.$iKey.'</td><td class="randje">'.$sValue.'</td></tr>';
}
I'm still not entirely sure what you're trying to do tbh...if every image is the same, why not just link to the image statically rather than trying to do it dynamically?

Re: txt Array, Loading images before each line.

Posted: Tue Aug 18, 2009 8:04 am
by elmr09
jackpf wrote:You've got two foreach loops.

Try this:

Code: Select all

foreach($aProducten as $iKey => $sValue) {
 
echo '<tr><td class="randje"><input size="20" type="text" name="aantal_'.$iKey.'" id="aantal" class="textInput" /> <font size="1" color="#e2007a">ex.</font></td><td class="randje"><td class="randje">'.$iKey.'</td><td class="randje">'.$sValue.'</td></tr>';
}
I'm still not entirely sure what you're trying to do tbh...if every image is the same, why not just link to the image statically rather than trying to do it dynamically?
Because every image most have a different link. OR is there a other way for doing this?

And now it works better. Now i have a list with every new line a new number. But how I can make every number a image?

thanks
w

Re: txt Array, Loading images before each line.

Posted: Tue Aug 18, 2009 8:33 am
by jackpf

Code: Select all

<img src="path/to/image.gif" />