Forum Moderators: coopster

Message Too Old, No Replies

1 Menu/12 Categories/1 PHP Page

         

Mtlinfo

7:20 pm on Sep 5, 2006 (gmt 0)

10+ Year Member



Hi guys,

I'm trying to replicate this type of php coding here.

<snipped url>

Basically, it's a simple menu on the left side that retrieves the info of a table (cat) and 12 different fields (ex: Area Guides, Business, etc...) containing web site addresses.

My question to you is, how can we use the same php page (res.php in this case) to retrieve the content of 12 different fields?

You see, I would have created 12 different php pages while this guy managed to use only one page to do it!

Could you please tell me how he did it and maybe paste me some php code to do something similar?

Thanks a lot.

Richard

[edited by: Mtlinfo at 7:22 pm (utc) on Sep. 5, 2006]

[edited by: coopster at 7:25 pm (utc) on Sep. 5, 2006]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]

eelixduppy

7:26 pm on Sep 5, 2006 (gmt 0)



For this I would do a switch statement. Something like this:

$cat = $_GET['cat'];
switch($cat) {
case 'business':
$table = 'Business';
break;
case 'area_guides':
$table = 'Area_Guides';
break;
default:
$table = 'Default_Table';
break;
}
$query = "SELECT * FROM ".$table;

Good luck!

Mtlinfo

8:05 pm on Sep 5, 2006 (gmt 0)

10+ Year Member



Hi eelixduppy.

Sorry for the question, i'm a newbie in php here.

Ok below is my php page code here. Tried to insert your code but it doesn't work.

My main table is called Links and Cities, Business and Linktext are just Fields under it, each one containing web site URLs.

For now, I get this error msg...which is near the 2-3 last lines of code. Any ideas where the bug is?

Parse error: parse error, unexpected '}' in /domains/the-agent-link-com/the-agent-link/www_root/demos/1/1.php on line 34

Thanks

Richard

= = = = = = = =
<?
mysql_connect(localhost,user,pw);
@mysql_select_db(my_db) or die( 'Unable to select database');
$cat = $_GET['cat'];
switch($cat) {
case 'Cities':
$table = 'Cities';
break;
case 'Businesss':
$table = 'Business';
break;
default:
$table = 'Linktext';
break;
}
$query = "SELECT * FROM ".$Links;

echo "

<html>

<body>

<P>
<a href=1.php?cat=Cities>Cities</a>
<br>
<a href=1.php?cat=Business>Business</a>

</body>
</html>";

$i++;
}

?>

[edited by: Mtlinfo at 8:27 pm (utc) on Sep. 5, 2006]

Mtlinfo

8:56 pm on Sep 5, 2006 (gmt 0)

10+ Year Member



Alright, this is the code I have now and here's what it does.

<snipped url>

I see 2 links at the top of my page (Cities and Business) and inside the body of the php page, I placed the $cat code to display the URLs of each category.

When I click the link Cities the $cat below displays Cities and when I click the Business link the $cat displays Business. So far so good!

Now how can I get the $cat code to not only switch categories but to retrieve the db content inside Cities and Business?

Thanks,

Richard

= = = = = = = =
<?
mysql_connect(localhost,user,pw);
@mysql_select_db(my_db) or die( 'Unable to select database');
$query='SELECT * FROM Links';
$cat = $_GET['cat'];
switch($cat) {
case 'Cities':
$table = 'Cities';
break;
case 'Businesss':
$table = 'Business';
break;
default:
$table = 'Default_Table';
break;
}

echo "

<html>

<body>

<P>
<a href=1.php?cat=Cities>Cities</a>
<br>
<a href=1.php?cat=Business>Business</a>

<p>
$cat

</body>
</html>";

$i++;

?>

[edited by: Mtlinfo at 9:08 pm (utc) on Sep. 5, 2006]

[edited by: coopster at 9:32 pm (utc) on Sep. 5, 2006]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]