dossie Posted August 17, 2009 Share Posted August 17, 2009 Hi, i'm busy with a site which shows information out of a dbase. No problem with making a connection to the dbase or getting the information from the dbase to the site but it goes wrong when i try to get the fields into an include. I want to break my page into different includes so I might be able to change text for all pages at once. Does anybode know where I go wrong? <? include('../dbaseincludes/connectioninclude.php'); include('../dbaseincludes/doctypeinclude.php'); $query = 'SELECT * FROM affiliates WHERE id="4"'; if ($result = mysql_query($query)){ echo ""; } else{ echo "Something went wrong, possibly you don't see all information"; exit; } while ($rij = mysql_fetch_array($result)) { // this include doesn't work include('../dbaseincludes/metainclude.php'); // this echo gives the good information but when I try to get it into an include it doesn't work echo "{$rij['town']}"; // these things I need in 3 different includes echo "<h4>{$rij['name']}</h4>"; echo "adress: {$rij['adress']}<br>"; echo "website: <a href={$rij['siteUrl']} target=_blank>{$rij['name']}</a>"; echo "<br><br>"; echo "<h4>Opinion</h4>"; echo "<a href={$rij['siteUrl']} target=_blank>Click here for opinions</a>"; echo "<br><br>"; echo "<h4>Is {$rij['name']} not what you're looking for?</h4>"; echo "<a href={$rij['more']}>Click here for more opinions</a>"; // this goes allright include('../tip.php'); echo "</div>"; echo "<!-- end #welcome -->"; include('../onderaan3.php'); echo "</div>"; echo "</body>"; echo "</html>"; } ?> Thanks! Arjen Quote Link to comment https://forums.phpfreaks.com/topic/170632-solved-problem-with-includes-from-dbase-in-php-script/ Share on other sites More sharing options...
dossie Posted August 17, 2009 Author Share Posted August 17, 2009 And to be a little bit more specific: Before I said: // this include doesn't work include('../dbaseincludes/metainclude.php'); ..That's not totally correct, the include does work for the css, the divs and all the written content but not for the dbase fields.. The include looks like this: <title>{$rij['name']} in {$rij['town']}</title> <meta http-equiv=content-type content=text/html; charset=iso-8859-1/> <meta name=description content={$rij['name']} in {$rij['town']}./> <meta name=robots content=index, follow /> <meta name=author content=vandorsten /> <meta name=design content=vandorsten /> <meta name=copyright content=vandorsten /> <meta name=language content=Dutch /> <meta name=country content=The Netherlands /> <meta name=revisit-after content=7 /> <meta name=keywords content={$rij['name']},{$rij['town']}/> <link href=/default.css rel=stylesheet type=text/css /> </head> <body> <div id=logo> </div> <div id=page> <div id=content> <div id=welcome> Quote Link to comment https://forums.phpfreaks.com/topic/170632-solved-problem-with-includes-from-dbase-in-php-script/#findComment-900300 Share on other sites More sharing options...
ignace Posted August 17, 2009 Share Posted August 17, 2009 First of all: add the while inside the if ($result ..) otherwise your while will execute even if your if failed. You can even extend to make sure there is something to loop over. $result = mysql_query($query); if ($result && mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { .. } } Second: $query = 'SELECT * FROM affiliates WHERE id="4"'; Implies your result will be one row which makes the while redundant: $result = mysql_query($query); if ($result && mysql_num_rows($result)) { $rij = mysql_fetch_assoc($result); // this include doesn't work include('../dbaseincludes/metainclude.php'); // this echo gives the good information but when I try to get it into an include it doesn't work echo "{$rij['town']}"; // these things I need in 3 different includes echo "<h4>{$rij['name']}</h4>"; echo "adress: {$rij['adress']}<br>"; echo "website: <a href={$rij['siteUrl']} target=_blank>{$rij['name']}</a>"; echo "<br><br>"; echo "<h4>Opinion</h4>"; echo "<a href={$rij['siteUrl']} target=_blank>Click here for opinions</a>"; echo "<br><br>"; echo "<h4>Is {$rij['name']} not what you're looking for?</h4>"; echo "<a href={$rij['more']}>Click here for more opinions</a>"; // this goes allright include('../tip.php'); echo "</div>"; echo "<!-- end #welcome -->"; include('../onderaan3.php'); echo "</div>"; echo "</body>"; echo "</html>"; } P.S. Groeten vanuit België Quote Link to comment https://forums.phpfreaks.com/topic/170632-solved-problem-with-includes-from-dbase-in-php-script/#findComment-900340 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.