donrobertito Posted November 15, 2012 Share Posted November 15, 2012 Hello there! I'm such a beginner in php coding, i don't know the trick yet. My question is: I have a site, the main files are header.php; index.php; footer.php. I include header and footer in index php The index.php contains the articles, with tags. I want to pass the tags form articles to header.php as meta information. I get the tags from a database query. How can i do this method? Thanks: Robert Quote Link to comment https://forums.phpfreaks.com/topic/270717-pass-parameters-from-indexphp-tag-to-headerphp-meta/ Share on other sites More sharing options...
Muddy_Funster Posted November 15, 2012 Share Posted November 15, 2012 By passing them as variables into the header.php after you include it. Quote Link to comment https://forums.phpfreaks.com/topic/270717-pass-parameters-from-indexphp-tag-to-headerphp-meta/#findComment-1392551 Share on other sites More sharing options...
donrobertito Posted November 15, 2012 Author Share Posted November 15, 2012 By passing them as variables into the header.php after you include it. Thanks! But can yopu be a bit more precise? With a tiny example? My code looks like this at the tags: <p>Tags <?php for ($i = 0; $i < $count; $i++) { echo '<a href="index.php?p=tag&tag='.$article[$i]->tag_word.'">'.$article[$i]->tag_word.'</a>'; if ($i != $count-1) echo ", "; }?></p><br /> How can i pass these to header? Quote Link to comment https://forums.phpfreaks.com/topic/270717-pass-parameters-from-indexphp-tag-to-headerphp-meta/#findComment-1392558 Share on other sites More sharing options...
Muddy_Funster Posted November 15, 2012 Share Posted November 15, 2012 in your header.php you would have something a bit like this : $tags = "<meta tags=\""; foreach ($article as $tag) $tags .= $tag->tag_word.","; } $tags = substr($tags,-1); $tags .= "\" />"; echo $tags; Quote Link to comment https://forums.phpfreaks.com/topic/270717-pass-parameters-from-indexphp-tag-to-headerphp-meta/#findComment-1392574 Share on other sites More sharing options...
donrobertito Posted January 24, 2013 Author Share Posted January 24, 2013 Dear Muddy_Funster, I come back to this project, I had so much to do, that I had no time for this, but this is really important to me to learn php! So than you for your help. There is something not clear with your suggestion: - I think, there is one "{" is missing, but I found his place... - As you can see, the "tag" is used in the "Tags:" line on the bottom of the page. Is this a good idea to use it in your example? - You defined multiple times the $tags variable. Is this rigth? Your example is not working for me... Thanks: Robert Quote Link to comment https://forums.phpfreaks.com/topic/270717-pass-parameters-from-indexphp-tag-to-headerphp-meta/#findComment-1407900 Share on other sites More sharing options...
donrobertito Posted January 24, 2013 Author Share Posted January 24, 2013 And it could be also the problem, that the article tags are way after my header.php definied... Or I got it wrong? Quote Link to comment https://forums.phpfreaks.com/topic/270717-pass-parameters-from-indexphp-tag-to-headerphp-meta/#findComment-1407917 Share on other sites More sharing options...
PFMaBiSmAd Posted January 24, 2013 Share Posted January 24, 2013 (edited) If you are defining or retrieving data in index.php, after the point where you have included header.php, that data does not exist at the time the header.php code is executed. Programming does not have the ability to go back in time. Using php include statements to paste together a page can only produce a very basic page. To do what you need, you must switch to a concept of having all the main php 'business' logic first on the page. That php code produces content that is stored in variables (different variables for the title, meta tags, navigation links, content...) Then you output your HTML document at the end of the code, echoing the php variables at the correct point to give you the output that you want. Edited January 24, 2013 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/270717-pass-parameters-from-indexphp-tag-to-headerphp-meta/#findComment-1407932 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.