Solved

PHP - Syntax passing record id

Posted on 2014-02-28
8
496 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

828 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