Jump to content

default text if no link selected


jstgermain

Recommended Posts

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 about
http://www.mct-hosting.com

the content i want to display will be the same as:
http://www.mct-hosting.com/index.php?page=Home

here 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 clicked
echo $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

[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

[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

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

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

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

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.