SunQuest
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 21st, 2004, 05:57 PM
cbunting cbunting is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 19 cbunting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to combine 2 php pages into 1?

Hello All,
I am having some problems trying to make one php page instead of having 2 seperate ones.

The first page simply connects to mysql and lists the article headlines. It also generates the topic and the link to the article on the second page, article_view.php?view=ID

The article_view page has an IF statement and this is where I'm getting confused. At the end, I have an else statement which I want to show the article headlines by default, but it's not showing anything unless the url includes ?view.

Example:

if ($view != "")
{

.......... mysql stuff...

else
{

.......... mysql stuff.. Show Article Headlines.
}
}
?>

Not sure if I exaplained the well. The example above is what I am trying to get to work. I just need the else statement and the mysql code to display without the need for ?view. I would like the headlines to appear by just visiting articles.php.

Thanks for your time,
Chris

Reply With Quote
  #2  
Old January 21st, 2004, 07:54 PM
aboyousif aboyousif is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Tanta, Egypt
Posts: 21 aboyousif User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 23 sec
Reputation Power: 0
Send a message via AIM to aboyousif Send a message via MSN to aboyousif Send a message via Yahoo to aboyousif
Finally i Found it :)

ok cbunting .. let's see what we need here ..

as you wrote ( or as i understand ) you want to make only one .php file that

1- connect to database
2- list articles headlines
3- view the articles ..

i will not ask you why this pain .. but here is the answer ..

1- you need to make a function to connect to database
2- make a page that list the headlines (on the fly )
3- make a page of the article view
and merger this 3 steps into one file

let's see

PHP Code:
<?
// step number 1
function connection(){
$link mysql_connect("localhost""root""") or die("Could not connect: " mysql_error());
mysql_select_db("dbasename") or die("could not get database: " mysql_error() );
}
// end of step 1

// step 2
if ($_GET['id'] == 0){
connection();
$query="select * from authors ";
$result=mysql_query($query) or die ("Unable to Made the Query:" mysql_error() );

while(
$row=mysql_fetch_array($result)){
echo 
$row['user'];
echo 
"<br>";
?>
<a href="eed2.php?id=
<?
echo $row['id'];
?>
" >ClickHere </a>
<?
}
}

// end of step 2

// step 3
if ($_GET['id']>0){
connection();
$selecid=$_GET['id'];
echo 
$selecid;
$query2 "select * from authors where id='$selecid'" ;
$result2=mysql_query($query2) or die("could not do this .. "mysql_error() );
$row2=mysql_fetch_assoc($result2);
echo 
$row2["id"];
echo 
"<br>";
echo 
$row2["user"];
echo 
"<br>";
//and finally the topic or password :)
echo $row2["passwd"];
?>
<hr>
<br>
<a href="eed2.php">Back</a>
<?
mysql_free_result
($result2);
}


?>
// end of step 3


first i made a function called connection() and added some things to connect to database

second i made an if condition assuming that the id not selected so the id will be 0 ..
and made a query to select all fields and add them to row and show the headline and ( click here link to the third option )

third .. the step 3 will take you to new on fly page and list the fields in new query as i did ..

i used a premade database of me has only one table containg 3 fields only ( id . user . passwd ) .. use your mind to change the names of fileds and tables and the strings of database to be suitable for ur site or project ..

don't forget to pray for me

Reply With Quote
  #3  
Old January 21st, 2004, 09:39 PM
cbunting cbunting is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 19 cbunting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks aboyousif...

This is perfect and exactly what I was looking for. If you wondered why I was wanting to do this, basicly it's because I am trying to learn a few things and this code you provided gave me that plus alot more. I am interested in how the fuction something() works and now I see that as well.

Thanks again,
Chris

Reply With Quote
  #4  
Old January 21st, 2004, 09:54 PM
aboyousif aboyousif is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Tanta, Egypt
Posts: 21 aboyousif User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 23 sec
Reputation Power: 0
Send a message via AIM to aboyousif Send a message via MSN to aboyousif Send a message via Yahoo to aboyousif
you are welcome ...
any time ..

Advice : try to download the manual of php from the php.net site ..

i use it to learn php ... it is very useful

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > How to combine 2 php pages into 1?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway