2015-12-01 36 views
1

我有兩個PHP腳本,說「first.php」,它調用另一個PHP,「GET.PHP」腳本與GET值。轉換SQL結果集爲字符串,PHP

first.php使用GET方法調用second.php。

GET方法值是從數據庫中檢索的字符串。

first.php代碼

$someString = mysqli_query($connectionName,"SELECT someString from db where id=1"; 

/* Then the php redirects to ->" */ 

'mywebsite.com/PHP/second.php?data='.someString 

second.php

if(isset($_GET['data'])) 
{ 
    $new_data = $_GET['data']; 

} 

我的問題是,在 「someString」 的數據是在結果集的格式,所以我得到一個PHP錯誤的GET方法需要一個String值。

是否有任何可能的方式將sql結果集轉換爲字符串?

+0

您使用<形式行動=「mywebsite.com/PHP/second.php」>重定向恢復? –

回答

1

試試這個。

$someStringRes = mysqli_query($connectionName,"SELECT someString from db where id=1"; 

$row=mysqli_fetch_row($someStringRes); 

$someString = $row[0]; 

/* Then the php redirects to ->" */ 

'mywebsite.com/PHP/second.php?data='.someString 
0

如果PHP重定向意味着這將是簡單

<?php 
$res = mysqli_query($connectionName,"SELECT someString from db where id=1"; 
$row = mysql_fetch_row($res); 
$data=$row[0]; 
header('Location: mywebsite.com/PHP/second.php?data='.$data); 
?> 

OR
我假設你使用的形式採取行動,傳遞DATAS:試試這個

<?php 
$res = mysqli_query($connectionName,"SELECT someString from db where id=1"; 
$row = mysql_fetch_row($res); 
$data=$row[0]; 
?> 
<form action='mywebsite.com/PHP/second.php'> 
<input type="text" name="data" value="<?php echo $data;?>"> 
<input type="submit"> 
</form> 

現在的網址傳似這mywebsite.com/PHP/second.php?data=//value。您可以在

<?php 
$data=$_GET[data]; 
?>