2012-06-22 25 views
0

我認爲我的鑄造問題。使用PHP MYSQL組合鑄造問題

$db = mysqli_connect('127.0.0.1','root','password','test'); 
if (! $db) { die("Can't connect: " . mysqli_connect_error()); } 

$new_table = $_POST["newtablename"]; 
$old_table = $_POST["oldtablename"]; 
$numberRows = $_POST["numberrows"]; 
$startRow = $_POST["startrow"]; 
$counter = 0; 

drop_table($db, $new_table); 

create_table($db, $new_table); 

for($counter = 0; $counter < $numberRows; $counter += 1) 
{ 
    $currentRow = getRow($db, $old_table); 
    $ID = $currentRow(1); 
    $Partner = $currentRow(2); 
    $Merchant = $currentRow(3); 
} 

function getRow($db, $old_table) 
{ 
    $select = "SELECT ID, Partner, Merchant FROM " .$old_table; 
    $q = mysqli_query($db, $select); 
    $row = mysqli_fetch_row($q); 

    return $row; 
} 



function create_table($db, $new_table){ 
    $create = "CREATE TABLE " .$new_table. "(ID INT, Partner VARCHAR(20), Merchant  VARCHAR(30))"; 

    $q = mysqli_query($db, $create); 
} 

function drop_table($db,$new_table){ 
    $drop = "DROP TABLE IF EXISTS " .$new_table; 
    $q = mysqli_query($db, $drop); 
    } 

這是錯誤我得到

致命錯誤:函數名必須是在C字符串:\ XAMPP \ htdocs中\ myfiles的\ mysqli_combined_functions.php上線26

第26行是哪裏我設置了$ ID = $ currentRow(1)。我的印象是行將作爲一個變量數組返回,並使用適當的數字我可以訪問我想要的變量。假設這是真的(讓我知道如果沒有),那麼我認爲它是以INT的形式讀取ID,它就是我在SQL表中的內容。有人能幫我把它轉換成字符串嗎?或者我完全錯過了這個問題?

+0

投下類型爲字符串,你將使用$ VAR =(字符串)是$ var。 但是,我不知道你是如何試圖通過變量@ $ currentRow(1)傳遞一個值。 – Kermit

+0

你表面上無用的循環似乎佔據一行,將其值賦給變量,然後立即重新分配這些變量而不使用它們。你有沒有刪除一些代碼來縮短你的帖子?我正在使用的IDE上的設置 – Wiseguy

+0

已設置爲將所有內容更改爲括號。甚至沒有意識到這一點。多謝你們! – user1459268

回答

1

沒有鑄造。這些是數組索引,請注意方括號。 []

$currentRow = getRow($db, $old_table); 
    $ID = $currentRow[1]; 
    $Partner = $currentRow[2]; 
    $Merchant = $currentRow[3]; 
4

您可以使用方括號來訪問數組的元素。

$currentRow[1] 

記住第一個索引也是0。