Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 06-09-2007, 02:21 PM
Andy128's Avatar
Major General
 
Join Date: Dec 2005
Location: Michigan
Posts: 2,293
Default db retrieval

I have a php display script that takes data from a flat file db and transforms it into an array and then displays that info in a table. No problems with this.

Each line of data in the db contains 8 items. The first item is the genre or group identifier. For example:
cars|2001|Dodge|Blue
cars|2003|Chevy|Green
truck|2006|Dodge|Black

What I would like to do create a link to the display script. That link URL would contain or pass a variable (the genre / group identifier) to the display script that in turn displays only those items inside that genre or group.

The display script is below:
PHP Code:
<html>
<head>
<style>
.th{background:#ccdd88;}
.td{background:#fffff0;}
.tr{text-align:right;}
.tc{text-align:center;}
.pr{padding-right: 6px;}
.plr{padding-left:6px;padding-right:6px;}
.w1{width:100px;}
.w2{width:75px;}
.w3{width:400px}
</style>
<body>
<?php
///////////////////////////////////////////////////////////
//Here I assume I would declare the genre variable that is passed
//in the URL from the link ???
///////////////////////////////////////////////////////////
if(!file_exists("db_display_test.txt"))
{
echo
"<center><b>NO RECORDS AT THIS TIME</center></b><br/>
<center>CHECK BACK LATER</center>"
;
exit;
}
echo
"<table border=6 width=100% cellpadding=2 cellspacing=6>";
echo
"<tr>";
echo
"<th class='th plr'>Box 1</th>";
echo
"<th class='th plr'>Box 2</th>";
echo
"<th class='th plr'>Box 3</th>";
echo
"<th class='th plr'>Box 4</th>";
echo
"<th class='th plr'>Box 5</th>";
echo
"<th class='th plr'>Box 6</th>";
echo
"<th class='th plr'>Box 7</th>";
echo
"</tr>";
//
$openedfile fopen"db_display_test.txt"'r' );
if(
$openedfile)
{
while (!
feof$openedfile ) )
    {
        
$line trim(fgets$openedfile ));
        if ( !empty( 
$line ) )
        {
            list( 
$genre,$entry1,$entry2$entry3$entry4$entry5$entry6$entry7) = explode"|"$line );
/////////////////////////////////////////////////////////////
//What would go here to list only those entries that matched
//a specific genre?
////////////////////////////////////////////////////////////
echo"<tr>";
echo
"<td class='td tc w2'>$entry1</td>";
echo
"<td class='td tc w1'>$entry2</td>";
echo
"<td class='td tc w2'>$entry3</td>";
echo
"<td class='td tc w2'>$entry4</td>";
echo
"<td class='td tc w2'>$entry5</td>";
echo
"<td class='td tc w2'>$entry6</td>";
echo
"<td class='td tc w2'>$entry7</td>";
echo
"</tr>";
}
}
fclose$openedfile );
}
else
{
echo
"<tr>";
echo
"<td class='th w3'>Cannot open file!</td>";
echo
"</tr>";
echo
"</table>";
}
?>
</BODY>
</HTML>
That is my dilemma.

Andy
__________________
My diamond in the rough - www.123gpp.com

* Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 06-09-2007, 02:27 PM
Andy128's Avatar
Major General
 
Join Date: Dec 2005
Location: Michigan
Posts: 2,293
Default Re: db retrieval

Apparently there are issues with the forum as I could not edit my above post.

Note- I have only listed 4 items for brevity in the db example. Additionally- in the display script, I have not displayed the genre in the table on purpose.

Andy
__________________
My diamond in the rough - www.123gpp.com

* Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 06-09-2007, 05:03 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,024
Default Re: db retrieval

Hi Andy,



PHP Code:
<html>
<head>
<style>
.th{background:#ccdd88;}
.td{background:#fffff0;}
.tr{text-align:right;}
.tc{text-align:center;}
.pr{padding-right: 6px;}
.plr{padding-left:6px;padding-right:6px;}
.w1{width:100px;}
.w2{width:75px;}
.w3{width:400px}
</style>
<body>
<?php
// Receiving the asked for genre, through a form in a previous page
@$askedforgenre addslashes($_POST['askedforgenre']);
 
if(!
file_exists("db_display_test.txt"))
{
echo
"<center><b>NO RECORDS AT THIS TIME</center></b><br/>
<center>CHECK BACK LATER</center>"
;
exit;
}
echo
"<table border=6 width=100% cellpadding=2 cellspacing=6>";
echo
"<tr>";
echo
"<th class='th plr'>Box 1</th>";
echo
"<th class='th plr'>Box 2</th>";
echo
"<th class='th plr'>Box 3</th>";
echo
"<th class='th plr'>Box 4</th>";
echo
"<th class='th plr'>Box 5</th>";
echo
"<th class='th plr'>Box 6</th>";
echo
"<th class='th plr'>Box 7</th>";
echo
"</tr>";
//
$openedfile fopen"db_display_test.txt"'r' );
if(
$openedfile)
{
while (!
feof$openedfile ) )
    {
        
$line trim(fgets$openedfile ));
        if ( !empty( 
$line ) )
        {
            list( 
$genre,$entry1,$entry2$entry3$entry4$entry5$entry6$entry7) = explode"|"$line );
/////////////////////////////////////////////////////////////
//What would go here to list only those entries that matched
//a specific genre?
////////////////////////////////////////////////////////////
if ($genre == $askedforgenre) {
echo
"<tr>";
echo
"<td class='td tc w2'>$entry1</td>";
echo
"<td class='td tc w1'>$entry2</td>";
echo
"<td class='td tc w2'>$entry3</td>";
echo
"<td class='td tc w2'>$entry4</td>";
echo
"<td class='td tc w2'>$entry5</td>";
echo
"<td class='td tc w2'>$entry6</td>";
echo
"<td class='td tc w2'>$entry7</td>";
echo
"</tr>";
}
}
}
fclose$openedfile );
}
else
{
echo
"<tr>";
echo
"<td class='th w3'>Cannot open file!</td>";
echo
"</tr>";
echo
"</table>";
}
?>
</BODY>
</HTML>
$askedforgenre of course can be changed to any variable name you like. A simple "if" statement is enough to only display those listings that match the required genre.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 06-09-2007, 06:53 PM
Andy128's Avatar
Major General
 
Join Date: Dec 2005
Location: Michigan
Posts: 2,293
Default Re: db retrieval

Naval- YOU ROCK! That was incredibly simple and it works perfectly.

Thanks again!

Reason: Currently I have about 125 pages each that lists businesses. So for Alarm Companies one would go to alarm_companies.html. But- I can enter all the businesses in a db and then use one page with the php script to get only those businesses that pertain to those that were requested. Thus effectively allowing me to have only two pages that serve up hundreds of pages worth of data. I hope you get what I mean.

I also did this: I am making a page (scrollable) with all the links to the various businesses / services for my directory. The link is made like this;
<a href="my_db.php?pg_genre=alarm_companies">Alarm Companies</a><br />
And in the script I have:
$pg_genre = $_GET['pg_genre'];

That way I do not need a form for them to fill out.

Very excited. I am going to be up all night!

Talk to ya later and thanks again.
Andy
__________________
My diamond in the rough - www.123gpp.com

* Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 06-09-2007, 06:59 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,024
Default Re: db retrieval

Yes, that is a very common way of passing values from a page to another. I use it myself all the time. I also use forms, if more than one values are to be passed (in that case i use database driven independent fieds or dependent (chained) dropdowns).Well done Andy!
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 06-11-2007, 01:23 PM
Andy128's Avatar
Major General
 
Join Date: Dec 2005
Location: Michigan
Posts: 2,293
Default Re: db retrieval

Naval-
I also made the table scrollable and placed that code inside an html box. In this manner- it is more SE friendly than an I-Frame containing the table.

Have a look at this site. I believe it will be a good resource to others that you help along the way.
http://www.htmlbasix.com/scrollingtable.shtml

Lots of cool stuff on that site.

Cheers-

Andy
__________________
My diamond in the rough - www.123gpp.com

* Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 03:55 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2007 VodaHost.com - All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54