2017-04-17 10 views
2

コード:?整数値を持つフィールドとphp/mysqlのテキストの場合にデータを表示する方法は?

私のデータベーステーブルで
<?php 
if($affiliated == '') 
{ 
    echo $affiliated; 
} 
else 
{ 
    $sql = "select * from all_university where university_id = '$affiliated'"; 
    $result = mysqli_query($link,$sql); 
    while ($row = mysqli_fetch_array($result)) 
    { 
     $short_name = $row['short_name']; 
    } 
} 

>

が所属フィールド名を持つと、それは1行が「整数」の値と別の持つ「テキスト」の値を持つ別の行に二つの異なる値を持ちます。私は別の値を表示したい、つまり整数値を持つ$ affiliatedの場合は整数の印刷テキストを印刷する。ですから、どうすればこの問題を解決できますか?

あなたが$affiliatedをチェックする必要が

+0

で私のコメントをご確認ありがとうございましたか! – hassan

+0

あなたは@kevinを試したことを表示できます –

答えて

0

まずnumericかではなく、あなたがこれまでにしようとしているものをすべての行

//check for integer 
    if (is_numeric($affiliated)) { 
     //condition for integer 
     // any number multiply by 1 equal to that number 
     $where = " WHERE concat('',university_id * 1) = university_id"; 
    } else { 
     //condition for text 
     $where = " WHERE concat('',university_id * 1) != university_id";// here use not equal to condition 
    } 
    $sql = "select * from all_university" . $where;// pass $where accouding to avove condition 
    $result = mysqli_query($link, $sql); 
    while ($row = mysqli_fetch_array($result)) { 
     $short_name = $row['short_name']; 
    } 
+0

ありがとうSaty。その仕事 – kevin

+0

You'r welcome !! enjoy – Saty

関連する問題