Advertisement
Sheriziya

attempt to get data after foreach join tables

Feb 3rd, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 15.58 KB | None | 0 0
  1. <?php
  2.  
  3. // Get the latest variable from Pods URL
  4. // $id = pods_url_variable('last');
  5.  
  6. // Define the params to find the Pods Item based on the $id
  7. // $params = array( 'where' => 'permalink = "'.$id.'"' );
  8.  
  9. // Display it by using Pods Template
  10. //echo pods( 'dragons' )->find( $params )->template( 'dragon_detail' );
  11.  
  12. // Trying to include template in page.
  13.  
  14. // Get the latest variable from Pods URL
  15. $id = pods_url_variable('last');
  16. $dragondata = new Pod('dragons', $id);
  17.  
  18. // Getting variables
  19. $dragon_code = $dragondata->get_field('code');
  20. $dragon_name = $dragondata->get_field('name');
  21. $dragon_breed = $dragondata->get_field('breed');
  22. $dragon_gender = $dragondata->get_field('gender');
  23. $dragon_coga = $dragondata->get_field('coga');
  24. $dragon_pol = $dragondata->get_field('part_of_a_lineage');
  25. $dragon_lineage = $dragondata->get_field('lineage');
  26. $dragon_generation = $dragondata->get_field('generation');
  27. $dragon_mother = $dragondata->get_field('mother.id');
  28. $dragon_father = $dragondata->get_field('father.id');
  29. $dragon_armypart = $dragondata->get_field('part_of_an_army');
  30. $dragon_army = $dragondata->get_field('army.id');
  31. $dragon_partnerava = $dragondata->get_field('partner_available');
  32. $dragon_partner = $dragondata->get_field('partner.id');
  33. $dragon_partref = $dragondata->get_field('any_refusals');
  34. $dragon_refpart = $dragondata->get_field('refused_partner.id');
  35. $dragon_children = $dragondata->get_field('children');
  36. $dragon_childwho = $dragondata->get_field('existing_children.id');
  37. $dragon_gifted = $dragondata->get_field('gifted');
  38. $dragon_gifter = $dragondata->get_field('gifter');
  39. $dragon_giftnotes = $dragondata->get_field('gift_notes');
  40. $dragon_morenotes = $dragondata->get_field('other_notes');
  41. $dragon_url = $dragondata->get_field('permalink');
  42.  
  43. // Pick the chosen value out of the array - needed for if statements.
  44. $dragon_coga2 = $dragondata->get_field('coga.id');
  45. $dragon_generation2 = $dragondata->get_field('generation.id');
  46. $dragon_mother_info = new Pod('dragons', $dragon_mother);
  47. $dragon_mother_url = $dragon_mother_info->get_field('permalink');
  48. $base_dragons_url = "http://dragoncreatures.com/dragons";
  49. $dragon_father_info = new Pod('dragons', $dragon_father);
  50. $dragon_father_url = $dragon_father_info->get_field('permalink');
  51.  
  52. // Getting partner data
  53. $dragon_partner_info = new Pod('dragons', $dragon_partner);
  54. $dragon_partner_name =  $dragon_partner_info->get_field('name');
  55. $dragon_partner_url = $dragon_partner_info->get_field('permalink');
  56.  
  57.  
  58. $partnerpod = new Pod('dragons', $dragon_partner);
  59. // get an array of the values, even if there's only one
  60. $partnerdata = (array) $partnerpod->field('partner.name.id');
  61.  
  62. // get an array of the value field arrays, even if there's only one field array
  63. $partnerdata1 = (array) $partnerpod->get_field('partner.id');
  64. ?>
  65. <table>
  66.     <TR>
  67.         <TD>Dragon picture:<BR>
  68.             <img src="http://dragcave.net/image/<?php echo $dragon_code; ?>.gif" style="border-width: 0" alt="Adopt one today!"/><BR>
  69.            
  70.         </TD>
  71.  
  72.     <TR>
  73.         <TD>Dragon code: <?php echo $dragon_code; ?><BR>
  74.             Dragon Name: <?php echo $dragon_name; ?><BR>
  75.             Dragon breed: <?php echo $dragondata->display( 'breed' ); ?><BR>
  76.             Dragon Gender: <?php echo $dragondata->display( 'gender' ); ?><BR>
  77.             Dragon Coga: <?php echo $dragondata->display( 'coga' ); ?><BR>
  78.             Dragon Coga version 2: <?php echo $dragon_coga2; ?><BR>
  79.             Dragon Coga version 3: <?php echo $dragondata->display( 'coga.name' ); ?><BR>
  80.             Dragon Part of a lineage: <?php echo $dragondata->display( 'part_of_a_lineage' ); ?><BR>
  81.             Dragon lineage: <?php echo $dragondata->display( 'lineage' ); ?><BR>
  82.             Dragon Generation: <?php echo $dragondata->display( 'generation' ); ?><BR>
  83.             Dragon Generation version 2: <?php echo $dragon_generation2; ?><BR>
  84.             Dragon mother: <?php echo $dragondata->display( 'mother' ); ?><BR>
  85.             Dragon father: <?php echo $dragondata->display( 'father' ); ?><BR>
  86.             Dragon part of an army: <?php echo $dragon_armypart; ?><BR>
  87.             Dragon part of an army version 2: <?php echo $dragondata->display( 'part_of_an_army' ); ?><BR>
  88.             Dragon Army: <?php echo $dragondata->display( 'army' ); ?><BR>
  89.             Dragon Partner available: <?php echo $dragon_partnerava; ?><BR>
  90.            Dragon Partner available: <?php echo $dragondata->display( 'partner_available' ); ?><BR>
  91.            Dragon Partner: <?php echo $dragondata->display( 'partner' ); ?><BR>
  92.            Dragon any refused partners?: <?php echo $dragondata->display( 'any_refusals' ); ?><BR>
  93.            Dragon any refused partners version 2?: <?php echo $dragon_partref; ?><BR>
  94.            Dragon Refused partners: <?php echo $dragondata->display( 'refused_partner' ); ?><BR>
  95.            Dragon are there any children?: <?php echo $dragondata->display( 'children' ); ?><BR>
  96.            Dragon Are there any children version 2?: <?php echo $dragon_children; ?><BR>
  97.            Dragon who are the children?: <?php echo $dragondata->display( 'existing_children' ); ?><BR>
  98.            Dragon did you get the dragon as a gift?: <?php echo $dragondata->display( 'gifted' ); ?><BR>
  99.            Dragon Who gifted you the dragon?: <?php echo $dragondata->display( 'gifter' ); ?><BR>
  100.            Dragon Any notes about the gift?: <?php echo $dragon_giftnotes; ?><BR>
  101.            Dragon Any notes about the gift?: <?php echo $dragon_morenotes; ?><BR>
  102.         </TD>
  103. </TR>        
  104. </table>
  105. <p>&nbsp;</p>
  106. <table>
  107.     <tr>
  108.       <td>
  109.           <b>now testing to see if statements will work properly.</b>
  110.       </td>
  111.     </tr>
  112.     <tr>
  113.       <td>
  114.           <u>First test, check which coga and display appropriate text based on coga.</u><BR>
  115. <?php
  116. if ($dragon_coga2 == 1)
  117. {
  118.     echo "I caught this dragon in the cave.<BR>";
  119. }
  120. else
  121.     if ($dragon_coga2 == 2)
  122.     {
  123.     echo "This is a dragon of my own breed.<BR>";
  124.     }
  125. else
  126.     if ($dragon_coga2 == 3)
  127.     {
  128.     echo "I got this dragon as a gift.<BR>";
  129.     }
  130. else
  131.     if ($dragon_coga2 == 4)
  132.     {
  133.     echo "I got this dragon from the Abandoned Area.<BR>";
  134.     }
  135. else
  136. {
  137.     echo "Something went wrong, because it is unclear where this dragon came from.<BR>";
  138. }
  139.           ?><B>Test has succeeded.</B><BR>
  140.         </td>
  141.     </tr>
  142.     <tr>
  143.       <td>
  144.           <u>Next test: Let's see if we can test if the dragon is part of a lineage.</u><BR>
  145. <?php
  146. if ($dragon_pol == 0)
  147. {
  148.    echo "This dragon is not part of any lineage.<BR>";
  149. }
  150. else
  151.    if ($dragon_pol == 1)
  152.    {
  153.    echo "This dragon is part a lineage.<BR>";
  154.    }
  155. else
  156. {
  157.    echo "Something went wrong, because it is unclear if this dragon is part of any lineage.<BR>";
  158. }
  159.          ?><b>Test has succeeded.</b>
  160.      </td>
  161.    </tr>
  162.    <tr>
  163.        <td><u>Let's see if we can display the lineage after we've tested if the dragon is part of a lineage.</u><br>
  164. <?php
  165. if ($dragon_pol == 1)
  166. {
  167.    echo "This dragon is part of the ";
  168.    echo $dragondata->display( 'lineage' );
  169.    echo " lineage.<BR>";
  170. }
  171. else
  172. {
  173.    echo ""; //We don't need to display anything if the dragon is not part of any lineage.
  174. }
  175.             ?><b>test has succeeded</b>
  176.         </td>
  177.     </tr>
  178.     <tr>
  179.         <td>
  180.             <u>Now let's test if we can display the generation together with the lineage once a dragon is part of a lineage.</u><br>
  181. <?php
  182. if ($dragon_pol == 1)
  183. {
  184.    echo "This dragon is part of ";
  185.    echo $dragondata->display( 'generation' );
  186.    echo " of the ";
  187.    echo $dragondata->display( 'lineage' );
  188.    echo " lineage.<BR>";
  189. }
  190. else
  191. {
  192.    echo ""; //We don't need to display anything if the dragon is not part of any lineage.
  193. }
  194.             ?><b>test has succeeded.</b>
  195.         </td>
  196.     </tr>
  197.     <tr>
  198.         <td>
  199.             <u>Let's see if can adjust the generation terms. I want to display:</u><BR>
  200.            <i>"This dragon is part of the first generation of the Seasonal dreams lineage."</i><BR>
  201. <?php
  202. if ($dragon_pol == 1)
  203. {
  204.  if ($dragon_generation2 == 1)
  205.  {
  206.    echo "This dragon is part of first generation of the ";
  207.    echo $dragondata->display( 'lineage' );
  208.    echo " lineage.<BR>";
  209.  }
  210. }
  211. else
  212. {
  213.    echo ""; //We don't need to display anything if the dragon is not part of any lineage.
  214. }
  215.             ?><b>test has succeeded.</b>            
  216.         </td>
  217.     </tr>
  218.     <tr>
  219.         <td>
  220.             <u>Let's test if the dragon has a mother and if so, who this mother is.</u><BR>
  221. <?php
  222. if ($dragon_mother != '')
  223. {
  224.    echo $dragondata->display( 'mother' );
  225.    echo " is ";
  226.    echo $dragon_name;
  227.    echo " 's mother<BR>";
  228.  
  229. }
  230. else
  231. {
  232.    echo ""; //We don't need to display anything if the dragon has no mother.
  233. }
  234.            ?><b>test has succeeded.</b>        
  235.        </td>
  236.    </tr>
  237.    <tr>
  238.        <td>
  239.            <u>Now let's see if we can have a link with the mother's name.</u><BR>
  240. <?php
  241. if ($dragon_mother != '')
  242. {
  243.    echo "<a href=\"$base_dragons_url/$dragon_mother_url\">";
  244.     echo $dragondata->display( 'mother' );
  245.     echo "</a>";
  246.     echo " is ";
  247.     echo $dragon_name;
  248.     echo " 's mother<BR>";
  249.  
  250. }
  251. else
  252. {
  253.     echo ""; //We don't need to display anything if the dragon has no mother.
  254. }
  255. ?> <b>Test has succeeded</b>        </td>
  256.    </tr>
  257.    <tr>
  258.        <td>
  259.            <u>Let's test if the dragon has a father and if so, who the father is.</u><BR>
  260. <?php
  261. if ($dragon_father != '')
  262. {
  263.     echo $dragondata->display( 'father' );
  264.     echo " is ";
  265.     echo $dragon_name;
  266.     echo " 's father<BR>";
  267.  
  268. }
  269. else
  270. {
  271.     echo ""; //We don't need to display anything if the dragon has no father.
  272. }
  273.            ?><b>Test has succeeded</b>    
  274.        </td>
  275.    </tr>
  276.    <tr>
  277.        <td>
  278.            <u>Now let's see if we can have a link with the father's name.</u><BR>
  279. <?php
  280. if ($dragon_father != '')
  281. {
  282.    echo "<a href=\"$base_dragons_url/$dragon_father_url\">";
  283.    echo $dragondata->display( 'father' );
  284.    echo "</a>";
  285.    echo " is ";
  286.    echo $dragon_name;
  287.    echo " 's father<BR>";
  288. }
  289. else
  290. {
  291.    echo ""; //We don't need to display anything if the dragon has no father.
  292. }
  293. ?> <b>Test succeeded. Onto the next one.</b>        </td>
  294.    </tr>
  295.    <tr>
  296.      <td>
  297.          <u>Next test: Let's see if we can test if the dragon is part of an army.</u><BR>
  298. <?php
  299. if ($dragon_armypart == 0)
  300. {
  301.    echo "This dragon is not part of any army.<BR>";
  302. }
  303. else
  304.    if ($dragon_armypart == 1)
  305.    {
  306.    echo "This dragon is part an army.<BR>";
  307.    }
  308. else
  309. {
  310.    echo "Something went wrong, because it is unclear if this dragon is part of any army.<BR>";
  311. }
  312.          ?><b>Test has succeeded</b>
  313.      </td>
  314.    </tr>
  315.    <tr>
  316.      <td>
  317.          <u>Next test: Let's see if we can test if the dragon is part of an army AND if so, of which army the dragon is a part of.</u><BR>
  318. <?php
  319. if ($dragon_armypart == 0)
  320. {
  321.    echo "This dragon is not part of any army.<BR>";
  322. }
  323. else
  324.    if ($dragon_armypart == 1)
  325.    {
  326.    echo "This dragon is part of ";
  327.    echo $dragondata->display( 'army' );
  328.    echo "<br>";
  329.    }
  330. else
  331. {
  332.    echo "Something went wrong, because it is unclear if this dragon is part of any army.<BR>";
  333. }
  334.          ?><b>Test has succeeded</b>
  335.      </td>
  336.    </tr>
  337.    <tr>
  338.        <td>
  339.            <u>Let's test if the dragon has a partner</u><BR>
  340. <?php
  341. if ($dragon_partnerava == 0)
  342. {
  343.    echo "This dragon does not have a partner.<BR>";
  344. }
  345. else
  346.    if ($dragon_partnerava == 1)
  347.    {
  348.    echo "This dragon has a partner.<BR>";
  349.    }
  350. else
  351. {
  352.    echo "Something went wrong, because it is unclear if this dragon has a partner.<BR>";
  353. }
  354.            ?><b>Test has succeeded</b>
  355.        </td>
  356.    </tr>
  357.    <tr>
  358.        <td><u>Let's see if we can display the partner after we've tested if the dragon has a partner.</u><br>
  359. <?php
  360. if ($dragon_partnerava == 1)
  361. {
  362.    echo $dragon_name;
  363.    echo " has ";
  364.    echo $dragondata->display( 'partner' );
  365.    echo " as a partner.<BR>";
  366. }
  367. else
  368. {
  369.    echo ""; //We don't need to display anything if the dragon is not part of any lineage.
  370. }
  371.            ?><b>Test has succeeded</b>
  372.        </td>
  373.    </tr>
  374.    <tr>
  375.        <td><u>Let's see if we can have a link with the partner's name</u><br>
  376. <?php
  377. if ($dragon_partner != '')
  378. {
  379.    echo $dragon_name;
  380.    echo " has ";
  381.    echo "<a href=\"$base_dragons_url/$dragon_partner_url\">";
  382.     echo $dragondata->display( 'partner' );
  383.     echo "</a>";
  384.     echo " as a partner.<BR>";
  385. }
  386. else
  387. {
  388.     echo "this dragon has no partner"; //We don't need to display anything if the dragon has no partner.
  389. }
  390. ?>
  391.            <b><font color="red">This displays the wrong link. Let's try this with Foreach instead.</font></b>
  392.         </td>
  393.     </tr>
  394.     <tr>
  395.         <td><u>A test to see how $key and $value are determined</u><br>
  396. <?php
  397. $fruit = array(
  398.         'orange' => '5.00',
  399.         'apple' => '2.50',
  400.         'banana' => '3.99'
  401. );
  402.  
  403. foreach ($fruit as $key => $value) {
  404.         echo "$key is $value dollars <br>";
  405. }
  406.             ?>
  407.             Test is ongoing
  408.         </td>
  409.     </tr>
  410.     <tr>
  411.         <td><u>Let's see if we can get the partner names with the adjusted name</u><br>
  412. <?php
  413. if ($dragon_partner != '')
  414. {
  415.    echo $dragon_name;
  416.    echo " has ";
  417.    echo "<a href=\"$base_dragons_url/$dragon_partner_url\">";
  418.    echo $dragon_partner_name;
  419.    echo "</a>";
  420.    echo " as a partner.<BR>";
  421. }
  422. else
  423. {
  424.    echo "this dragon has no partner"; //We don't need to display anything if the dragon has no partner.
  425. }
  426. ?>
  427.             <B><font xolor="red">De verkeerde naam wordt gepakt als er meer dan 1 dragon als partner is. Nu eerst uitzoeken hoe ik de juiste data uit de array kan pakken.</font></B>
  428.         </td>
  429.     </tr>
  430.     <tr>
  431.         <td><u>First, let's get the partner (names) from the partner array instead of the $dragondata </u><br>
  432. <?php
  433. if ($dragon_partner != '')
  434. {
  435.    echo $dragon_name;
  436.    echo " has ";
  437.    echo $partnerdata;
  438.    echo "</a>";
  439.    echo " as a partner.<BR>";
  440. }
  441. else
  442. {
  443.    echo "this dragon has no partner"; //We don't need to display anything if the dragon has no partner.
  444. }
  445. ?>
  446.             Test is ongoing
  447.         </td>
  448.     </tr>
  449.     <tr>
  450.         <td><u>wederom nieuwe poging: get an array of the value field arrays, even if there's only one field array</u><br>
  451. <?php
  452.    if (isset($partnerdata1['partner.id']))
  453.        {
  454.    $partnerdata1 = array( $partnerdata1 );
  455.    echo $dragon_name;
  456. }
  457.        //    echo " has ";
  458.        // echo $partnerdata;
  459.        // echo "</a>";
  460.        // echo " as a partner.<BR>";
  461. else
  462. {
  463.    echo "this dragon has no partner"; //We don't need to display anything if the dragon has no partner.
  464. }
  465. ?>
  466.             Test fails. Nieuwe poging met iets anders.
  467.         </td>
  468.     </tr>
  469.     <tr>
  470.         <td><U>nieuwe poging: let's display the content of the array and then echo the values and keys.</U><BR>
  471. <?php
  472. if ($dragon_partner != '')
  473. {
  474. var_dump($dragon_partner);
  475.    echo "<BR>";
  476. foreach ($dragon_partner as $key => $value)
  477. {
  478.    echo 'Key: ' . $key . ' Value: ' . $value . "<BR>";
  479. }
  480. }
  481. ?>
  482.        </td>
  483.    </tr>
  484.    <tr>
  485.        <td><U>Now let's see if we can get the names from the partners</U><BR>
  486. <?php
  487. if ($dragon_partner != '')
  488. {
  489. var_dump($dragon_partner);
  490.     echo "<BR>";
  491. foreach ($dragon_partner as $key => $value)
  492.  {
  493.      $partnerinfo = array( 'where' => 'id = "'.$value.'"' );
  494.      $partnerinfopod = pods( 'dragons', $partnerinfo );
  495.      $partnername = $partnerinfopod->get_field('name');
  496.      while ( $partnerinfopod->fetch() )
  497.      {
  498.         echo $partnername;
  499.         echo "something was processed<BR>";
  500.      }
  501.  }
  502. }
  503. ?>
  504.         </td>
  505.     </tr>
  506. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement