Solved

PHP - Syntax passing record id

Posted on 2014-02-28
8
499 Views
Last Modified: 2014-02-28
Learning PHP and I don't have problems with the difficult concepts but the syntax is the worst language I have dealt with.  I can't get the passing of the URL id code to pass the syntax test.  I'm sure it is easy for experienced PHP coders -  If you notice the image code on the last line - I went through the same thing getting it to pass the syntax test.  I am modifying a program with a feature I want from another program and they coded things differently.

Thanks

  echo '<tr>';
                echo '<td>' . $i . '</td>';
		echo '<td>' <a href='info.php?id=".$row['id']."'>".$row['lastname']."</a>'</td>';
                echo '<td>' . $row['lastname'] . '</td>';
                echo '<td>' . $row['firstname'] . '</td>';
                echo '<td>' . $row['email'] . '</td>';
                echo '<td>' . $row['phonenumber'] . '</td>';
		echo '<td> <img src="'. $row['s_img']. '" width="102" height="111"/></td>';

Open in new window

0
Comment
Question by:JohnMac328
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39895579
                echo '<tr>';
                echo '<td>' . $i . '</td>';
		echo '<td> <a href="info.php?id='.$row['id'].'">'.$row['lastname'].'</a></td>';
                echo '<td>' . $row['lastname'] . '</td>';
                echo '<td>' . $row['firstname'] . '</td>';
                echo '<td>' . $row['email'] . '</td>';
                echo '<td>' . $row['phonenumber'] . '</td>';
		echo '<td> <img src="'. $row['s_img']. '" width="102" height="111"/></td>';

Open in new window

0
 

Author Comment

by:JohnMac328
ID: 39895582
Thats my question - I can't fix the syntax error
0
 
LVL 58

Expert Comment

by:Gary
ID: 39895594
The code is fixed in that comment

Sometimes it makes more sense to drop out of the PHP parse and do it this way.

%>
                <tr>
                <td><?=$i?></td>
		<td> <a href="info.php?id=<?=$row['id']?>"><?=$row['lastname']?></a></td>
                <td><?=$row['lastname']?></td>
                <td><?=$row['firstname']?></td>
                <td><?=$row['email']?></td>
                <td><?=$row['phonenumber']?></td>
		<td> <img src="<?=$row['s_img']?>" width="102" height="111"/></td>

Open in new window


(This is assuming open_tag is enabled)
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Author Comment

by:JohnMac328
ID: 39895612
I guess I better add more code since it is changing so much - so how would it work with all of this

 while ($row = mysql_fetch_array($sql)) {
                // Print out the contents of the entry 
				
				
                echo '<tr>';
                echo '<td>' . $i . '</td>';
		echo '<td>' <a href='info.php?id=".$row['id']."'>".$row['lastname']."</a>'</td>';
                echo '<td>' . $row['lastname'] . '</td>';
                echo '<td>' . $row['firstname'] . '</td>';
                echo '<td>' . $row['email'] . '</td>';
                echo '<td>' . $row['phonenumber'] . '</td>';
		echo '<td> <img src="'. $row['s_img']. '" width="102" height="111"/></td>';
                $i++;
            }
 } 
else 

Open in new window

0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39895636
while ($row = mysql_fetch_array($sql)) {
                // Print out the contents of the entry 
          	echo '<tr>';
                echo '<td>' . $i . '</td>';
		echo '<td><a href="info.php?id='.$row['id'].'">'.$row['lastname'].'</a></td>';
                echo '<td>' . $row['lastname'] . '</td>';
                echo '<td>' . $row['firstname'] . '</td>';
                echo '<td>' . $row['email'] . '</td>';
                echo '<td>' . $row['phonenumber'] . '</td>';
		echo '<td><img src="'. $row['s_img']. '" width="102" height="111"/></td>';
		echo '<tr>'; 
                $i++;
            }
 } 
else

Open in new window

0
 

Author Closing Comment

by:JohnMac328
ID: 39895656
Great thanks - Do you know of any good sites with examples of different PHP coding to decipher the syntax problem I am running into?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39895681
php.net has samples for all its functions.
Your problem above is very, very common when dealing with apostrophes and speech marks, even I screw up with it sometimes.
0
 

Author Comment

by:JohnMac328
ID: 39895691
Thanks Cathal!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to dynamically set the form action using jQuery.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question