Results 1 to 7 of 7
-
June 11th, 2006, 04:38 PM #137Registered User
posts[PHP] parsing error - T_CONSTANT_ENCAPSED_STRING / parse error, unexpected $
hello and thanks for the superior brain power!
portfolio site:
http://www.bigbritchescreative.com
using SQL db, with fields: id(key), img_title, img_descrip, img_file, img_type, img_link
a portfolioimagedb entry (row) may or may not have multiple (extra) images; i want all (if there are any) returned. i've made my naming convention 1.jpg, 1-1.jpg, 1-2.jpg and so on, for extra images - the 1.jpg being the img_file value, matching it's id, for callback purposes. this function is to check if there are extra files, based on this convention, and to increment until the condition is met, and output any extra images found:
<?php $i = 1;
$file = "images/".$_GET['id']."-".$i".jpg";
while (file_exists($file)) {
echo <img src= $file />;
$i++;
$file = "images/".$_GET['id']."-".$i".jpg";
}?>
with this, i'm getting a "parse error, unexpected T_CONSTANT_ENCAPSED_STRING" ; it has to be a syntax/escape character/tiny detail thing...my novice eyes are bleeding trying to understand where i'm off.
i also, in not knowing if that was logical or would have any chance of working, went another direction. i added 2 more columns in my database, img_alt1 and img_alt2. then, just like my view project link(in which an if is used to check the column img_link and return accordingly, i used an if statement to detect the presence of anything in these columns, and to take action if something's found. this one seems messier to me, but also seems more likely to work, given my inexperience:
<?php if ($row_data['img_link'] != "" && $row_data['img_link'] != NULL) { ?>
<h3><a href="<?php echo $row_data['img_link']; ?>">view project</a></h3><?php } ?>
<img src="images/<?php echo $row_data['id']; ?>.jpg"><br />
<?php if ($row_data['img_alt1'] != "" && $row_data['img_alt1'] != NULL) { ?>
<img src="<?php echo $row_data['img_alt1']; ?>"><br />
<?php if ($row_data['img_alt2'] != "" && $row_data['img_alt2'] != NULL) { ?>
<img src="<?php echo $row_data['img_alt1']; ?>">
but this returns a "parse error, unexpected $" , pointing to the last line of code, after the
<?php
mysql_free_result($data);
?>
everything was going smoothly in this, my inaugural database venture (as you can tell by the small number of entries, it's exploratory), until this particular tweak. any help or immediate obvious syntax relief is warmly welcomed. thanks!
-
June 11th, 2006, 04:49 PM #24,029home cooking is killing the restaurant industry
posts$file = "images/".$_GET['id']."-".$i".jpg";
should be
$file = "images/".$_GET['id']."-".$i.".jpg";There are only 10 kinds of people in this world:
Those that might know ternary, those that do, and those that don't
Say NO to DRM.
-
June 11th, 2006, 06:03 PM #337Registered User
postsdidn't catch that, thank you. sadly, the same cryptic error is taunting me...
Originally Posted by λ
the layout of that function:
<?php $i = 1;
$file = $_GET['id']."-".$i.".jpg";
while (file_exists($file)) {?>
<img src="images/<?php echo $file; ?>" />;
<?php $i++;
$file = ($_GET['id']."-".$i.".jpg");
}?>
makes sense to me, and should work. i need $file to be a string, to be called to complete the img path...frustrating.
-
June 12th, 2006, 04:14 PM #437Registered User
posts*******************
Originally Posted by big_britches
let me rephrase, or be more specific, in asking: is this a viable strategy to accomplish what I want? i think so, and I believe I can work out the syntax issue as i stare at it. thanks for any input!
-
June 12th, 2006, 04:45 PM #5my personal opinion is that this is a bad setup. i would not rely on file naming convention for as pulled by php to load images. i would much rather have filenames pulled from SQL and then subsequently loaded.
Originally Posted by big_britches
i say this for 3 main reasons:
1) usability - when a user clicks on an image, it's reassuring to see that the image name is related. also, this helps if the image is saved.
2) maintainability - it's easier to maintain filenaming conventions when the files have appropriate, descriptive titles (1-1.jpg is not descriptive. companylogo_1.jpg is).
3) findability and SEO - say a potential client is a partner in a law firm. naturally, they may search for web designers who have made law sites. so your portfolio is more likely to come up if you have an appropriate filename, description, etc.
if you want, i can show you the table setup that i would use.
-
June 12th, 2006, 05:10 PM #637Registered User
postshey, i would love your thoughts. in the second half of my original post:
Originally Posted by bwh2
********************
i added 2 more columns in my database, img_alt1 and img_alt2. then, just like my view project link(in which an if is used to check the column img_link and return accordingly, i used an if statement to detect the presence of anything in these columns, and to take action if something's found. this one seems messier to me, but also seems more likely to work, given my inexperience:
<?php if ($row_data['img_link'] != "" && $row_data['img_link'] != NULL) { ?>
<h3><a href="<?php echo $row_data['img_link']; ?>">view project</a></h3><?php } ?>
<img src="images/<?php echo $row_data['id']; ?>.jpg">
<?php if ($row_data['img_alt1'] != "" && $row_data['img_alt1'] != NULL) { ?>
<img src="<?php echo $row_data['img_alt1']; ?>">
<php? } ?>
<?php if ($row_data['img_alt2'] != "" && $row_data['img_alt2'] != NULL) { ?>
<img src="<?php echo $row_data['img_alt2']; ?>">
<php? } ?>
but this returns a "parse error, unexpected $" , pointing to the last line of code, after the
<?php
mysql_free_result($data);
?>
**********************
i think i was on that wavelength. img_alt1 and img_alt2 columns would be filenames for those extra images - i'll never have more than 2, but if i did it would be fairly simple to add them in...? thank you
-
June 12th, 2006, 05:27 PM #7well, the problem then is that the 3 images for the piece might have different descriptions and/or titles. so each image should be a separate record in the table. my point is 1) the db tables should be relational and 2) you should't be pulling back data that you don't need, then having to process it on the PHP side.
Originally Posted by big_britches
it's a lot easier to say, "pull back any row with this as the piece_ID and echo out the data" than it is to say, "pull back the row with this as the piece_ID, then check if this field is null and then check if this field is null and then echo out what some more logic has deemed appropriate".
also, let's say you do end up with a portfolio piece that has more than 2 images. then it's a pain to adjust the portfolio because you have to 1) alter the table to create the field, 2) insert the data, 3) update your php file to check for the null values in that field, 4) make sure nothing is broken. contrast that with a method where each entry gets its own row, in which case all you have to do is 1) insert the data.

Reply With Quote

Bookmarks