Results 1 to 7 of 7

Thread: [PHP] parsing error - T_CONSTANT_ENCAPSED_STRING / parse error, unexpected $

  1. #1

    [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!

  2. #2
    4,029
    posts
    home cooking is killing the restaurant industry
    $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.

  3. #3
    Quote Originally Posted by λ
    $file = "images/".$_GET['id']."-".$i".jpg";

    should be

    $file = "images/".$_GET['id']."-".$i.".jpg";
    didn't catch that, thank you. sadly, the same cryptic error is taunting me...
    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.

  4. #4
    Quote Originally Posted by big_britches
    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.
    *******************
    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!

  5. #5
    Quote 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!
    my 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.

    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.

  6. #6
    Quote Originally Posted by bwh2
    my 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.

    if you want, i can show you the table setup that i would use.
    hey, i would love your thoughts. in the second half of my original post:

    ********************
    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

  7. #7
    Quote Originally Posted by big_britches
    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
    well, 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.

    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012