PDA

View Full Version : PHP newbie



kpcrump
01-22-2007, 04:35 AM
i am building a script for my WS but i'm not real sure how to use it. i am very new to PHP, my buddy has helped me out but i've learned more here. The PHP script if a if / else script, it is supposed to replace the flash banner i created @ the top of my pages. I created 6 gallery pages and 6 flash banners but i don't know exactly how to place. Everytime i place it it doesnt work, what am i doing wrong?

Many thanks

Both the scrip and page are attached.

djr33
01-22-2007, 07:16 AM
You just want a random banner? Is that it?
That script is incredibly complex... there are much better/easier ways of going about it.

kpcrump
01-22-2007, 02:04 PM
i guess u could call it a random banner but it actually is specific to the page. eg: bedroom page, bedroom banner and so on. Actually when the site was developed the pages were written in PHP but wasnt flexable enough, so it was tied to a SQL dB to make everything work right. Any suggestions?

jonnyynnoj
01-22-2007, 06:57 PM
So you want to change the banner depending on what page your on? If so you could make your links like http://yoursite.com/index.php?page=bedroom

Then your code would be like:



if ($_GET['page']=='home' or $_GET['page']==''){ //default page
echo "<img src="banner.jpg" />"; //default banner
}
elseif ($_GET['page']=='bedroom'){ //on the bedrom page, so show bedroom banner
echo "<img src="bedroom.jpg" />";
}
else{ //if the link is just http://yoursite.com/index.php
echo "<img src="banner.jpg" />";
}

Steganos
01-22-2007, 07:45 PM
Well...
You can just call your bannersthe same name as the page and just echo them. IE: I have a page in the format of www.domain.com/index.php?page=home.php. In this case, the home banner will be home.gif:



<?php
$page=$_GET[page];
$banner=explode(".", $page);
echo("<img src=\"path/to/$banner[0].gif\" alt=\"\" />");
?>

kpcrump
01-22-2007, 09:20 PM
Trying both examples, wish me luck but if understand the 2nd one correctly i am breaking the string in to an array with the explode function correct? but when the server reads it, it might get confused because I am calling .swx files as well.

mburt
01-22-2007, 09:41 PM
$banners = array("banner1.gif","banner2.png","etc.");
$random = rand(0,count($banners));
echo "<img src=\"" . $banners[$random] . "\" alt=\"Banner " . $random . "\">";
Not tested

kpcrump
01-23-2007, 02:57 AM
Trying the last but it looks to me that the code is to assign random banners? rather than a very specific one. Notice that the very same banner (swx file) plays on both pages, when in fact each page has it's own .swx file. My problem is i don't know exactly where to implement the code on the given page to make it work correctly, no matter which example i've tried. i have tried to clear my head and just think PHP but that doenst seem to work.

Here are the pages in question :

http://www.kwcabinets.com/gallery.php?gal=Kitchen

http://www.kwcabinets.com/gallery.php?gal=Media&#37;20Room

thetestingsite
01-23-2007, 03:06 AM
Try the following attached file, and see if this is what you mean. First, look at the code and you will see what you need to edit.

Hope this helps.

734

Note: All I did was edit your original code above.

kpcrump
01-23-2007, 05:01 AM
Now, that's what i think i was after, when i tried to write it. Still won't work due to the big fat parse error, an unexpected T_string. Thanks, i'll keep chugging along.........

djr33
01-23-2007, 01:19 PM
Parse errors are easy to fix.

You just need to figure out what comes before the thing that's not expected.

Usually, it's something missing or something extra-- ), }, ;, etc.

kpcrump
01-24-2007, 08:14 AM
Pulling my hair. I tried the code that was edited (from above) both after i changed the neccessary parts for the swx files and straight up, neither works. Here is what i keep getting :

Parse error: parse error, unexpected T_STRING in /home/content/k/p/c/kpcrump/html/gallery.php on line 33. .

i have checked everything i know how. all the curly cues are correct, double brackets, quotes, opening statements, closing statement.s. can anybody see what i'm doing wrong?

djr33
01-24-2007, 12:52 PM
I can't see anything wrong with the code (at least in the first section), especially anywhere near line 33. I must assume you have a different version of code in use. Please post line 33.

If you did insert a bit of text at the top of the page, perhaps it starts with:
if ($gal==’Kitchen’){

I am not sure if that is valid or not. If it appears before line 32, then it must be, as is the case in the above post. However, usually, we use 'kitchen', not... er... backwards apostrophes.

What are you using to edit your text in? MS Word, I know, likes to add strange characters. I'd be suspicious of this.

kpcrump
01-24-2007, 02:51 PM
Here is the entire section before the <body>. I am using XP Pro, word pad, to date it hasnt't failed me yet with any type of code but i guess you never know.

<?
ob_start();
session_start();
include_once "adminsection/conn.php";

if (!isset($_GET["gal"]))
{
header("location:home.php");
exit();
}
else
{
$gal=$_GET["gal"];
}



// if then statement
if ($gal==’Kitchen’){
$banner = "kitchenstb.swf";
}
elseif ($gal==’Bedroom’){
$banner = "Bedroomtb.swf";
}
elseif ($gal==’Office’){
$banner = "officetb.swf";
}
elseif ($gal==’Media Room’){
$banner = "mediatb.swf";
}
elseif ($gal==’Living Room’){
$banner = "lroomtb.swf";
}
elseif ($gal==’Architectual’){
$banner = "Architectual.swf";
}
elseif ($gal==’Others’){
$banner = "others.swf";
}
elseif ($gal==’our work’){
$banner = "ourworktb.swf";
}

else
$banner = "kitchenstb.swf";

}?>

//$sqlnew="select * from kitchen_main_images where category_name='$gal'";
//$rsnewrest=mysql_query($sqlnew);
//$datatrivia=mysql_fetch_array($rstrivia);
?>


<?php

//Set the page size
$PageSize = 6;
$StartRow = 0;

//Set the page no
if(empty($_GET['PageNo'])){
if($StartRow == 0){
$PageNo = $StartRow + 1;
}
}else{
$PageNo = $_GET['PageNo'];
$StartRow = ($PageNo - 1) * $PageSize;
}

//Set the counter start
if($PageNo &#37; $PageSize == 0){
$CounterStart = $PageNo - ($PageSize - 1);
}else{
$CounterStart = $PageNo - ($PageNo % $PageSize) + 1;
}

//Counter End
$CounterEnd = $CounterStart + ($PageSize - 1);



$TRecord = mysql_query("SELECT * from kitchen_main_images where category_name='$gal'");
$result = mysql_query("SELECT * FROM kitchen_main_images where category_name='$gal' LIMIT $StartRow,$PageSize");

//Total of record
$RecordCount = mysql_num_rows($TRecord);

//Set Maximum Page
$MaxPage = $RecordCount % $PageSize;
if($RecordCount % $PageSize == 0){
$MaxPage = $RecordCount / $PageSize;
}else{
$MaxPage = ceil($RecordCount / $PageSize);
}

?>



<html>
<head>
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Kitchen - title>
<link href="includes/global.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
font-weight: bold;
color: #CF4A01;
}
.style7 {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
color: #000000;
}
.style8 {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
}
-->
</style>
</head>

djr33
01-24-2007, 06:50 PM
Which one is line 33? My count shows a middle line in the elseif statements that is identical to the rest....

EDIT: Shows, not "shots"... oops.

kpcrump
01-24-2007, 09:19 PM
That is exactly what i count, no matter how many times i count it. The reason i am going crazy. The entire statement is the same, top to bottom and includes all the neccessary quotes, curly braces, simi-colons. ect.

thetestingsite
01-26-2007, 02:32 AM
One thing I see in the code you posted above is the following (in red)



else
$banner = "kitchenstb.swf";

}?>

//$sqlnew="select * from kitchen_main_images where category_name='$gal'";
//$rsnewrest=mysql_query($sqlnew);
//$datatrivia=mysql_fetch_array($rstrivia);
?>



Other than that, not sure what else it could be.

Hope this helps.

kpcrump
01-26-2007, 04:53 AM
Thanking all for the help so far, maybe i'm just STOOPID? I d/l PHP designer to edit all my files. I went back in and removed the >? from the last post, kept getting t_string in line ?. @ various points so i rewrote every line it kept advancing to (looking for funny chars.) then FTP'd. Now the gallery doesn't even come up, just shows a blank page. No banner, no page. I deleted that gallery.php from my server, flushed cache, reloaded, changed from bad to prior working one. i dunno what else to do or think of? ^&#37;$#^%$&. This is the last part to getting my site up and running and i cant stand one more cup of coffee...........LOL

kpcrump
01-30-2007, 07:11 PM
bump.

thetestingsite
01-30-2007, 07:35 PM
The only things that I can see it to be is in the following code:



<?
ob_start();
session_start();
include_once "adminsection/conn.php";

if (!isset($_GET["gal"]))
{
header("location:home.php");
exit();
}
else
{
$gal=$_GET["gal"];
}



// if then statement
if ($gal==’Kitchen’){
$banner = "kitchenstb.swf";
}
elseif ($gal==’Bedroom’){
$banner = "Bedroomtb.swf";
}
elseif ($gal==’Office’){
$banner = "officetb.swf";
}
elseif ($gal==’Media Room’){
$banner = "mediatb.swf";
}
elseif ($gal==’Living Room’){
$banner = "lroomtb.swf";
}
elseif ($gal==’Architectual’){
$banner = "Architectual.swf";
}
elseif ($gal==’Others'){
$banner = "others.swf";
}
elseif ($gal=='our work'){
$banner = "ourworktb.swf";
}

else {
$banner = "kitchenstb.swf";

}?>

//$sqlnew="select * from kitchen_main_images where category_name='$gal'";
//$rsnewrest=mysql_query($sqlnew);
//$datatrivia=mysql_fetch_array($rstrivia);
?>


<?php

//Set the page size
$PageSize = 6;
$StartRow = 0;

//Set the page no
if(empty($_GET['PageNo'])){
if($StartRow == 0){
$PageNo = $StartRow + 1;
}
}else{
$PageNo = $_GET['PageNo'];
$StartRow = ($PageNo - 1) * $PageSize;
}

//Set the counter start
if($PageNo &#37; $PageSize == 0){
$CounterStart = $PageNo - ($PageSize - 1);
}else{
$CounterStart = $PageNo - ($PageNo % $PageSize) + 1;
}

//Counter End
$CounterEnd = $CounterStart + ($PageSize - 1);



$TRecord = mysql_query("SELECT * from kitchen_main_images where category_name='$gal'");
$result = mysql_query("SELECT * FROM kitchen_main_images where category_name='$gal' LIMIT $StartRow,$PageSize");

//Total of record
$RecordCount = mysql_num_rows($TRecord);

//Set Maximum Page
$MaxPage = $RecordCount % $PageSize;
if($RecordCount % $PageSize == 0){
$MaxPage = $RecordCount / $PageSize;
}else{
$MaxPage = ceil($RecordCount / $PageSize);
}

?>


Also, change all of the apostrophes (spelling?) to single quotes ( ' ).

Hope this helps.

EDIT: Note the bracket in red.

kpcrump
01-31-2007, 04:18 AM
Nope, didnt help. i changed all apostrophe (u were correct) to single quotes, added the curly brace. Still comes up as blank page in this configuration.

?>
//$sqlnew="select * from kitchen_main_images where category_name='$gal'";
//$rsnewrest=mysql_query($sqlnew);
//$datatrivia=mysql_fetch_array($rstrivia);
?>


* removed the top ending statement in front of the notes, the page just returns the notes

* removed the bottom ending statement, get blank pages.

Now officially pulling my hair. Is there another way to write this code?

BLiZZaRD
01-31-2007, 02:14 PM
Err... I may have to go back and re-read this thread as I haven't been following it, but...

?> ends the PHP statement. "//" effectively prevents that line from being parsed.
then you have another ending ?> without opening one first.

Not sure what you are trying to do there, but you only have 2 <?php opening tags, and 3 ?> closing ones.

And if you have only blocked lines //Like this...

Nothing will get parsed to show anything.

thetestingsite
01-31-2007, 03:16 PM
Ok, I took your code from the first post. Combined it with the code in one of my posts. Then I made the script look a little better (syntax wise). Try the following, you should at least get some kind of output. If not, post a link to the page so that we can see it first hand.

Hope this helps.

BLiZZaRD
01-31-2007, 04:04 PM
Hey, looks good test... but I still don't understand why you comment out those 4 lines?

Is that for later use or just making notes or what? I don't get it... :rolleyes:

thetestingsite
01-31-2007, 04:40 PM
Those four lines were originally commented out, not sure why the OP did so. Perhaps for later use, or something else entirely. I'm just trying to fix the "blank page syndrome", but it might have something to do with the database stuff that the OP commented out.

mburt
01-31-2007, 05:02 PM
Considering without it, you can't connect to your db

thetestingsite
01-31-2007, 05:26 PM
Well, in the script, there are a few sql queries (spelling?) that are not commented. Not sure what they are getting back as a result, but I do know the syntax is correct.

Added Later: There is also an include to (I believe) the actual connection to the db. Not sure though being that we do not have the code to the file being included in the original script.

kpcrump
02-02-2007, 04:40 PM
Sorry for the delay, computer crashed two days ago (haven't fixed the backup yet,LOL). The blank page syndrom is caused by the PHP on line 16 that is not parsing, viewing the source after that pulls the html statement on line 17. (if /then statement) Yes, it does connect to a SQL DB, that pulls up the images. The comments are there for clarification and a link to see the in action with a different (if/then) that doesnt quite work but makes the page work correctly. Also, I've included the two pages just for comparison in a zip file. Now, in playing with the PHP opening / ending tags i get the same results if i shift the tags or leave the as is (banner.txt):). Is there something i'm missing / forgetting / overlooking? . Once again, Thanks to all who are helping my understand this cryptic code. LOL

1.) w / tags on start and end of php code i get blank page, just html.
2.) w/ tags rewritten around each php statement before the comments i get blank page, just html


go here:

http://www.kwcabinets.com/gallery.php?gal=Kitchen

thetestingsite
02-02-2007, 05:08 PM
In the noifgallery.php file, you have the following in your code:



<?php if($gal==’Kitchen’){ ?>}
// Flash code for Kitchen Banner..
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="574" height="85"><param name="movie" value="flash/kitchenstb.swf"> <PARAM NAME=loop VALUE=false>
<param name="quality" value="high"> <embed src="flash/kitchenstb.swf" loop=false quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="574" height="85"></embed>
</object>

<? }?>

<?php if ($gal=='media room'){?>}


All of the items in red are things messed up that I could see just briefly scanning the file. Also, go to this page (http://www.kwcabinets.com/gallery.php?gal=media&#37;20room) and notice the flash banner works as compared to the link you showed (Kitchen).

Hope this helps.

kpcrump
02-03-2007, 07:15 PM
I do see the banner, yes, and TY. However what i dont understand is the noifgallery, is the page i hacked up. It is not the one that was reworked with the "cleaner" code but i don't undstand why that one doesn't work? The if / then statements are much nicer than my page. Also, based on what i understand i though the curly brackets were needed @ the end of a statement but it was mentioned that it not correct?