mustiej Posted April 18, 2014 Share Posted April 18, 2014 Hello freaks, I'm new here and so this is my first post. Let me introduce myself, my name is Mustafa and I live in the Netherlands. I have a little bit of a situation going on.. I'm studying mediadevelopment, so basically webdesign/programming/photoshop/video editting bla bla bla.. But we have literally zero teachers that give us lessons about PHP... before I can take serious actions and take this to a court or file a complaint about the school, monday will be long gone and so my exam week which is crucial for my study. The reason that we came this far with PHP is literally because of three little lessons from a trainee from a higher education school and since he left us because of unknown reasons, every student is fked. Our job for the exam week is to make a multi-array about 8 products. Each product must have an EAN(international product code thingy) product code. By typing this unique code at the end of your website, example: locallhost/EAN.php/?ean=1001, the 1001 named product needs to show it's details without having a seperate details.php document. So to make it simple: I click on one of the 8 products or type in the product code, the website shows us the product and it's details of that product only without showing the other 7. This is what I have so far: EAN.php(my multi-array) EAN.inc.php(my functions) index.php(my outputs) I can't have more then 3 files. What I need right now is how can I make the page change to the product page and show it's details? I added the files so maybe it clears things up. Sorry for my bad English and feel free to criticize my codes. Thank you so much in advance!!! EA.inc.php EA.php index.php Quote Link to comment https://forums.phpfreaks.com/topic/287876-a-little-story-of-my-situation-and-a-multi-array-help/ Share on other sites More sharing options...
Rifts Posted April 19, 2014 Share Posted April 19, 2014 can you copy paste your code on pastebin or something Quote Link to comment https://forums.phpfreaks.com/topic/287876-a-little-story-of-my-situation-and-a-multi-array-help/#findComment-1476635 Share on other sites More sharing options...
mustiej Posted April 19, 2014 Author Share Posted April 19, 2014 <html> <head> <title>test</title> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <?php include 'EA.inc.php'; $array = $ean; //dubblecast ean; unset ($ean); $ean = (int) $_GET['ean']; if (isset($ean) && $ean !== 0) { if (isset ($array[$ean]){ echo json_encode($array[$ean]; doorLopen($ean); } } //if(isset ($_GET['EAN'])) // { // $eannummer = $_GET['EAN']; // eannummer($eannummer, $ean); // } //else { //doorLopen($ean); // } ?> </body> </html> <?php $ean = array( "978904560816" =>array( "EAN" => "<a href=11.php?ean=>" . "9789045630816" ." </a>"."<a href=11.php?ean=>" . "<br><img width=100 height=100 src=9789045630816.jpg></img> " ." </a>", "naam" => "Studio Webdesign", "omschrijving" => "Professionele websites ontwerp je voortaan gewoon zelf! Dankzij de unieke interface in dtp-stijl creeer je met Studio Webdesign in alle eenvoud de meest aantrekkelijke sites, zonder je hiervoor te moeten verdiepen in ingewikkelde programmeertalen. Uitgeroepen tot beste koop door PCM (Personal Computer Magazine), juni 2004.", "prijs" => "39,95", "bestelnummer" => "#001", "systeemvereisten" => array( "processor" => "Pentium ¨ III", "geheugen" => "256 KB", "besturingssysteem" => "Windows 95", "schijfruimte" => "5 MB", "schermresolutie" => "1024 x 768", "overige" => "USB aansluiting"), "highlights" => "highlight1", ), "9789045632063" =>array( "EAN" => "<a href=11.php?ean=>" . "9789045632063" ." </a>"."<a href=11.php?ean=>" . "<br><img width=100 height=100 src=9789045632063.jpg></img> " ." </a>", "naam" => "Planten Enceclopedie 2004", "omschrijving" => "In deze nieuwe versie vindt u informatie over meer dan 5000 planten, bomen, bloemen en struiken met meer dan 3500 foto's. Als extra krijgt u er meer dan 400 kamerplanten bij, inclusief de verzorgingstips!", "prijs" => "24,95", "bestelnummer" => "#002"), "9789045632902" =>array( "EAN" => "<a href=11.php?ean=>" . "9789045632902" ." </a>"."<a href=11.php?ean=>" . "<br><img width=100 height=100 src=9789045632902.jpg></img> " ." </a>", "naam" => "PC Drukkerij 3 Suite", "omschrijving" => "Een krachtig programma met maar liefst 200.000 foto's en cliparts voor een onbeperkt aantal mogelijkheden! Op dezelfde engine gebaseerd als de andere PC Drukkerij-pakketten, maar met zo mogelijk nog meer afbeeldingen, sjablonen en thema's, is dit ongetwijfeld het meest complete programma uit de reeks! Meer dan 15.000 kant-en-klare voorbeelden: wenskaarten, visitekaartjes, uitnodigingen, verjaardagskaarten, cd-labels, menu's, ontwerpen om op textiel te drukken...", "prijs" => "29,95", "bestelnummer" => "#003"), "9789045634814" =>array( "EAN" => "<a href=11.php?ean=>" . "9789045634814" ." </a>"."<a href=11.php?ean=>" . "<br><img width=100 height=100 src=9789045634814.jpg></img> " ." </a>", "naam" => "Creatief Fotolab", "omschrijving" => "De beste creatieve gereedschappen in dienst van je foto's! Eindelijk een alles-in-een oplossing om je foto's op een creatieve manier te beheren, te optimaliseren en te delen. Van het klassement naar de afdruk via het retoucheren, een diavoorstelling of zelfs de creatie van originele documenten, niets ontbreekt!", "prijs" => "29,95", "bestelnummer" => "#004"), "9789045634838" =>array( "EAN" => "<a href=11.php?ean=>" . "9789045634838" ." </a>"."<a href=11.php?ean=>" . "<br><img width=100 height=100 src=9789045634838.jpg></img> " ." </a>", "naam" => "MovieJack DVD Pro", "omschrijving" => "Maak snel en eenvoudig back-ups van uw originele dvd-video's op traditionele cd-r's of dvd's. Het programma comprimeert de enorme hoeveelheid gegevens op de oorspronkelijke dvd automatisch tot een video-cd (VCD), super video-cd (SVCD) of DivX-cd indien u dat wenst.", "prijs" => "49,95", "bestelnummer" => "#005"), "9789045649429" =>array( "EAN" => "<a href=11.php?ean=>" . "9789045649429" ." </a>"."<a href=11.php?ean=>" . "<br><img width=100 height=100 src=9789045649429.jpg></img> " ." </a>", "naam" => "Easy Computing PC Drukkerij Visitekaartjes 7.5", "omschrijving" => "PC Drukkerij Visitekaartjes 7.5 is een complete pakket, inclusief talrijke tekengereedschappen en een volledig vernieuwde interface. Visitekaartjes 7.5 biedt alle hulpmiddelen die je nodig hebt om jouw eigen visitekaartjes te ontwerpen en af te drukken. Met deze totaaloplossing, duizenden sjablonen, afbeeldingen en een krachtige afdrukmodule met inktbesparende functie, ontwerpt je voortaan moeiteloos originele visitekaartjes.", "prijs" => "19,99", "bestelnummer" => "#006"), "B00F4OQVE6" =>array( "ASIN" => "<a href=11.php?ean=>" . "B004FOQVE6" ." </a>"."<a href=11.php?ean=>" . "<br><img width=100 height=100 src=B004FOQVE6.jpg></img> " ." </a>", "naam" => "CraftArist Wedding Day", "omschrijving" => "The perfect tool for creating personal, unique wedding stationery that suits you and your style. Choose your favourite style and personalise it with as much text, embellishments and photographs as you like. Designs can be personalised with unlimited pictures and text, plus there are craft tools and a built-in photo editor to help deliver high quality results that are guaranteed to impress friends and family. CraftArtist Wedding Day is incredibly easy to use, thanks to its simple drag-and-drop function.", "prijs" => "19,99", "bestelnummer" => "#007"), "9789045647579" =>array( "EAN" => "<a href=11.php?ean=>" . "9789045647579" ." </a>"."<a href=11.php?ean=>" . "<br><img width=100 height=100 src=9789045647579.jpg></img> " ." </a>", "naam" => "Super Architect 3D Platinum NexGen", "omschrijving" => "Nieuwbouw en renovatie; Huis en tuin; Decoratie en presentatie; Snel resultaat; Automatisch en intuïtief; Veelzijdige tools; AutoCAD (t/m 2012) en Google SketchUp (t/m v7!) compatibel; Handige tips; Videotraining. Nog eenvoudiger dan tevoren genereert u een volledig woningplan dat automatisch wordt aangepast wanneer u de grootte of indeling van de kamers wijzigt - inclusief het dak! Tot 26 keer sneller dan de concurrentie levert Super Architect 3D een ongekende fotorealistische weergave. Met deze Platinum-editie kunt u o.a. maquettes maken, AutoCAD-bestanden importeren en exporteren, zwembaden ontwerpen en veel meer!", "prijs" => "42,50", "bestelnummer" => "#008")); ?> <html> <head> <style type="text/css"> td{ width: 33%; text-align: left; } td.left{ text-align: right; background-color: #E0E0D1; } </style> </head> <?php include 'EA.php'; function doorLopen($ean) { $output = "<div class=wrapper><h1>Catalogus</h1>"; foreach($ean as $product => $details) { $output .= "<table width=500>"; foreach($details as $title => $merk) { $output .= "<tr><td>". "$title : </td><td class=left>" .$merk."</td></tr>"; } $output .= "</table>"; } $output .= "</table></div>"; echo $output; } function eannummer($eannummer, $ean) { $output = "<div class=wrapper>"; foreach($ean as $key => $val) { $output .= "<table width=500>"; if($val['EAN'] == $eannummer) { foreach($val as $title => $merk) { $output .= "<tr><td>". "$title : </td><td class=left>" .$merk."</td></tr>"; } } $output .= "</table>"; } $output .= "</div>"; echo $output; } function goed() { echo "test"; } /*function doorLopen($ean){ foreach($ean as $key => $uitkomst) { $output = ""; foreach($uitkomst as $merk => $prijs) { echo $ouput = "<table width=400>"; echo "<tr><td>" . $merk . "</td>" . "<td class=left>" . $prijs . "</td></tr></table>"; } } }*/ ?> </html> Quote Link to comment https://forums.phpfreaks.com/topic/287876-a-little-story-of-my-situation-and-a-multi-array-help/#findComment-1476636 Share on other sites More sharing options...
mustiej Posted April 19, 2014 Author Share Posted April 19, 2014 Okay, don't know if pastebin is supposed to look like this.. Quote Link to comment https://forums.phpfreaks.com/topic/287876-a-little-story-of-my-situation-and-a-multi-array-help/#findComment-1476637 Share on other sites More sharing options...
Ch0cu3r Posted April 19, 2014 Share Posted April 19, 2014 In index.php delete lines 13 to 21. I do not understand what you're trying to do there. The correct code you need is for some reason commented out (lines 22 to 30). So this is what index.php should look like after edits <html> <head> <title>test</title> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <?php include 'EA.inc.php'; if(isset ($_GET['ean'])) { $eannummer = $_GET['ean']; eannummer($eannummer, $ean); } else { doorLopen($ean); } ?> </body> </html> The problem lies in the eannummer() function located in EA.inc.php. On line 47 you have this line if($val['EAN'] == $eannummer) $val['EAN'] should be $key. But there is a more efficient way to code that function which is like this function eannummer($eannummer, $ean) { $output = "<div class=wrapper>"; if(isset($ean[ $eannummer ])) { $output .= "<table width=500>"; foreach($ean[ $eannummer ] as $title => $merk) { $output .= "<tr><td>". "$title : </td><td class=left>" .$merk."</td></tr>"; } $output .= "</table>"; } else { $output .= 'Product #'.$eannummer. ' does not exist'; } $output .= "</div>"; echo $output; } Quote Link to comment https://forums.phpfreaks.com/topic/287876-a-little-story-of-my-situation-and-a-multi-array-help/#findComment-1476650 Share on other sites More sharing options...
mustiej Posted April 19, 2014 Author Share Posted April 19, 2014 Thank you for the reply. But the codes still won't open a new page with the product and it's details called systeemvereisten and highlights. That is the part where i'm stuck. Quote Link to comment https://forums.phpfreaks.com/topic/287876-a-little-story-of-my-situation-and-a-multi-array-help/#findComment-1476651 Share on other sites More sharing options...
boompa Posted April 19, 2014 Share Posted April 19, 2014 The URLs in your ean.php file are badly formed, resulting in no ean number: http://blah/11.php?ean= I am guessing that the 11.php should be index.php as well. Quote Link to comment https://forums.phpfreaks.com/topic/287876-a-little-story-of-my-situation-and-a-multi-array-help/#findComment-1476652 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.