Jump to content

Archived

This topic is now archived and is closed to further replies.

rand3h

SERIOUS PHP NOOB HERE

Recommended Posts

Hi I created a site and I heard somewhere that creating tables in php is much better than framing in HTML. So, i did exactly that.

[a href=\"http://www.rav3online.com/randysocandy/rr/HTML/\" target=\"_blank\"]http://www.rav3online.com/randysocandy/rr/HTML/[/a]
thats the beta stage of my site, don't laugh, it's pretty mediocre as I am just learning this. anywho..

i've realized that using the php instead of frames is very beneficial when it comes to site changes. This way, I won't have to change EVERY single .php file in order to keep the site maintained. But as I was making the files, I had a index.php attached with a main.php as the main page content. I have a link that leads to the about us page. But hte problem was, when i linked it to the aboutus page, i realized it only linked to that specific file instead of the index + aboutus.php . Is there a way so that I could somehow keep the index.php and add whatever content i need for each link???? I can't seem to figure out how the linking works without having to create two aboutus php files. It's very frustrating =(
PLEASE HELP!
I'm sorry if my noobiness has confused u. let me know so i can clarify the problem a little more!!


p.s. - is there a way that I can somehow automatically feed my sidebar to receive updated news?? I hate the fact that I have to update it every single time. There's gotta be an easier way no?


-randy

Share this post


Link to post
Share on other sites
I suggest switch statement instead of frames, like this
[code]
<?php

// top layout here, or include header file

switch ($_GET['view'])
{
case 'about':
include ("path/about.html");
break;

case 'news':
include ("path/news.php");
break;

default:
include ("path/welcome.php");
break;
}

// footer layout here, or include footer file

?>
[/code]

You see the pattern, if this is called index.php , calling --> index.php?view=about <-- would include about.html

As to the news-bar, once you get more familiar with php i suggest mysql database to store news and then get news from the database as many ways as you wish :)

Share this post


Link to post
Share on other sites
doesn't that mean i have to add those lines for EVERY link i have to my site???

Share this post


Link to post
Share on other sites
It depends on how your site is build, and if i understand you correctly you currently only have text files. Then the answer is YES if you want to use switch like in my example above.

You can do a different twist and include files based on GET variable directly - BUT do it with caution as it is in some cases very vounerable to url injection attacs,

example if all your include pages end with .html:
[code]
$view = htmlspecialchars($_GET['view']);
$page = "path/".$view.".html";

if(empty($view))
{
include ("path/welcome.html");
}
else
{
if(file_exists($page))
{
include ($page);
}
else
{
print "Page not found";
}
}
[/code]
Then call it with --> index.php?view=about <-- that will include --> about.html

Share this post


Link to post
Share on other sites
what if they are php files that i would like to put in? does it matter or can i just switch the .html part to .php?

Share this post


Link to post
Share on other sites
Yes you can - or you can make it compatible with both by using different GET calls
[code]
if(!empty($_GET['html']))
{
$view = htmlspecialchars($_GET['html']);
$page = "path/".$view.".html";
}
elseif(!empty($_GET['php']))
{
$view = htmlspecialchars($_GET['php']);
$page = "path/".$view.".php";
}
else
{
$page = "path/welcome.html";
}

if(file_exists($page))
{
include ($page);
}
else
{
print "Page not found";
}
[/code]

Either call it with --> index.php?html=about <-- that will include --> about.html
OR call it with --> index.php?php=about <-- that will include --> about.php

Share this post


Link to post
Share on other sites
going back to the mysql database for adding news content on my page..
exactly what must i do to do that? I'm just looking to add news from say.. msn or some third party news syndicate but I would prefer to somehow automatically update that portion. Ive seen a few RSS feeds so i was wondering what would be best for my situation.

www.rankreview.com

the left side would be my news content part. what do u suggest i do and exactly how would i do it????
I'm so lost when it comes to that stuff.



Also, i had a question off the topic but I was wondering how
[a href=\"http://www.prosportsdaily.com/\" target=\"_blank\"]http://www.prosportsdaily.com/[/a]
works. obviously the owner of the site doesn't update all those .htmls daily. I mean.. 20-something teams for a good 5 different sports is impossible. I understand that he made his page look for keywords from certain pages. I could be really off too..

Share this post


Link to post
Share on other sites
To feed your sidepanel, create your script, save it as something like news.php. Then include it in your main page in the left panel

[code]
<?php
include 'news.php';
?>
[/code]

Just a quick copy, paste and edit of one of my news scripts:

[code]
<?php
//db.inc.php

mysql_connect ("localhost", "username", "password") or die (mysql_error());
mysql_select_db("your_db_name_here") or die (mysql_error());

?>
[/code]

[code]
//news.php

<?php
include 'db.inc.php';//db username and pass
?>

<p class="heading">
News & Announcements
</p>
<?php
$result = mysql_query("SELECT * FROM news ORDER BY date DESC") or die (mysql_error());
while ($row = mysql_fetch_array($result)) {
?>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><b><?=$row['subject'];?></b>
</tr>
<tr><td>
<?php
echo $row['body'];
echo "<br>";
?><br><br>Posted on <?=$row['date'];?><hr/>
</td>
</tr>
<tr>
<td></td>
</tr></table><br>
<?
}
?>

[/code]

The code above will fetch everything from your db, from the table 'news', ordered by the newest date, and loop through echoing the heading, body, and then the date it was posted on.

Hope this helps

Share this post


Link to post
Share on other sites
ok, done that. now how do i feed it to my database. and where do i get the content for it? and are rss involved with this somehow?




i'm sorry, im a real mysql nub.

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]ok, done that. now how do i feed it to my database. and where do i get the content for it? and are rss involved with this somehow?[/quote]

What exactly do you mean? RSS is not involved. The script i provided, will connect to the db and retrieve all the info out of it, and then put everything into a table. If you want to add news, you can use something like phpMyAdmin, or alternatively, write your own script that inserts data into the db.

hth.

Share this post


Link to post
Share on other sites

×

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.