redhairgal Posted July 1, 2010 Share Posted July 1, 2010 I'm a newbie (and this is my first post) and I just can not see what I'm doing wrong with this echo line here's the code: echo "<select name=\"records\" style=\"width:155px;\"/>"; The problem is everything after the semi-colon to the next line semi-colon gets printed. Can someone who is not dog tired tell me what I did wrong? Thank you, red Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 1, 2010 Share Posted July 1, 2010 You probably need to show several lines before and after this line. Quote Link to comment Share on other sites More sharing options...
redhairgal Posted July 1, 2010 Author Share Posted July 1, 2010 Thank you AbraCadaver (LOL) here's the whole snippet: <?php include "./recordfx.inc"; $bd = recordlist(); echo "<select name=\"records\" style=\"width:155px;\"/>"; while ($row = mysqli_fetch_array($bd)){ echo ("<option value=\"" . $row[records] . "\">" . $row[records] . "</option>"); } echo ("</select>"); ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 1, 2010 Share Posted July 1, 2010 Let's simplify the echos by using single quotes instead of double quotes so there's less escaping: <?php include "./recordfx.inc"; $bd = recordlist(); echo '<select name="records" style="width:155px;"/>'; while ($row = mysqli_fetch_array($bd)){ echo '<option value="' . $row['records'] . '">' . $row['records'] . "</option>"; } echo "</select>"; ?> Does this still present the problem? Ken Quote Link to comment Share on other sites More sharing options...
redhairgal Posted July 1, 2010 Author Share Posted July 1, 2010 Thank you Ken, I changed to single quotes and the problem persists. The bizarre thing is that it works correctly in my debugger (Nusphere)! I don't know what to think. I've been stuck on this one thing for hours..... Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 1, 2010 Share Posted July 1, 2010 What is in recordfx.inc? Can you post the last several lines from that file? Quote Link to comment Share on other sites More sharing options...
rwwd Posted July 1, 2010 Share Posted July 1, 2010 Hi all, while ($row = mysqli_fetch_array($bd)){ echo '<option value="' . $row['records'] . '">' . $row['records'] . "</option>"; } could be replaced with: while ($row = mysqli_fetch_array($bd)){ ?> <option value="<?php echo $row['records'];?>"><?php echo $row['records']; ?></option> <?php } dipping in and out of php is less over head for the parser cpu to deal with, and it makes editing the html easier too, no need to escape the " quotes at all. Rw Quote Link to comment Share on other sites More sharing options...
travo1992 Posted July 2, 2010 Share Posted July 2, 2010 @rwwd that makes it harder to read the structures though. Execution time is cheap, man hours are expensive. Not to mention this is one of those microoptimisations which is almost negligible. @redhairgal just wondering why do you have <select ... /> on the first line? It should just be <select ... > Not sure if that will help... Quote Link to comment Share on other sites More sharing options...
redhairgal Posted July 2, 2010 Author Share Posted July 2, 2010 Thank you for all the help yesterday. I got so frustrated it reached the point I was hurting the code more than helping so I walked away. (Of course after trying all the suggested changes). Oh and the <select /> was a typo thank you for finding it but it didn't fix it I did figure out why the code wasn't working for some reason the mysql data isn't being put into place so the php/html shows because the expected data isn't substituted. For the life of me I can't figure out why the mysql data isn't be substituted. Could it be a state or scope issue? Dropping into and out of php how does that affect the scope of variables? The data is correctly pulled from the db but not inserted. I had to change from mysql to mysqli php connector but my mysqli calls seem to work in every other place but in this one? So I'm clearer on the problem but no closer to a solution. I wanted to thank you all for your generous help! Thanks again, red Quote Link to comment Share on other sites More sharing options...
redhairgal Posted July 2, 2010 Author Share Posted July 2, 2010 You guys are NOT going to believe this. But I finally got the code to work. Actually there was nothing wrong with the code the entire problem was a state issue. I kept thinking and finally REALIZED that loading a drop down list with items then allowing a selection was a 2 state action! I was trying to do this from an html file...... I changed my file extension to php and voila it all works.... 2 days wasted. Anyway you were all kind and generous about helping me and I learned from each and every response and cleaned up my code so it is much cleaner, thanks to all your input. But I just had to let you know what fixed it. LOL Thank you again, red Quote Link to comment Share on other sites More sharing options...
rwwd Posted July 2, 2010 Share Posted July 2, 2010 @ travo1992, "Execution time is cheap, man hours are expensive" CPU load on the parser is also an issue when you have high bandwidth issues, but I understand what you say, but having the html separated from the php like that means that during that time there would be a lot less load on the parser/CPU - more so if you have HUGE chunks of code being echo'd to screen this would be the better alternative IMO. @redhairgal - we all do that from time to time, cool as its sorted out now Rw Quote Link to comment Share on other sites More sharing options...
travo1992 Posted July 4, 2010 Share Posted July 4, 2010 @ rwwd I understand your point, however this is more relevant with larger, or even medium sized chunks of text. For smaller chunks of code, such as this, it is usually quicker (just) to just echo the code, rather than having php switch in and out I just tested to make sure I wasnt going to make a fool of myself, over 100000 reps of echoing 3 variables rather than html with inline php, echoing the lot is approx 40ms quicker. Inline PHP actually peaked higher cpu usage, showing that you need to take the context into account before you apply optimisations. Saying that, for this it probably doesnt really matter too much anyway @redhairgal that'll do it to you hehe, glad you worked it out. Quote Link to comment 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.