radio button link

lameduck

Solid State Member
Messages
9
Location
under a bridge
Hi, another fun project:
I'm printing a list from a table alternating line colors. I'm including
a radio button on each line to link to the URL "target". I've greatly
edited offerings from the net and all is well except that the buttons
do nothing. I don't understand the line:
echo "<input type=\"radio\" name=\"select\" value=\"{$res['target']}\">";
Thanks for any help!

Code:
<!DOCTYPE html><html>
<head>
<title>Email Visits</title>
</head>
<body><center>
 <form id="testform" name="testform" action="" method="post" 
accept-charset="UTF-8">
PHP:
  <?php
$host="localhost"; $username="root"; $password="cookie"; 
$db_name="homedb"; $tbl_name="emailtbl";

/* Connect to server and select databse */
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Define $count
$count = "";

$sql="SELECT * FROM emailtbl ORDER BY target ASC";
$result=mysql_query($sql);

echo '<table border="1" cellspacing="0">';
while($res=mysql_fetch_assoc($result))
 {
// Add 1 to the row count
    $count=$count + "1";

/* -------------If $count==1 table row color = #FFC600 ----------*/
    if($count=="1")
    { echo "<tr bgcolor='#FFC600'>"; }

/* -------------If $count==2 table row color = #ccffff ----------*/
    if($count=="2")
    { echo "<tr bgcolor='#ccffff'>"; $count=$count - "2"; }

echo "<td>";
echo "<input type=\"radio\" name=\"select\" value=\"{$res['target']}\">";
echo "</td>";
echo "<td>";echo $res['target'];echo "</td>";
echo "<td>";echo $res['username'];echo "</td>";
echo "<td>";echo $res['password'];echo "</td>";
echo "<td>";echo $res['emailused'];echo "</td>";
echo "<td>";echo $res['lastused'];echo "</td>";
echo "<td>";echo $res['purpose'];echo "</td>";
echo "<td>";echo $res['visits'];echo "</td>";
echo "<td>";echo $res['saved'];echo "</td>";
echo "</tr>";

 }
echo '</table>';
mysql_close();
?>
Code:
  </table> </form></body></html>
 
That line builds the link radiobutton from the $res variable retrieved by PHP from MySQL.

It's expecting a field to be in the DB named 'target' which contains your link that you want. That line then sets the value of each radio button to the 'target' field from from $res from each row from the DB.
 
That line builds the link radiobutton from the $res variable retrieved by PHP from MySQL.
It's expecting a field to be in the DB named 'target' which contains your link that you want. .

Thanks, I understand that. You had me lost at first with: "It's expecting a field to be in the DB named 'target' which contains your link that you want."

It's expecting a field named 'target' which contains your link that you want, to be in the DB.
I can copy the "target" (URL) and paste it in the task bar but I want to click that line's button and go there. I just don't know how to change the code of that line to do that?
 
Do you have a database that this is hooked up to? if so, what does your table structure look like that it's tied to?
 
emailtbl
Column Type Null Default Comments MIME
id int(2) No
target varchar(40) No
username varchar(30) No
password varchar(20) No
emailused varchar(40) No
lastused date No
visits int(3) No
purpose varchar(15) No
saved varchar(1) No
IndexesDocumentation
Keyname Type Unique Packed Column Cardinality Collation Null Comment
PRIMARY BTREE Yes No id 65 A No
 
So are you wanting the radio button to navigate to the URL when you click it? In the same window or a new window? You can do this via the onClick. Something like this:

Code:
<input type=\"radio\" name=\"select\" onclick=\"window.open('$res['target']');\">
 
I thank you for your help. The code suggested gives this:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\home\email_report.php on line 38
 
Looks like an issue with the quotes - you'll have to play with it to get the quotes working; I don't have a PHP parser/server running at the moment.
 
Back
Top Bottom