DeFActo Posted April 2, 2008 Share Posted April 2, 2008 Hello all, i have a code $query = "SELECT * FROM table_name WHERE id='$name'" could anyone help me how to do so that if i push different links like: capsa, capsa1, capsa2 that link name appears instead of $name? Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/99137-solved-variables-in-select-statement/ Share on other sites More sharing options...
mkoga Posted April 2, 2008 Share Posted April 2, 2008 try $query = sprintf("SELECT * FROM table_name WHERE id='%s'", $name); Quote Link to comment https://forums.phpfreaks.com/topic/99137-solved-variables-in-select-statement/#findComment-507220 Share on other sites More sharing options...
DeFActo Posted April 3, 2008 Author Share Posted April 3, 2008 that is what i got: <?php $link = mysql_connect(' ', ' ', ' '); mysql_select_db('kolekcijos'); function pirma(){ $query = "SELECT * FROM gylis WHERE id= "; $result=mysql_fetch_assoc($query); if ($result) { $a=$result['gylis4']; echo "$a"; } else{ echo "There is no such a record."; } } if (isset($_GET["name"])) $name = mysql_real_escape_string($_GET["name"]) or die ("nera"); if (isset($name)) echo "$name"; if (isset($name)) pirma(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " "> <html xmlns=" "> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Title</title> <style type="text/css"> </style> </head> <body> <table width="300px"> <tr> <td width="100px"><a href="result2.php?name=Capsa">Capsa</a> </td> <td></td> </tr> <tr> <td width="100px">Capsa1</td> <td></td> </tr> <tr> <td width="100px">Capsa2</td> <td></td> </tr> </table> </body> </html> but i need somehow to put that $name here: $query = "SELECT * FROM gylis WHERE id= "; and result $a here: <td width="100px">Capsa</td> <td> result </td> Any hint, please? Quote Link to comment https://forums.phpfreaks.com/topic/99137-solved-variables-in-select-statement/#findComment-508210 Share on other sites More sharing options...
DeFActo Posted April 3, 2008 Author Share Posted April 3, 2008 i've found some mistakes and updated the code: <?php $link = mysql_connect(' ', ' ', ' '); mysql_select_db(' '); if (isset($_GET["name"])) $name = mysql_real_escape_string($_GET["name"]) or die ("nera"); if (isset($name)) echo "$name"; if (isset($name)) { $sql = "SELECT * FROM gylis WHERE id='$name'"; $query = mysql_query($sql); $result=mysql_fetch_assoc($query); if ($result) { $a=$result['gylis4']; echo "$a"; } else{ echo "There is no such a record."; }; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " "> <html xmlns=" "> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Title</title> <style type="text/css"> </style> </head> <body> <table width="300px"> <tr> <td width="100px"><a href="result2.php?name=capsa">Capsa</a> </td> <td></td> </tr> <tr> <td width="100px">Capsa1</td> <td></td> </tr> <tr> <td width="100px">Capsa2</td> <td></td> </tr> </table> </body> </html> only thing i need is to get result $a in here: <tr> <td width="100px"><a href="result2.php?name=Capsa">Capsa</a> </td> <td> result </td> </tr> help please, because i am out of imagination Quote Link to comment https://forums.phpfreaks.com/topic/99137-solved-variables-in-select-statement/#findComment-508513 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.