Forum Moderators: coopster

Message Too Old, No Replies

unexpected $end?

         

Bigjohn

6:43 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



Thats the error I get from PHPedit. PHP on my server just says parse error.

Here is the code:

Could someone please tell me why I'm getting "unexpected $end in line ****?


<?php
$table_name='orinth';
$dbh=mysql_connect ("localhost", "****_joetest", "****") or die ('Cannot connect to Database - error: ' . mysql_error () );
mysql_select_db("stegenga_joetest1",$dbh);

function make_table_start() {
$content = '<table border="2" cellpadding="0" cellspacing="0" width="540px">';
return $content;
}
function make_table_end() {
$content = '</table>';
return $content;
}
function make_fill_table() {
$sql = $sql = 'SELECT * '
. ' FROM ornith'
. ' WHERE subclass = "audubon"';
$result = mysql_query($sql);
if (!$result) {
print mysql_error() . "ERROR - query failed";
}
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$content .='<tr>'."\n";
$content .='<td align="center">'."\n";
$content .='<a href="javascript:popImage(\'images/'. $row[picname] . ',' . $tablename . ' '. $row[picname].'\')">'."\n";
$content .='<img src="images/' .$row[thumbname].'" alt="$row[thumbname]"></a></td>';
$content .='<td align="left" style="padding-left:5px">' .$row[itemdesc] . '</td>';
$content .='<td align="left">' .$row[item_qual] . '</td>';
$content .='<td align="center">' .$row[item_height] . '" x "' .$row[item_width] . '</td>';
$content .='<td align="right">'.$row[itemprice] . '</td>';
if ($row[itemstatus]=="1") {$content .='<td align="center">YES</td></tr>';}
else {$content .='<td align="center">HELD</td></tr>';}
return $content;
}
}
print make_table_start();
print make_fill_table();
print make_table_end();
?>

the error line is right at/after?>

HELP

The syntax highligher in PHPedit does not show any syntax problem....

John

coopster

6:49 pm on Feb 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Not sure, could be this:

$sql = $sql = 'SELECT * '
. ' FROM ornith'
. ' WHERE subclass = "audubon"';

Try:

$sql = "SELECT * FROM ornith WHERE subclass = 'audubon'";

Bigjohn

7:15 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



that's not it. The only thing I changed was the IF that I embeded into the while loop.

mipapage

7:20 pm on Feb 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Theres only one Bigjohn...and this is weird cause he's tryin to build a table ;0]

coopster

7:53 pm on Feb 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I ran your code locally without issue. Well, there were quite a few notice errors, but I did not receive a parse error. The html was displayed as expected. You may want to check out some of the PHP Troubleshooting [webmasterworld.com] tips in the Forum Library.

Robert Thivierge

8:48 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



For that big long, "string in string", "quote in quote" expression you got, try this:

$content .= <<<END
Put anything you want here, don't worry about quotation marks.
Use curly brace {$variables} to avoid ambiguity.
END;
//(note: nothing comes after END; not even spaces)

Also,

'" alt="$row[thumbname]"></a></td>'

You can't do variable substitution inside single quotes. The double quotes there are *literal*, so the string is still single-quoted.

rob

Bigjohn

9:41 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



@mipapage
Hmmm?

@coopster - what sort of warns? Just about not being able to open the db? or construct/syntax stuff?

@Robert
Um, how do I include the variables when I try your <<< END method?

Please advise folks! And THANKS for your help!

John

Robert Thivierge

10:09 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



$x="10";
mystring = <<<END
stuff
x={$x}
more stuff
END;
echo $mystring;

The above code will display:

stuff
x=10
more stuff

Variable substition works like it does with double-quotes. The difference is that the string is not terminated with quotation marks.

Bigjohn

10:11 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



mojo cool! I'll give that a rip.

Thanks.

ooh... one q... how to handle the IF embeded in there?

John

mipapage

10:17 pm on Feb 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey Bigjohn,

Notice errors would occur for things like this:

$row[itemprice]

Which should be this:

$row['itemprice']

There not mission critical (duck!) but do speed things up a bit if you don't have them.

you are bigjohn of css fame, no?

Robert Thivierge

10:41 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



how to handle the IF embeded in there?

You don't need to. Simply assign the appropriate sub-string value to an intermediate variable in advance, and substitute that variable into the larger string.

Bigjohn

10:44 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



css fame? nah. I'm a newbie to all of this. but I've posted at webdev forums too...

John

Bigjohn

10:46 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



@robert -

SO, i define yes/no with a test BEFORE constructing the string within the while loop?

John

Robert Thivierge

11:00 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



SO, i define yes/no with a test BEFORE constructing the string within the while loop?

Yes, assign whatever text you wish to appear to an intermediate variable BEFORE you use "<<<" and within the loop.

It looks like you want the variable to be "YES" or "HOLD". Then just substitute it in at the appropriate place. I'm not sure why you said "yes/no" when your code says "YES/HOLD". Just to be clear, I'm talking exlcusively about string variables (not boolean).

Bigjohn

11:21 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



@robert -

Something like this?


while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($row['itemstatus']=='1') {$avail = "yes";
$style='onhold'}
else {$avail = "hold";
$style='stock'}
$content =<<<END
<tr class={$style}><td align=center>

note - the above is truncated...

Robert Thivierge

11:33 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



Bigjohn,
I'm wary of answering because your last example differs from your original code.

You had

......a whole bunch of code here.....
if ($row[itemstatus]=="1") {$content .='<td align="center">YES</td></tr>';}
else {$content .='<td align="center">HELD</td></tr>';}

I'm suggesting:

if ($row[itemstatus]=="1") {$x="YES"}
else {$x="HELD"}

$content .= <<<END
......a whole bunch of code here.....
<td align="center">{$x}</td></tr>
END;

I suggest you look at php.net's help on strings (search for "heredoc"). I know more about PHP than I do with CSS or JavaScript, which you've got. I can tell you *how* to substitute a string into another string, but not *what* to substitute.

Bigjohn

12:16 am on Feb 18, 2004 (gmt 0)

10+ Year Member



of course it differs somewhat, i'm trying to clean it up and remove all the $content .= , as you suggested.

can i set 2 variables within the context of the if? And would $style be a valid variable in PHP?

and your example does not have the semi-colons (;)... do I not need them?

John

Robert Thivierge

12:28 am on Feb 18, 2004 (gmt 0)

10+ Year Member



can i set 2 variables within the context of the if? And would $style be a valid variable in PHP?

Yes. Inside the braces, you can set all the variables you wish (or do any other code). Do whatever makes the code easier and readable for you. Just be sure that every variable is always set before it's used (i.e. wether the condition is true or false).

I don't know what all the reserved words are in PHP. I haven't heard of "style" being reserved. So, I think it's ok to use. You'll find out when you run it :)

Bigjohn

1:07 am on Feb 18, 2004 (gmt 0)

10+ Year Member



so the way I've shown my sample will work?


if ($row['itemstatus']=='1') {$avail = "yes"; $style='onhold'}

obviously this is in the if statement, before the <<<END string building...

John

Robert Thivierge

2:00 am on Feb 18, 2004 (gmt 0)

10+ Year Member



You must ensure the variables are always set. You can initialize the variables, or you can specify an "else" condition.

good luck,
rob

Bigjohn

2:22 am on Feb 18, 2004 (gmt 0)

10+ Year Member



Thanks. I'm just looking to ensure the syntax is correct. Most 'examples' don't set multiple variables at the same time (that I've seen).

a question for you -

once I've built this array, how do I have buttons, etc, access items in it? For example, how would I build a button in the table row that updated the $row[itemstatus]? How does the program know/remember what is what?

John

Bigjohn

1:29 pm on Feb 18, 2004 (gmt 0)

10+ Year Member



It works - sorta...here

but now something in the html construct is not working... i need more coffee.. .if anyone see's what I've screwed up, kindly tell me!

EDIT: Damn quotation mark... now it's working. Need to write my styles and my header-row. Thanks!

John

PS - still have that other question:
how to do a button that will update the status of a field (i.e. a "buy" button)....

John

[edited by: Bigjohn at 1:42 pm (utc) on Feb. 18, 2004]

[edited by: jatar_k at 5:54 pm (utc) on Feb. 18, 2004]
[edit reason] delinked [/edit]

coopster

1:34 pm on Feb 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Good Morning, Bigjohn. Yes, you need some coffee. Your images are named incorrectly :)

Bigjohn

1:53 pm on Feb 18, 2004 (gmt 0)

10+ Year Member



Caffeeeeen is my friend...

if I define cell widths in the header row, all other <td>'s follow, right?

Answer: yep!

John