jstgermain Posted January 10, 2007 Share Posted January 10, 2007 here is the problem, and hopefully somone will have a solution. i set my new site to have the menu be php and run on the mysql database, and obviously all the content too, but when i go to the home page, nothing displays as far as content since there is no link selected yet. how can i get it to automatically display the same info as the home link if no link has been clicked yet?here is a link to the site to see what i am talking abouthttp://www.mct-hosting.comthe content i want to display will be the same as:http://www.mct-hosting.com/index.php?page=Homehere is a little code that might help.[code]<?php#This is in the index page$get = mysql_query("SELECT * FROM `Menu` WHERE l_name='$_GET[page]'") OR DIE(mysql_error());$page = mysql_fetch_assoc($get);//table settings are here, NOT IMPORTANT FOR THIS//code for displaying the content once a link is clickedecho $page['content'];?>[/code]here is the code for the links that makes the content display[code]<?php$query1 = "SELECT * FROM Menu WHERE 1 AND id=1"; $link1 = mysql_query ($query1);$l1 = mysql_fetch_array ($link1, MYSQL_ASSOC); echo '<a href="index.php?page='.$l1['l_name'];.'">'.$l1['name'];.'</a>?>[/code]hopefully that helps with solving the problem. Link to comment Share on other sites More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 [code]if(!$_GET['page']){ $page = (whatever your home page num is)}else{ $page = $_GET['page'];}[/code]You need to read about SQL injection too. And what is up with your query? Take out the WHERE 1 AND, just do WHERE Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 10, 2007 Share Posted January 10, 2007 as jesi said you'll want to worry about that sql injection, you can check out the magic quotes function [url=http://www.php.net/mysql_real_escape_string]here[/url] for a quick fix, but it would be good for you to read up on the problem yourself. Link to comment Share on other sites More sharing options...
magic2goodil Posted January 10, 2007 Share Posted January 10, 2007 [quote author=jesirose link=topic=121732.msg501038#msg501038 date=1168398976][code]if(!$_GET['page']){ $page = (whatever your home page num is)}else{ $page = $_GET['page'];}[/code]You need to read about SQL injection too. And what is up with your query? Take out the WHERE 1 AND, just do WHERE [/quote]wouldn't that be:[code]if(empty($_GET['page'])){ $page = "Home";}else{ $page = $_GET['page'];}[/code] Link to comment Share on other sites More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 Either one would work. Link to comment Share on other sites More sharing options...
magic2goodil Posted January 10, 2007 Share Posted January 10, 2007 [quote author=jesirose link=topic=121732.msg501044#msg501044 date=1168399222]Either one would work.[/quote]Pretty sure trying to call that $_GET variable as a bool would cause an error... Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 10, 2007 Share Posted January 10, 2007 I'm pretty sure you're wrong ;) try it! Link to comment Share on other sites More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 PHP uses weak typing. You can use ! on false, 0, null, anything. Link to comment Share on other sites More sharing options...
magic2goodil Posted January 10, 2007 Share Posted January 10, 2007 [quote author=jesirose link=topic=121732.msg501068#msg501068 date=1168401305]PHP uses weak typing. You can use ! on false, 0, null, anything. [/quote]Doesn't mean that it's correct coding just because PHP enables laziness. Link to comment Share on other sites More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 It's correct in PHP. If PHP had strong typing, it'd be wrong. But it's fine since that's what the language supports. If you don't want to take advantage of the weak typing, that's fine, but that doesn't make it wrong to use ! on many types. What you said was wrong. You said it would cause an error, and it doesn't. Link to comment Share on other sites More sharing options...
magic2goodil Posted January 10, 2007 Share Posted January 10, 2007 Well I didn't say it as the pure moral behind the sloth of it, I said it because I come from a C and Java background and was under the impression it worked the same. My bad cranky. :P Link to comment Share on other sites More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 Hey I'm a Sun Certified Java Programmer. (la dee dah, right?)Every language has it's strong points and weak points. I don't think using weak typing encourages laziness, but makes it easier to pick up and start working. In Java, it often takes a lot more work to do something simple - but if you need an "enterprise" app, Java is often a better choice. It just depends what you're doing. Doesn't mean PHP makes people lazy :-P Link to comment Share on other sites More sharing options...
jstgermain Posted January 10, 2007 Author Share Posted January 10, 2007 ok, well, none of the code you guys tried to help with did anything. the closest help came from magic2goodil, but left out that i still needed to query the database to get the results to echo the correct row, but i appreciat you guys and gals trying to help. that is why i love this community. even though i didnt get what i was looking for, i was still pointed in a good direction to figure it out myself.jesirose, as far as the sql injection, i am not sure exactly how that would happen with this site, but i will definately look into it and see if i can find some things to make it a little more secure. thanks fo rthe advise. Link to comment Share on other sites More sharing options...
Recommended Posts