Jump to content

Link with Variable in Echo Statement


gunthertoody

Recommended Posts

I have to put a link that can be clicked around the first name and last name variables in the echo statement below.  I also need to add a variable from the Select query to the link such as: 'www.phpfreaks.com/admin/customers.php?page=1&cID="VARIABLE HERE" &action=edit'

 

I've tried a bunch of things and none seem to work.

 

 

while($row = mysql_fetch_array($result)){

 

 

echo '<tr><td>' . $row['customers_firstname'] . " " . $row['customers_lastname'] . '</td><td>' .

 

 

date("M. d, Y", strtotime($row['date'])) . '</td><td>' . $row['plan_id'] . '</td></tr>';

 

David

Link to comment
https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/
Share on other sites

Okay. I got the link to work, but only with a static ID. What is the proper syntax for a variable in the bold text? Do I have to qualify it somehow? The variable from the select statement is "customers_history.customers_id".

 

  $bg = ($bg=='#ffffff' ? '#e7e8e8' : '#ffffff'); //For Alternate Row Colors
   
   echo '<tr bgcolor="' . $bg . '"><td><a href="https://www.phpfreaks.com/admin/customers.php?page=1&cID=[b]['customers_history.customers_id'][/b]&action=edit">' . $row['customers_firstname'] . " " . $row['customers_lastname'] . '</a></td><td>' . date("M. d, Y", strtotime($row['date'])) . '</td><td>';

 

Okay, I think I got most of the syntax right, but how do I pull the variable (customers_history.customers_id) from the SELECT statement and make it populate in the link below?

 

$query = "SELECT customers_history.customers_id, customers_history.date, customers_history.status, customers_history.plan_id, customers.customers_firstname, customers.customers_lastname FROM customers_history LEFT JOIN customers ON customers_history.customers_id = customers.customers_id WHERE customers_history.status ='1' OR customers_history.status = '4' ORDER BY date DESC LIMIT 10";


echo '<tr bgcolor="' . $bg . '"><td><a href="https://www.example/admin/customers.php?page=1&cID=<?=[b]$customers_history.customers_id[/b]>&action=edit">' . $row['customers_firstname'] . " " . $row['customers_lastname'] . '</a></td><td>' . date("M. d, Y", strtotime($row['date'])) . '</td><td>';

Thanks, but I'm a novice and completely lost as to the proper syntax for a variable inside an href. What is the proper syntax?

 

echo '<tr bgcolor="' . $bg . '"><td><a href="https://www.example.com/admin/customers.php?page=1&cID=<?=$row['customers_history.customers_id'];?>&action=edit">' . $row['customers_firstname'] . " " . $row['customers_lastname'] . '</a></td><td>' . date("M. d, Y", strtotime($row['date'])) . '</td><td>';

I tend to like to keep some sort of structure, so I would tend to do something like:

echo "";
echo "";
echo "{$row['customers_firstname']} {$row['customers_lastname']}";
echo "";
echo "" . date('M. d, Y', strtotime($row['date'])) . "";
echo "";

Thanks. I'm learning bit by bit and I like the structure you put it in.

 

Regarding the functionality. It works except "customers_history.customers_id" won't populate into the browser. It goes straight from "ID=" to "&action".

 

I tend to like to keep some sort of structure, so I would tend to do something like:

echo "<tr bgcolor='{$bg}'>";
echo "<td>";
echo "<a href='https://www.example.com/admin/customers.php?page=1&cID={$row['customers_history.customers_id']}&action=edit'>{$row['customers_firstname']} {$row['customers_lastname']}</a>";
echo "</td>";
echo "<td>" . date('M. d, Y', strtotime($row['date'])) . "</td>";
echo "<td>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.