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

2004-09-25 Thread Antoine
 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 (/trtrtd span='4'img src='images/spacer.gif' height='10'
 width='1'/td/trtr);
$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'/abr
 clear='all'b$pname/bbri$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.

Yip, the logic of the switch statement. You simply don't have a case
statement. I must confess I don't understand fully what you are trying
to do yet but I don't think this is the way to go. The above extract
should be enough to see what I mean... 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. You don't have one so... it
won't ever start!
Cheers
Antoine



-- 
G System, The Evolving GUniverse - http://www.g-system.at

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



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

2004-09-24 Thread spam
[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 (/trtrtd span='4'img src='images/spacer.gif' height='10'
width='1'/td/trtr);
   $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'/abr
clear='all'b$pname/bbri$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 (/trtrtd span='4'img src='images/spacer.gif' height='10'

width='1'/td/trtr);
   $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'/abr
clear='all'b$pname/bbri$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