Search
Left Quote    Treat your password like your toothbrush. Don't let anybody else use it, and get a new one every six months.
- Clifford Stoll    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Can i do this again?
  This user is offline  BoricuaLayz
  Subject: "Can i do this again?" Posted: @ 3:39 am on Jun 30 2007   
Member #: 356
Rank: User - (30)
Since: 06/25/07
Posts: 44
From: Florida

Ok before the forum developed some glitches i created a topic asking other members if they knew how i could switch the head.php file to another file like head2.php when a user clicks a link and the file stays on the page unless a user switches back to the original file. I remember a user posted a code but the topic got deleted so i never got the code. If you posted the code here before please repost it. I know that it has to deal with a database entry, a cloumn named 'theme', and i give the column the value of head.php, head2.php, ect...

Edited at 03:43:19 am on 06/30/07


    Viewed: 9,844 Times | Reply to This | To top
  This user is offline  WintersDance
  Subject: "re: Can i do this again?" Posted: @ 4:33 am on Jun 30 2007    

Member #: 353
Rank: User - (27)
Since: 06/19/07
Posts: 36
From: California

You can try this, but honestly, I think you would be better off switching style sheets then complete headers. You can set things like the site's banner and other images through the style sheets.

But here is what you're looking for I believe.

Create a drop down menu with a list of themes registered members can choose from. Each theme name must have a matching header.php file for it. Look at example below:

<form action=" " method=post>
<select name="the me">
<option value="he ader1.php" ;>Style 1</option> ;
<option value="he ader2.php" ;>Style 2</option> ;
<option value="he ader3.php" ;>Style 3</option> ;
</select>
<input type=submit value="Se t Theme"> ;
</form>

Once the member chooses a theme, it gets set in a column called 'themes' in the members table.


Code:


$username = $_SESSION['use rname'];
$sql = "UPDATE members SET themes = '$theme' WHERE username='$use rname'";
@mysql_query( $sql);



To call it up, try something like this:


Code:

<?
ob_start();
require_once(' db_connect.php ');

$q = "SELECT themes FROM members WHERE username = $_SESSION['use rname']" ;
$result = @mysql_query($q );
if(!$result){
include(header. php);
}
else {
while ($row = mysql_fetch_arr ay($result))
{
$theme = $row['themes' ];
if($theme != '') //If the member has set a theme, use it.
{
include($theme) ; //Use member selected theme.
}
else //If no theme has been set, use the default theme.
{
include('heade r.php');
}
} // end while statement
} //end else statement
?>



Hope that helps you experiment more with it.



Edited at 05:02:23 am on 06/30/07


wintersdance |     Viewed: 9,838 Times | Reply to This | To top
  This user is offline  BoricuaLayz
  Subject: "re: Can i do this again?" Posted: @ 5:36 am on Jun 30 2007    
Member #: 356
Rank: User - (30)
Since: 06/25/07
Posts: 44
From: Florida

The way my site is built i dont include any banners or backgrounds in the css i put it in the head.php file because the banner may include a immage map

now back to the script when i put the code onto the page i get this error

 error said...

< i>Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/j /p/9/jp954rr/ht ml/Member Area/index.php on line 5

This is line 5


Code:

$q = "SELECT themes FROM members WHERE username = $_SESSION['use rname']" ;



Edited at 05:46:58 am on 06/30/07


    Viewed: 9,831 Times | Reply to This | To top
  This user is offline  WintersDance
  Subject: "re: Can i do this again?" Posted: @ 5:42 am on Jun 30 2007    

Member #: 353
Rank: User - (27)
Since: 06/19/07
Posts: 36
From: California

the image links can look like this:

<a href="< ;? echo $_SERVER['PHP_ SELF']?>?ta sk=set_theme&am p;theme=head2& quot;><im g src=" " width=30 height=30>&l t;/a>

Where &theme=head 2, head2 can be any header page you wish to include, just don't add .php to it, that will be added in the code below for calling up the correct header.

To add the theme to the db, add this on the same page:


Code:


if ($task==" set_theme"
{
$username = $_SESSION['use rname'];
$sql = "UPDATE members SET themes = '$theme' WHERE username='$use rname'";
@mysql_query($s ql);
header("L ocation: ".$PHP_SE LF."&quo t; /* Redirect back to same page */
exit;
}



Then call it up like this:

Code:

<?
ob_start();
require_once(' db_connect.php ');

$q = "SELECT themes FROM members WHERE username = ".$_SESSI ON['username' ]."" ;; //that should fix your error.
$result = @mysql_query($q );
if(!$result){
include(header. php);
}
else {
while ($row = mysql_fetch_arr ay($result))
{
$theme = $row['themes' ];
if($theme != '') //If the member has set a theme, use it.
{
include($theme. php); //Use member selected theme.
}
else //If no theme has been set, use the default theme.
{
include('heade r.php');
}





Edited at 05:58:28 am on 06/30/07


wintersdance |     Viewed: 9,821 Times | Reply to This | To top
  This user is offline  BoricuaLayz
  Subject: "re: Can i do this again?" Posted: @ 6:00 am on Jun 30 2007    
Member #: 356
Rank: User - (30)
Since: 06/25/07
Posts: 44
From: Florida

Ok so i got everything working but the head.php doesnt
change

I think i found the problem what "type&qu ot; is the "theme&q uot; column supposed to be right now it is set to VARCHAR



Edited at 07:27:20 am on 06/30/07


    Viewed: 9,815 Times | Reply to This | To top
  This user is offline  WintersDance
  Subject: "re: Can i do this again?" Posted: @ 1:10 pm on Jun 30 2007    

Member #: 353
Rank: User - (27)
Since: 06/19/07
Posts: 36
From: California

make the 'themes' column varchar(10) NULL,

and insert the values as "head2&q uot;, "head3&q uot;, "head4&q uot;, etc...




wintersdance |     Viewed: 9,782 Times | Reply to This | To top
  This user is offline  BoricuaLayz
  Subject: "re: Can i do this again?" Posted: @ 3:00 pm on Jun 30 2007    
Member #: 356
Rank: User - (30)
Since: 06/25/07
Posts: 44
From: Florida

I believe there is a problem with this code


Code:

<?
ob_start();
require_once(' db_connect.php ');

$q = "SELECT themes FROM members WHERE members.usernam e = ".$_SESSI ON['username' ]."" ;;
$result = @mysql_query($q );
if(!$result){
include(" head4.php" ;
}
else {
while ($row = mysql_fetch_arr ay($result))
{
$theme = $row['themes' ];
if("$them e != ''"
{
include($theme) ;
}
else //If no theme has been set, use the default theme.
{
include(" head4.php" ;
}
}
}
?>



because i manualy put head3 in the themes column on my row to change the theme but it doesnt change so i think it may be a problem when you call the session username



Edited at 02:49:03 am on 07/01/07


    Viewed: 9,777 Times | Reply to This | To top
  This user is offline  WintersDance
  Subject: "re: Can i do this again?" Posted: @ 2:42 am on Jul 01 2007    

Member #: 353
Rank: User - (27)
Since: 06/19/07
Posts: 36
From: California

Try adding the session_start() ; it should work after the member has logged in.

Code:


<?
ob_start();
session_start() ;
require_once(' db_connect.php ');

$q = "SELECT themes FROM members WHERE members.usernam e = ".$_SESSI ON['username' ]."" ;;
$result = @mysql_query($q );
if(!$result){
include(" head4.php" ;);
}
else {
while ($row = mysql_fetch_arr ay($result))
{
$theme = $row['themes' ];
if("$them e != ''"
{
include($theme) ;
}
else //If no theme has been set, use the default theme.
{
include(" head4.php" ;);
}
}
}
?>




wintersdance |     Viewed: 9,737 Times | Reply to This | To top
  This user is offline  BoricuaLayz
  Subject: "re: Can i do this again?" Posted: @ 3:10 am on Jul 01 2007    
Member #: 356
Rank: User - (30)
Since: 06/25/07
Posts: 44
From: Florida

Everthing Wors and i used the 30 x 30 pix as the links and the theme changes perfectly thnx alot Wintersdance your were a big help



Edited at 09:47:24 pm on 07/01/07


    Viewed: 9,733 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank