Echo text by many variables in php [closed]
I have 3 vars, which are forwarded by php (index.php?a=v1&&b=v6&&c=v10)
Now I want to echo a text (from mysql) by these specific vars.
mysql-table:
index.php?a=v1&&b=v6&&c=v10
id | 1
variable1 | "v1"
variable2 | "v6"
variable3 | "v10"
text | "this is the text for v1&v6&v10"
index.php?a=v3&&b=v8&&c=v12
id | 2
variable1 | "v3"
variable2 | "v8"
variable3 | "v12"
text | "this is the text for v3&v8&v12"
what is the mysql-query?
$query = "SELECT * FROM text_table WHERE ???;";
<a href="index.php?a=v1&b=v6&c=v10">Link 1</a>
<?php
if(isset($_GET)){
foreach($_GET as $key=>$value){
if(get_magic_quotes_gpc()) {
$value=stripslashes($value);
}
$_GET[$key]=mysql_real_escape_string($value);
}
}
$query = mysql_query('SELECT *
FROM my_table
WHERE a LIKE '.$_GET['a'].'
AND b LIKE '.$_GET['b'].'
AND c LIKE '.$_GET['c']);
if(mysql_num_rows($query)>=1){
while($row=mysql_fetch_assoc($query)){
$a = $row['a'];
$b = $row['b'];
$c = $row['c'];
echo "This is the text for {$a}&{$b}&{$c}";
}
}else{
echo 'No results';
}
?>
$query = mysql_query('SELECT * FROM my_table WHERE a = '.$_GET['a'].' AND b = '.$_GET['b'].' AND c = '.$_GET['c']);
$affectedRows = mysql_affected_rows();
for($i = 0; $i < $affectedRows; $i++){
$currentResult = mysql_fetch_assoc($query);
$a = $currentResult['a'];
$b = $currentResult['b'];
$c = $currentResult['c'];
echo "this is the text for {$a}&{$b}&{$c}";
}
If that is what you are asking for. If you need to insert those values, use this query:
mysql_query('INSERT INTO my_table SET a = "'.$_GET['a'].'", b = "'.$_GET['b'].'", c = "'.$_GET['c'].'" ');
Which, however, is quite insecure. I'd recommend, before inserting these values, do following:
$sqlA = mysql_real_escape_string($_GET['a']);
$sqlB = mysql_real_escape_string($_GET['b']);
$sqlC = mysql_real_escape_string($_GET['c']);
mysql_query('INSERT INTO my_table SET a = "'.$sqlA.'", b = "'.$sqlB.'", c = "'.$sqlC.'" ');
SELECT
a,
b,
c,
'This is the text for ' + a + '&' + b + '&' + c
FROM mysql-table
Is this what you want?
精彩评论