I am having a very challenging time with Chapter 4 of this book. If you are someone that was once in my shoes, are there any tips you can give me? Specifically with the last couple of examples of this chapter. I am brand new to PHP and want very badly to be great at it! Just have to wrap my head around it all. If you could connect me with any resources you may have used to help or anything at all like that, I would be very grateful, thanks!
It’s the 4th edition book. I will post the places I am having problems with when I get home (in transit right now). Thanks for your willingness to help so far though! I believe there is actually a link somewhere on the sitepoint website that shows the entire fourth chapter. Can’t find it right now that easily though. Thanks again, will post more once I get home.
So just to clarify… does this mean that all double quotes will be turned into a single quote, and all single quotes will be turned into " ?? Or do the single quotes just stay as single quotes? Lastly, what does the “ENT” techcnially stand for? “enter” ? “Entry” ? sorry, i’m a total n00b with this!
Double quotes and single quotes are not turned to anything but their entities.
That means that each time you have a double symbol, it will appear "e; instead, and when you have a single quote, it will appear & #039;.
By using entities, you don’t have to worry about the special meaning that these characters have for PHP or HTML. The user reading the page will see the quote with no problem at all.
In the example I gave you, if you execute it in your own computer and look at the view source, you will see that the correct result is:
<a href=& #039;test& #039;>Test</a>
note: I’ve added unnecessary white spaces so the entity is not parsed (by the browser) and show a single quote instead.
What the user reading the page will see is:
That is, exactly the text I wrote. By changing the characters with special meaning and substitute them with their entities, I was able to force the browser to show this string as regular text, instead of having the browser creating a proper link.
Just in case, an entity is just an alias for a character. The browser recognizes that alias and shows the right character or text in its place. Entities should always start with & and end with ;
Unless it is related to what we just talked about, you should start a new thread. Although many of your questions may have been answered and it may be worth it to do a search first, and if they’re related to this book, it may be worth to check the PHP forum as well
Hey I can really understand where you are coming from with trying to get chapter 4 down. I am readng the 4thedition and am also struggling with Chapter 4. I am having a hard time getting past this piece of code:
$result = mysqli_query($link, ‘SELECT joketext FROM joke’);
$error = 'Error fetching jokes: ’ . mysqli_error($link);
while ($row = mysqli_fetch_array($result))
$jokes = $row[‘joketext’];
Are you at this point and do you understand what’s goig on in the code???
I don’t have the fourth version but a previous one, where mysqli was not used… but I think I can explain what’s going on and I hope this will help you. I’ll try to be detailed although I’m sure that there are things that you already know
$result = mysqli_query($link, 'SELECT joketext FROM joke');
Open a connection to the database and table using the info kept in the variable $link, and execute the query ‘SELECT joketext FROM joke’
Then keep the details and the error message in a variable called $error. The function mysqli_error() will have the specifics details.
then, use the HTML template error.html.php to display the error on screen (remember that Kevin likes to keep the HTML in one page, with as little php as possible, if any, and the php functions in other and code in other).
while ($row = mysqli_fetch_array($result))
$jokes = $row['joketext'];
If you get to this point, it is because you do have at least one record. So while there are records to be read, fetch record by record and add it to the array $jokes. In this way, if you what to get access to the very first record, you only it will be kept in $jokes, if I want the second, in $jokes and so on.
The HTML to display the jokes is jokes.html.php, so I need to include it to handle this particular job.