Ninjakreborn Posted August 17, 2006 Share Posted August 17, 2006 [code]<?php$image = "<a href=\"test.php\"><img src=\"images/standards/\"{$row[lam_number]}-{$row[lam_name]}_40.gif\" alt=\"{$row[1am_name]}\" /></a>";?>[/code]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.[code]<?phpsession_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 belowif (!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>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/ Share on other sites More sharing options...
GingerRobot Posted August 17, 2006 Share Posted August 17, 2006 What is the exact error?I can see one problem:$image = "<a href=\"test.php\"><img src=\"images/standards/[b]\"[/b]{$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. Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76171 Share on other sites More sharing options...
Ninjakreborn Posted August 17, 2006 Author Share Posted August 17, 2006 [code]<?php$image = "<a href=\"test.php\"><img src=\"images/standards/{$row[lam_number]}-{$row[lam_name]}_40.gif\" alt=\"{$row[1am_name]}\" /></a>";?>[/code]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. Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76172 Share on other sites More sharing options...
Ninjakreborn Posted August 17, 2006 Author Share Posted August 17, 2006 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[quote]Parse error: parse error, unexpected T_STRING, expecting ']' in /homepages/30/d162063315/htdocs/zcart/fys/test.php on line 35[/quote]I just don't understand why it's not working. Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76174 Share on other sites More sharing options...
Jenk Posted August 17, 2006 Share Posted August 17, 2006 Just for the sake of it, try $row['lam_number'] instead of $row[lam_number] Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76177 Share on other sites More sharing options...
Ninjakreborn Posted August 17, 2006 Author Share Posted August 17, 2006 How the hell. I have been taught this whole time[quote]"when Extrapolation variables, you DO NOT need the single quotes around the name of the variable."[/quote]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. Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76180 Share on other sites More sharing options...
Ninjakreborn Posted August 17, 2006 Author Share Posted August 17, 2006 Actually I was told it was the safer, and recommended way?:S Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76181 Share on other sites More sharing options...
GingerRobot Posted August 17, 2006 Share Posted August 17, 2006 [code]<?php$image = "<a href='test.php'><img src='images/standards/".$row[lam_number]-$row[lam_name]."_40.gif' alt='$row[1am_name]' /></a>";?>[/code]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 Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76184 Share on other sites More sharing options...
Ifa Posted August 17, 2006 Share Posted August 17, 2006 [quote author=businessman332211 link=topic=104619.msg417367#msg417367 date=1155822170]How the hell. I have been taught this whole time[quote]"when Extrapolation variables, you DO NOT need the single quotes around the name of the variable."[/quote]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.[/quote]array? Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76185 Share on other sites More sharing options...
Jenk Posted August 17, 2006 Share Posted August 17, 2006 It's because you have it encompassed in braces.Valid formats:[code]<?php$string = "blah$array[var]blah" . "blah${array['var']}blah" . "blah{$array['var']}blah"?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76186 Share on other sites More sharing options...
Ninjakreborn Posted August 17, 2006 Author Share Posted August 17, 2006 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[code]<?php{$_POST[variable]}{$_GET[variable]}{$row[variable]} // or whatever variable your array was set too?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76187 Share on other sites More sharing options...
Ninjakreborn Posted August 17, 2006 Author Share Posted August 17, 2006 Ok, so when you use brackets, you need the' ' because I never needed those before, so it depends on my formatso if I use brackets, which I always do, then I need to include those single quotes around it everytime? Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76188 Share on other sites More sharing options...
Jenk Posted August 17, 2006 Share Posted August 17, 2006 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.:[code]<?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.?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76190 Share on other sites More sharing options...
SharkBait Posted August 17, 2006 Share Posted August 17, 2006 [code]<?php$image = "<a href=\"test.php\"><img src=\"images/standards/{$row['lam_number']}-{$row['lam_name']}_40.gif\" alt=\"{$row['1am_name']}\" /></a>";?>[/code]So pretty much what Jenk said, was that $row['lam_number'] is looking for the field name called lam_numberIf you want to see the array of $row[] then use [code=php:0] print_f($row); [/code] and it will show you the names and their values :) Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76198 Share on other sites More sharing options...
trq Posted August 17, 2006 Share Posted August 17, 2006 [quote]Ok, so when you use brackets, you need the ' '[/quote]No... When you use $foo['bar'] within a string you need the brackets, not the other way around.And [b]all[/b] non numerical array indexes should [b]allways[/b] 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. Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76203 Share on other sites More sharing options...
Ninjakreborn Posted August 17, 2006 Author Share Posted August 17, 2006 I see thanks for the advice, I walk away with new knowledge even today, thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/17838-typo-misprint/#findComment-76231 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.