gunthertoody Posted February 9, 2011 Share Posted February 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/ Share on other sites More sharing options...
Maq Posted February 9, 2011 Share Posted February 9, 2011 I don't see anything that relates to creating this URL. You have an example of exactly what the URL should look like, echo out the 'a' tag. Look at the structure of the 'a' element: http://www.w3schools.com/tags/tag_a.asp Quote Link to comment https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/#findComment-1171934 Share on other sites More sharing options...
gunthertoody Posted February 9, 2011 Author Share Posted February 9, 2011 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/#findComment-1171941 Share on other sites More sharing options...
gunthertoody Posted February 9, 2011 Author Share Posted February 9, 2011 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/#findComment-1171957 Share on other sites More sharing options...
Maq Posted February 9, 2011 Share Posted February 9, 2011 Please use tags in the future please. Quote Link to comment https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/#findComment-1171984 Share on other sites More sharing options...
gunthertoody Posted February 9, 2011 Author Share Posted February 9, 2011 okay. Quote Link to comment https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/#findComment-1171995 Share on other sites More sharing options...
Maq Posted February 9, 2011 Share Posted February 9, 2011 The same way you pulled 'customers_firstname' and 'customers_lastname'. Quote Link to comment https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/#findComment-1171997 Share on other sites More sharing options...
gunthertoody Posted February 9, 2011 Author Share Posted February 9, 2011 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/#findComment-1172044 Share on other sites More sharing options...
Maq Posted February 9, 2011 Share Posted February 9, 2011 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 ""; Quote Link to comment https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/#findComment-1172053 Share on other sites More sharing options...
gunthertoody Posted February 10, 2011 Author Share Posted February 10, 2011 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/227187-link-with-variable-in-echo-statement/#findComment-1172108 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.