Jump to content


Photo

typo? misprint?


  • Please log in to reply
15 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 August 2006 - 01:28 PM

<?php
$image = "<a href=\"test.php\"><img src=\"images/standards/\"{$row[lam_number]}-{$row[lam_name]}_40.gif\" alt=\"{$row[1am_name]}\" /></a>";
?>
I am not totally sure why it doesn't go through it tells me expected ] but I have went over it about 4 times.  I normally don't have a problem setting up url's sometimes even 3-4 times longer than this.

Here is the full code.

<?php
session_start();
include 'db.inc'; // include here
/* Below here I reformatted slightly so I could read it better, change what you need */
$sql = 'SELECT * FROM `fyswilson_art` WHERE 1 LIMIT 0, 300 ';
if (!($connection = @ mysql_pconnect("localhost",
"#####", "######"))) {
     showerror();
}// added quotes and brackets
// added quotes and brackets for the 2 below
if (!mysql_select_db("db162100635", $connection)) {
     showerror();
}
        
if (!($result = @ mysql_query ($sql, $connection))) {
     showerror();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Wilson Art</title>
</head>
<body>
<div style="width:200px;"><!-- Contains left view -->
<?php
// because of the nature of this program, it might take a lot of tweaking, so I 
// prepared the ground work slightly different.  Here I am starting by
// trapping each individual section of the program in a variable, and combining
// them in a master variable to allow me to display everything that goes on the left
// with one variable.  This allows me to single out broken code, or what's causing 
// problems, or make changes, it also saves a little server load with performance.
while ($row = mysql_fetch_array($result))	{	
$image = "<a href=\"test.php\"><img src=\"images/standards/\"{$row[lam_number]}-{$row[lam_name]}_40.gif\" alt=\"{$row[1am_name]}\" /></a>";
echo $image;
}
?>			

</div><!-- Ends Left View -->
<div><!-- Contains right view -->
</div><!-- Ends right view -->
</body>
</html>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 17 August 2006 - 01:37 PM

What is the exact error?

I can see one problem:
$image = "<a href=\"test.php\"><img src=\"images/standards/\"{$row[lam_number]}-{$row[lam_name]}_40.gif\" alt=\"{$row[1am_name]}\" /></a>";

The bit in bold closes the src attribute but it looks to be like the following part should be apart of it.

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 August 2006 - 01:37 PM

<?php
$image = "<a href=\"test.php\"><img src=\"images/standards/{$row[lam_number]}-{$row[lam_name]}_40.gif\" alt=\"{$row[1am_name]}\" /></a>";
?>
That is my modified code by the way I found 1 issue in it earlier, but the only thing is, it's giving me the same error,  It seems to be telling me it's around the alt somewhere, when I cut up the url into 3 different variables it singles out the one that starts the alt, but I want them all together either way.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 August 2006 - 01:38 PM

Yes, I had just caught that one, and I also split up the url in 3 sections to single out that area, but for some reason it's still telling me

Parse error: parse error, unexpected T_STRING, expecting ']' in /homepages/30/d162063315/htdocs/zcart/fys/test.php on line 35

I just don't understand why it's not working.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 17 August 2006 - 01:39 PM

Just for the sake of it, try $row['lam_number'] instead of $row[lam_number]

#6 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 August 2006 - 01:42 PM

How the hell.  I have been taught this whole time

"when Extrapolation variables, you DO NOT need the single quotes around the name of the variable."

Can someone please explain this too me I am confused, it worked, atleast the code works, where I can start making the pictures display, no errors, I always used {$_POST[variable]} when I am extrapolating, why did this happen, this makes me confused.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#7 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 August 2006 - 01:43 PM

Actually I was told it was the safer, and recommended way?:S

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#8 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 17 August 2006 - 01:45 PM

<?php
$image = "<a href='test.php'><img src='images/standards/".$row[lam_number]-$row[lam_name]."_40.gif' alt='$row[1am_name]' /></a>";
?>

Give that a try, im not quite sure if your use of {} was causing a problem. I also replaced the escaped double quotes with singles to make it a bit easier to see if there was a problem

#9 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 17 August 2006 - 01:45 PM

How the hell.  I have been taught this whole time

"when Extrapolation variables, you DO NOT need the single quotes around the name of the variable."

Can someone please explain this too me I am confused, it worked, atleast the code works, where I can start making the pictures display, no errors, I always used {$_POST[variable]} when I am extrapolating, why did this happen, this makes me confused.


array?
I'm just a guy who likes to code for fun...

#10 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 17 August 2006 - 01:46 PM

It's because you have it encompassed in braces.

Valid formats:

<?php

$string = "blah$array[var]blah" . "blah${array['var']}blah" . "blah{$array['var']}blah"

?>


#11 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 August 2006 - 01:47 PM

It worked after that, I know it wouldnt have been the { } those are suppose to be used based on the manual, but the $row[variable] was suppose to be used when extrapolating, can someone explain this too me, this has almost knocked me off of my chair, this whole time I have been programming like that, getting into a bad habit, I was told, and read it's best and recommended to use this format when extrapolation

<?php
{$_POST[variable]}
{$_GET[variable]}
{$row[variable]} // or whatever variable your array was set too?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#12 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 August 2006 - 01:48 PM

Ok, so when you use brackets, you need the
' ' because I never needed those before, so it depends on my format
so if I use brackets, which I always do, then I need to include those single quotes around it everytime?

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#13 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 17 August 2006 - 01:53 PM

Your own post shows pretty much why :)

you have to specify indices by type and when you use braces, you are extrapolating the variable they encompass. Whe using braces, this reverts back to how you must use them on the php scope, as you should be able to see in your example, all three will throw a notice error because PHP will think you are specifying the Constant called 'variable' and not specifying the string value of 'variable'

e.g.:
<?php

$array['var'] = 'foo'; //indice is a String, as denoted by the apostrophies.

$string = "blah $array[var] blah"; //works - 'var' is still a string here, because the variable is within a string.

?>


#14 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 17 August 2006 - 02:18 PM

<?php
$image = "<a href=\"test.php\"><img src=\"images/standards/{$row['lam_number']}-{$row['lam_name']}_40.gif\" alt=\"{$row['1am_name']}\" /></a>";
?>

So pretty much what Jenk said, was that $row['lam_number'] is looking for the field name called lam_number

If you want to see the array of $row[]  then use
print_f($row);
and it will show you the names and their values :)



#15 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 02:24 PM

Ok, so when you use brackets, you need the ' '


No... When you use $foo['bar'] within a string you need the brackets, not the other way around.

And all non numerical array indexes should allways have quotes around them, they are string indexes so it makes perfect sense. Php howver is pretty forgiving in this area wich means they will work weither way most of the time. This is IMP a design floor.

#16 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 17 August 2006 - 02:50 PM

I see thanks for the advice, I walk away with new knowledge even today, thanks again.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users