gurhy Posted January 26, 2008 Share Posted January 26, 2008 Hi all just wondering if any 1 know how to make this work? <? $main_page = mysql_query("SELECT * FROM menu") or die(mysql_error()); while ($row = mysql_fetch_array ($main_page)) { if($owh == $row["url"]) { include("$row[url2]"); } } ?> at the moment it anly displays the first page in the database but I would like it to pull all the info from it (every row) which is only 10 rows. I am not sure what to do Quote Link to comment Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 <?php $sql = "SELECT * FROM `menu`"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ if($owh == $row['url']){ include $row['url2']; }else { include $row['url3']; } } ?> something like that i suppose. Quote Link to comment Share on other sites More sharing options...
gurhy Posted January 26, 2008 Author Share Posted January 26, 2008 just tried it but it lists every thing in 1 go Iwhat I mean is to list every thing but will not show that page unless I click the URL thats what the if($owh == $row['url']){ comes in, but its not showing the way it should Quote Link to comment Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 What is $owh defined to. Quote Link to comment Share on other sites More sharing options...
gurhy Posted January 26, 2008 Author Share Posted January 26, 2008 thats what calls this from the address bar index.php/?owh=Services Quote Link to comment Share on other sites More sharing options...
Aureole Posted January 26, 2008 Share Posted January 26, 2008 Then don't you need to be using $_GET['owh'] instead of $owh? Quote Link to comment Share on other sites More sharing options...
gurhy Posted January 26, 2008 Author Share Posted January 26, 2008 just tried that, but gives the same result of not loading the page thats suppose to be included, just returns the page empty Quote Link to comment Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 do this: <?php $sql = "SELECT * FROM `menu`"; $res = mysql_query($sql) or die(mysql_error()); echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<tr><td>Menu ID</td><td>URL One</td><td>URL Two</td></tr>\n"; while($row = mysql_fetch_assoc($res)){ echo "<tr><td>".$row['id']."</td><td>".$row['url']."</td><td>".$row['url2']."</td></tr>\n"; } echo "</table>\n"; ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted January 26, 2008 Share Posted January 26, 2008 May help if you verify the actual column names in the DB. Quote Link to comment Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 Exactly what I'm doing for him. Quote Link to comment Share on other sites More sharing options...
gurhy Posted January 26, 2008 Author Share Posted January 26, 2008 yea all in database are correct here is whats printed mgallforever Menu ID URL One URL Two 1 main.php 2 ?owh=product /pages/product.php 5 ?owh=Services pages/product.php 6 ?owh=Programs pages/product.php 10 ?owh=Order pages/product.php 11 ?owh=Policy pages/product.php 12 ?owh=Agreement pages/product.php 13 ?owh=Copyright pages/product.php page is not meant to display like that though so I am guessing you wanted to see if it printed any thing out Quote Link to comment Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 I see. Remove ?owh= from each of the $row['url'] or you can do something like: <?php $owh = $_GET['owh']; $sql = "SELECT * FROM `menu`"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ $splode = explode('=',$row['url']); if($splode[1] == $owh){ include $row['url2']; } } ?> Quote Link to comment Share on other sites More sharing options...
gurhy Posted January 26, 2008 Author Share Posted January 26, 2008 I just used that script and now it reports all the pages like I need now I can add propa products and services. 1 bit I dont get is why I am now getting this error after adding this in :S Warning: main() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/owhostin/public_html/index1.php on line 56 Warning: main() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/owhostin/public_html/index1.php on line 56 Quote Link to comment Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 Your files obviously don't exist. if(file_exists($row['url2'])){ include " ".$row['url2']." "; }else { echo "File does not exist!\n"; } Quote Link to comment Share on other sites More sharing options...
revraz Posted January 26, 2008 Share Posted January 26, 2008 Check your PHP.INI include path setting. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted January 26, 2008 Share Posted January 26, 2008 <?php if(file_exists($row['url2'])){ require " ".$row['url2']." "; }else { echo "File does not exist!\n"; }?> Quote Link to comment Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 You just changed include to require from my script, lol. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted January 26, 2008 Share Posted January 26, 2008 from the examples i have seen row works better when you use require Quote Link to comment Share on other sites More sharing options...
gurhy Posted January 26, 2008 Author Share Posted January 26, 2008 hmmm that code u just sent just got rid of the error, but dont want File does not exist! to be showing up on my main page, hehe dont get what file does not exist as all files do exist. Dont get what you mean Check your PHP.INI include path setting. what do you mean about include path setting???? I do not control this php.ini so Quote Link to comment Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 the file obviously doesn't exist... the one being included. do this instead of inclusion: echo $row['url2']; then go see if that's anywhere on your server Quote Link to comment Share on other sites More sharing options...
gurhy Posted January 26, 2008 Author Share Posted January 26, 2008 well just checked but the page thats loading is there and is showing but that bit of script is also saying that the page dont exist. confusing. guess I have to keep that error and just leave that echo "File does not exist!\n"; blank so its just echo ""; cos I see all pages are loading and at the moment they are all still product.php for every page and no other url is visable so I leave that echo blank and no 1 ever notice the differnce while looking at the website like a friendly patch on the error hehe Thanks for all you help guys as this been bugging me for ages and never woulda got as far as I have with out you all here Quote Link to comment 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.