Solved

PHP - Syntax passing record id

Posted on 2014-02-28
8
490 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
  • 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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
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 look for a specific file type in a local or remote server directory using PHP.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now