[Newbie] switch, if, or something to choose queries and echo formatting--PLEASE help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[Newbie] switch, if, or something to choose queries and echo
formatting--PLEASE help

Please bear with me, I will be telling you step by step what I have tried,
and what I want.

I'm a newbie to this whole thing.  I've had no trouble getting php and mysql
running on computer and getting a test database going so I could perform
some sample queries.

I have a personal website with a fair amount of content--and more waiting in
the wings for whenever I can figure this php-mysql stuff out.

Certain pages will contain 'image galleries' that will show thumbnails and
link to larger images, possibly with a name or a comment underneath the
picture.

I have code for that, which works fine--by itself.

Other pages will contain lists of titles that will link to stories or
essays.  That will be easy to do, pretty much the same as the image gallery,
but without the thumbnail or the need for columns.

What I am NOT finding easy to do is working out how I can get php to
recognize which page is attempting to be viewed and then query the
appropriate table and echo the results in the appropriate format.

I WILL be manually typing in my links, because the layout I want to use
involves a drop-down menu by ALA that I've altered a bit with images (
http://www.memoira.com/testing/3col/ - sample of layout).  The format will
be subsections.php?section=something?page=something OR
subsections.php?page=something

The first thing I did was attempt to import variables and use a series of if
statements, ie:
if ($page==animation)
{include design.php;}

Which didn't work at all.  Then someone suggested to me using this instead:
switch($_GET[section]){
   case "design":
       include("design.php");
       break;

Which DID work--but I can hardly use that for every page--otherwise I'll end
up making as many php files as I did html files before, which is totally not
the point of this, is it?

So I attempted to do this:
switch($_GET[page]){
$count=1;
$table = mysql_query("SELECT * FROM thumbs",$db);
echo("<table border='0' cellspacing='1' cellpadding='1' width='300'
align='center'><tr>");
while ( $r = mysql_fetch_array($table) ) :
if ($count==4){
   echo ("</tr><tr><td span='4'><img src='images/spacer.gif' height='10'
width='1'></td></tr><tr>");
   $count=1;
  }else{
$id=$r["id"];
$pic=$r["pic"];
$thumb=$r["thumb"];
$pname=$r["pname"];
$pcom=$r["pcom"];
echo("<td align='left' valign='top' width='100'><a href='$pic'
target='blank'><img src='$thumb'
border='0' align='left'></a><br
clear='all'><b>$pname</b><br><i>$pcom</i></td>");
   $count++;
  }
endwhile;
       break;

Which did not work.  I wondered if that was "too much" for the case or if
you couldn't nest.  PHP.net says "The switch statement executes line by line
(actually, statement by statement). In the beginning, no code is executed.
Only when a case statement is found with a value that matches the value of
the switch expression does PHP begin to execute the statements. PHP
continues to execute the statements until the end of the switch block, or
the first time it sees a break statement."  Which made me think
otherwise--but, hey, something's wrong.

So I've reviewed and changed and altered and edited and queried friends that
use ASP and now I'm just thoroughly frustrated.

It seems to me that putting in all the echo stuff is screwing things up, so
I figured I'd have to come up with some other kind of method...

So I thought I WOULD go with both a section designation and a page
designation.  The section designation would include design.php which would
contain the code for the multi-column image gallery (all sections/tables
containing that sort of information can be named and formatted alike), but
the table in the query would be a variable.

So,

subsections.php would contain the connection to the mysql server and
database, and a series of cases like:

switch($_GET[section]){
   case "design":
       include("design.php");
       break;

Then design.php would contain a series of cases like

switch($_GET[page]){
   case "animation":
       $page=thumbs;
       break;

as well as

$count=1;

$table = mysql_query("SELECT * FROM $page");

echo("<table border='0' cellspacing='1' cellpadding='1' width='300'
align='center'><tr>");

while ( $r = mysql_fetch_array($table) ) :

if ($count==4){
   echo ("</tr><tr><td span='4'><img src='images/spacer.gif' height='10'

width='1'></td></tr><tr>");
   $count=1;
  }else{
$id=$r["id"];
$pic=$r["pic"];
$thumb=$r["thumb"];
$pname=$r["pname"];
$pcom=$r["pcom"];
echo("<td align='left' valign='top' width='100'><a href='$pic'
target='blank'><img src='$thumb'

border='0' align='left'></a><br
clear='all'><b>$pname</b><br><i>$pcom</i></td>");
   $count++;
  }
endwhile;

echo ("</tr></table>");

However, this is not working either.  The link says:
subsections.php?section=design?page=animation

It's giving me my default case "Error" message I've set.

I'm baffled--how do MOST people accomplish this?  Is my insistance on the
manual linking throwing everything off?  Is my insistence on keeping the
site organized almost exactly as it was organized before making it
impossible?  Am I just stupid?

I've been reading everything I think could be helpful and going through the
php manual, but nothing seems to be helping me much.

I hate having to ask questions when I don't really have intelligent
questions (in my opinion), but obviously if I can't find a tutorial and if 2
weeks of experimentation hasn't yielded anything, I need some help from
someone who knows what s/he's doing.

Why isn't anything of this working?
If it's totally crazy, what SHOULD I be trying, instead?

Keeping in mind that if possible I want to use the menu I have ready AND
that I want to keep my sections and pages organized as I've been doing it.
(Which is the same as the site that's currently up, with a few name
changes).

- (R)hy
   http://www.virtualrevolution.net
   spam@xxxxxxxxxxxxxxxxxxxxx
            .switch.it.on.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 9/17/2004

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux