2012-04-08 16 views
3

私はユーザIDからユーザの名前を教えてくれました。異なるユーザーIDはwhileループ内にあるので、関数は複数回使用されます。 1人のユーザーIDでうまく動作しますが、複数のユーザーIDがある場合はエラーが表示されます。 「:mysql_select_db():警告与えられた引数が有効なMySQLのリンクリソースではありません」というエラーがあるphp関数が複数回動作しません

コードが

<?php 

function user_details($user_id) { 

require_once('../Connections/runner.php'); 

if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string ($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 

$colname_users = $user_id; 
$first_name = ""; 
$last_name = ""; 
mysql_select_db($database_runner, $runner); 
$query_users = sprintf("SELECT first_name, last_name, profile_img_small FROM sign_up WHERE user_id = %s", GetSQLValueString($colname_users, "int")); 
$users = mysql_query($query_users, $runner) or die(mysql_error()); 
$row_users = mysql_fetch_assoc($users); 
$totalRows_users = mysql_num_rows($users); 
$first_name = $row_users['first_name']; 
$last_name = $row_users['last_name']; 
$profile_sml = $row_users['profile_img_small']; 

echo "$first_name $last_name"; 
} 



?> 

<?php 
$user_id = 10; 
?> 

<a href="*"><?php user_details("$user_id"); ?></a> 

<?php 
$user_id = 9; 
?> 

<a href="*"><?php user_details("$user_id"); ?></a> 

答えて

5

あなたが機能を実行するたびに、あなたがそのファイルを要求しようとしています1回だけ。既に必要とされている場合にはそれを必要としないと言っているので、それを無視する前ににはが必要です。したがって、これらの変数は、2回目に呼び出されたときには存在せず、関数は必然的に何もしません。私は完全にファイルがないので他のエラーを生成しないことに徹底的に驚いています。それは非常に重要ではありません。

+1

私は自分自身を悩ましています。それはそれを修正した。 – Jeff

+0

あなたの素早い返信をありがとう – Jeff

+0

@Jeffが成功した場合、答えを受け入れるべきです –

関連する問題