Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

link and display

Posted on 2005-05-09
8
Medium Priority
?
181 Views
Last Modified: 2006-11-18
hi,,
I am trying to take values from DB and link each value to another page.
for example, I have 7 categories and 70 subcategories and 200 products.
I will have only one main subcategory page and when I click one of 7 categories, it will call one of subcategories in main subcategory page everytime.
so, I don have to make 70 different subcategory of PHP pages....

Well.. I look  php example site. when I click, it shows
http://www.cypress.com/portal/server.pt?space=CommunityPage&cached=true&parentname=CommunityPage&parentid=3&in_hi_userid=2&control=SetCommunity&CommunityID=223&PageID=0
when I click one of lists, it only changes ID number...
http://www.cypress.com/portal/server.pt?space=CommunityPage&cached=true&parentname=CommunityPage&parentid=3&in_hi_userid=2&control=SetCommunity&CommunityID=209&PageID=0

How can I do that??

this is a code that I can get only one subcategory of category.

Thank you in advance.

<?
include 'config.php';
$query  = "SELECT PNAME, PDESC, PID FROM products WHERE SUBCAT_ID='SC1'";

$result = mysql_query($query, $link);

      while($row = mysql_fetch_array($result, MYSQL_ASSOC))
   {
    echo "<tr align=\"left\" valign=\"top\" bordercolor=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
    echo "<td height=\"19\" align=\"left\" valign=\"middle\" class=\"porductdesc\"><a href=\"{$row['PID']}.php\" class=\"porductdesc\"> {$row['PNAME']} </td>";
    echo "<td class=\"porductdesc\">{$row['PDESC']}</td>";
      echo "</tr> ";
    }
?>
0
Comment
Question by:bbvic
  • 5
  • 2
8 Comments
 
LVL 4

Expert Comment

by:punkstar
ID: 13961796
could you make it a bit clearer?

i have no idea what you are trying to do...
0
 

Author Comment

by:bbvic
ID: 13962236
I have 200 products..I put those into product page.
each product will have each page..
But...I do not want to have 200 php pages..
it shows on one page depending on ID number.,..
how can I to that??

on my code, it displays if SUBCAT_ID='SC1'. but there are SC2, SC3....and SC10.

<?
include 'config.php';
$query  = "SELECT PNAME, PDESC, PID FROM products WHERE SUBCAT_ID='SC1'";

$result = mysql_query($query, $link);

     while($row = mysql_fetch_array($result, MYSQL_ASSOC))
   {
    echo "<tr align=\"left\" valign=\"top\" bordercolor=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
    echo "<td height=\"19\" align=\"left\" valign=\"middle\" class=\"porductdesc\"><a href=\"{$row['PID']}.php\" class=\"porductdesc\"> {$row['PNAME']} </td>";
    echo "<td class=\"porductdesc\">{$row['PDESC']}</td>";
     echo "</tr> ";
    }
?>
0
 

Author Comment

by:bbvic
ID: 13962248
I have 200 products..I put those into DB.
each product will have each page..
But...I do not want to have 200 php pages..
it shows on one page depending on ID number.,..
how can I to that??

on my code, it displays if SUBCAT_ID='SC1'. but there are SC2, SC3....and SC10.

<?
include 'config.php';
$query  = "SELECT PNAME, PDESC, PID FROM products WHERE SUBCAT_ID='SC1'";

$result = mysql_query($query, $link);

     while($row = mysql_fetch_array($result, MYSQL_ASSOC))
   {
    echo "<tr align=\"left\" valign=\"top\" bordercolor=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
    echo "<td height=\"19\" align=\"left\" valign=\"middle\" class=\"porductdesc\"><a href=\"{$row['PID']}.php\" class=\"porductdesc\"> {$row['PNAME']} </td>";
    echo "<td class=\"porductdesc\">{$row['PDESC']}</td>";
     echo "</tr> ";
    }
?>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:bbvic
ID: 13962466
example site..
main page
http://www.weberdev.com/
example page
http://www.weberdev.com/CodeExamples.php
In CodeExamples.php  there are Many examples...like
http://www.weberdev.com/get_example.php3?count=4163
http://www.weberdev.com/get_example.php3?count=4162
....
These proceses are what I wanted to explain..
0
 

Author Comment

by:bbvic
ID: 13962878
got it..

<?php
// f.php
  function abc () {
    echo "ABC";
  }

  function xyz () {
    echo "XYZ";
  }

  $v = $_REQUEST["f"];

  $v();
?>

<a href="myscript.php?f=abc">Click me</a>
<a href="myscript.php?f=xyz">Click me</a>
<?php
if ($_GET['function'] == 'myfunction')
{
  myfunction();
}
?>
0
 
LVL 7

Accepted Solution

by:
minnirok earned 2000 total points
ID: 13996745
Did you solve this problem to your satisfaction?

Looking at your last post, you can improve upon the methodology for creating seperate listings for each page;  Creating a function for each product (however simple the functions are) is alot of unnecessary extra code.

The good news is that you seem to be on the right track.  From an implementation standpoint, it's easiest to link to one php page that will dynamically output information from the database...  You'll have two pages; one that prints out the listing of links, and another that will receive this and print out all relevent information on the product specified.

<?php
// your initial page's code reworked
include( "config.php" );

//initialize data variables (don't *need* to do this in
// php, but do it for the sake of clarity)
$arraySubCat = array(); //array of our subcategories
$output = "";            //string output
$destPage = "myscript.php"      //page to display products

//lets loop through all subcategories to extract them
//this way if you add more, you dont have to modify
//any of your code
$query0 = "SELECT SUBCAT_ID FROM products;";
$result0 = mysql_query($query0, $link);

while($row = mysql_fetch_array($result) ) {
      $arraySubCat[] = $row[0]; //insert each subcategory into our array
}

//now we have each subcategory, so we will loop through each one
//and generate all the product links for each one
$numSubCat = sizeof($arraySubCat);
for( $i=0; $i<$numSubCat; $i++ ) {
      $tempQuery = "SELECT PNAME, PDESC, PID FROM products WHERE SUBCAT_ID = '" . $arraySubCat[$i] . "';";
      $tempResult = mysql_query( $tempQuery, $link );

      //output heading if we found anything
      if( @mysql_num_rows($tempResult) > 0 )
            $output .= "<tr>\n<td colspan=\"2\"><h2>{$arraySubCat[$i]}</h2></td>\n</tr>\n";

      //our while loop
      while($row = mysql_fetch_array($tempResult, MYSQL_ASSOC)) {
            $output .= "<tr valign=\"top\" bordercolor=\"#FFFFFF\" bgcolor=\"#FFFFFF\">\n";
            $output .= "<td height=\"19\" align=\"left\" valign=\"middle\" class=\"porductdesc\"><a href=\"{$destPage}?id={$row['PID']}\" class=\"porductdesc\"> {$row['PNAME']}</a></td>\n";
            $output .= "<td class=\"porductdesc\">{$row['PDESC']}</td>\n";
            $output .= "</tr>\n";
      }
}

if( @strlen($output) > 0 ) {
      echo "<table>\n" . $output . "</table>\n";
} else {
      echo "No Results products in db";
}

?>

then myscript.php (or whatever $destPage happens to be) would print out info based on what id happened to be...

<?php
//myscript.php
include( "config.php" );      //db includes, may we assume?

//get id from query string
parse_str($_SERVER['QUERY_STRING'],$vars);
if( isset( $vars['id'] ) ) )
      $locID = mysql_real_escape_string($vars['id']);

$query = "SELECT PNAME, PDESC FROM products WHERE PID = '$locID' LIMIT 1;";
$result = mysql_query( $query, $link );
$row = mysql_fetch_row( $result, MYSQL_ASSOC );
echo "<h1>{$row['PNAME']}</h1>\n";
echo "<p>{$row['PDESC']}</p>\n";

?>

hope this is of some help.
0
 
LVL 7

Expert Comment

by:minnirok
ID: 13996764
line 16 should be $result0 not $result

while($row = mysql_fetch_array($result0) ) {
0
 

Author Comment

by:bbvic
ID: 14752141
thank you..
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question