Ok, I'm sooo close (this is my third thread started in realtion to my site, so many problems, I just hope that these threads will be usefull to others in the future, I've tried to keep one problem/solution per thread)

ok, what I would like to do is take a variable containing text and use it to make alt text for an image.
the way my site works, I have a database with different comics, and when you load the page, it will load the appropriate comic (if its your first time it loads the latest and if you're browsing it will load the appropriate issue) and it will also load a blog.

basically I call the record for the appropriate issue number form a table that contains: issue number, the name of the image file, the title of the comic, the date.

I then take these array values and use them to create the appropriate page for the appropriate comic, aka, the name of the image file is used to call the appropriate image (as well as teh appropriate blog posting .txt file since it shares teh same name), it loads the title of the comic into the head of the page and it loads the date of the posting just above the blog.

you can see an example of this working here: http://andrew.ulmb.com/index.php

now...I want to put alt text onto the image. the alt text is contained in a file called $issue[1]alt.txt where $issue[1] would be a 5 digit issue number, in this case 00001 since I have one comic. this file is in the same folder as the blog, the blog is named $issue[1].txt.

I load the alt text and the blog in the same fasion, by opening the txt file and reading the entire file into a single variable. this leaves me with two variables containing all the text I want displayed.

displaying the blog was easy, just a single print function wher ei want the text to appear, BUT the alt text is giving me a hard time, I can't get it to display. here is the html code surrounding the image

				<div style="position:absolute;top:32px;left:224px;width:580px;height:1475px;">
					<?PHP print "<img src = COMICS/$issue[1].jpg>" ?> </div>

This properly displays the image (fo rthe moment but I'll get to that later or in a different thread since it's a seperate problem)

how would I add the variable $alt into these lines of code so that the value of $alt is displayed as the alt text?

I've tried to be as specific as possible but if you need clarification on anythign please reply.

thanks.
andrew

    ok I changed my code for the image to this

    <?PHP print "<img src = COMICS/$issue[1].jpg alt = $alt >" ?>

    duh, that worked...sort of

    it's only printing the first word from the string $alt. if I print the string in a different place in the source, I get the whole file, so I knwo that the variable contains all the information, so why isnt it displaying it all in the alt text area when you scroll over the image?

    andrew

      BAH!!!

      I figured the html was only picking up the first word because the whole text file was being printed without ("), so I put some quotes around $alt and got a syntax error.
      I got it to work by putting apostrphes (') around the $alt variable. this worked ALMOST like a charm!

      here's my new problem, because I had to use single quotes (double gave me an error) I can no longer use single quotes anwhere in my alt text because it will trigger the end of alt text early. I could work around this, proper grammar isn't somethign I HAVE to have, but I know I'll make a mistake at some point and accidentally put one in out of habit. is there any way around this?

      thanks,
      andrew

        Escape the ". eg \", of course then you can't have " in your file.

          In other words, in order to use the same type of quote you used as your string delimiter, you need to precede it with a blackslash so that in "escaping" it, PHP knows you're not trying to end the string early - you're just trying to insert a literal quote character.

          If you can't get it, re-post the code you're having trouble with.

            nEmoGrinder wrote:
            <?PHP print "<img src = COMICS/$issue[1].jpg alt = $alt >" ?>

            mmm putting out your html from php looks like this...

            <img src = COMICS/issue1.jpg alt = the number #1 issue >

            ...that is not a good code. You have to put the strings in to quote or double quote...

            <img src = "COMICS/issue1.jpg" alt = "the number #1 issue" >

            ...that look like better.
            But putting back in the html into php...

            <?PHP print "<img src = "COMICS/$issue[1].jpg" alt = "$alt" >" ?>

            ...there is some doublequote conflict. To correct this you have to "escaping" the inner double quote...

            <?PHP print "<img src = \"COMICS/$issue[1].jpg\" alt = \"$alt\" >" ?>

            et-voilà 😃

            see you!

              Write a Reply...