SQL comment with array element PHP

Banna360

This is my first question in this site hope that some one will help me over here.

I have a investor table with some fields and a project table with some files

Project table
---------------------
project_investor_id     1,26,29,30,39,48

data stored as , separated values So in my investor admin area i want show perticular project to show for logedin investor I am using this function.

public function list_all_projects_by_userid ($uid){


    $rs = mysql_query("select * from  project_table WHERE project_investor_id LIKE '$uid'  ORDER BY project_id DESC");    
    $i = 0;
    while ($row = mysql_fetch_assoc($rs)) {    
    $result[$i]['project_id'] = $row['project_id'];
    $result[$i]['project_investor_id'] = $row['project_investor_id'];
    $result[$i]['project_name'] = $row['project_name'];
    $result[$i]['project_location'] = $row['project_location'];
    $result[$i]['project_location'] = $row['project_location'];
    $result[$i]['project_phase'] = $row['project_phase'];
    $result[$i]['project_capital'] = $row['project_capital'];
    $result[$i]['project_notes'] = $row['project_notes'];
    $result[$i]['project_file'] = $row['project_file'];
    $i++;
    }
    return $result;
    }

But its not working with project have multiple investors. Please let me know how recode this?

Thank You

Viktor S.

Normally, you should have another mapping table for such things. And use joins to do a search.

If you want to make your approach work, you should change your sql request like this:

 $rs = mysql_query("select * from  project_table WHERE project_investor_id LIKE '%$uid%'  ORDER BY project_id DESC"); 

See % symbols added before and after $uid. It should work fine with that.

Also, remember about sql injections! You must escape your input. with mysql_* you can do it like this:

 $rs = mysql_query("select * from  project_table WHERE project_investor_id LIKE '%".mysql_real_escape_string($uid) . "%'  ORDER BY project_id DESC"); 

Function to escape: mysql_real_escape_string. Also, read carefully about what is shown in warning section of linked page.

But still, you should better put a list of project investors into a different table. It should be something lie this:

Project table
-------------
pr_id    pr_name


project investors map table
----------------------------
pr_id         investor_id
 1              1
 1              26
 1              29

And then, your request will be like:

$rs = mysql_query("select * from  project_table as pt join project_investor_map  as pi on pi.pr_id = pi.investor_id WHERE pi.investor_id = ".mysql_real_escape_string($uid) . "  ORDER BY project_id DESC");

which will take all projects of some investor

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Compare element of string array in php

분류에서Dev

How to delete an element inside a multidimensional array in PHP?

분류에서Dev

How to add two sql rows to a php array

분류에서Dev

Generate an array in PHP of random number not close to the X previous element

분류에서Dev

Create an Array and get Element, or part of String, in One Line - PHP

분류에서Dev

PHP sort array of associative arrays by element size / string size

분류에서Dev

Adding multiple returned MySQL rows to the same array key element in PHP

분류에서Dev

PHP array into individual php string, from SQL data

분류에서Dev

How to pass array from php sql to android list view?

분류에서Dev

SQL PHP ARRAY 에코 단일 배열

분류에서Dev

PHP Accessing Values quickly an Arrray holding objects which one element of the object has an array

분류에서Dev

Get three element from database using mysql_fetch_array and php

분류에서Dev

PHP With 2 arrays how do I get first element that exists in both arrays based on the order of the first array?

분류에서Dev

Add or update an array element

분류에서Dev

pointer to next element of an array

분류에서Dev

Multidimensional array to array in PHP

분류에서Dev

finding a specific array element and remove the container array

분류에서Dev

Finding an index of an element in a string array

분류에서Dev

How to remove whitespace in array element?

분류에서Dev

Elasticsearch Scripts to add element into an array

분류에서Dev

Need to add an element in a numpy array

분류에서Dev

Array only returns one element

분류에서Dev

PHP odbc_fetch_array fail when query has a join with same fieldname SQL server

분류에서Dev

Extract SVG file element with PHP

분류에서Dev

SQL query: where array is in array

분류에서Dev

PHP array in array - DXF script

분류에서Dev

Merge a php array and a php object

분류에서Dev

Json encode array with php - array() becomes "Array{...}" not "[...]"

분류에서Dev

Array Pointer in PHP

Related 관련 기사

  1. 1

    Compare element of string array in php

  2. 2

    How to delete an element inside a multidimensional array in PHP?

  3. 3

    How to add two sql rows to a php array

  4. 4

    Generate an array in PHP of random number not close to the X previous element

  5. 5

    Create an Array and get Element, or part of String, in One Line - PHP

  6. 6

    PHP sort array of associative arrays by element size / string size

  7. 7

    Adding multiple returned MySQL rows to the same array key element in PHP

  8. 8

    PHP array into individual php string, from SQL data

  9. 9

    How to pass array from php sql to android list view?

  10. 10

    SQL PHP ARRAY 에코 단일 배열

  11. 11

    PHP Accessing Values quickly an Arrray holding objects which one element of the object has an array

  12. 12

    Get three element from database using mysql_fetch_array and php

  13. 13

    PHP With 2 arrays how do I get first element that exists in both arrays based on the order of the first array?

  14. 14

    Add or update an array element

  15. 15

    pointer to next element of an array

  16. 16

    Multidimensional array to array in PHP

  17. 17

    finding a specific array element and remove the container array

  18. 18

    Finding an index of an element in a string array

  19. 19

    How to remove whitespace in array element?

  20. 20

    Elasticsearch Scripts to add element into an array

  21. 21

    Need to add an element in a numpy array

  22. 22

    Array only returns one element

  23. 23

    PHP odbc_fetch_array fail when query has a join with same fieldname SQL server

  24. 24

    Extract SVG file element with PHP

  25. 25

    SQL query: where array is in array

  26. 26

    PHP array in array - DXF script

  27. 27

    Merge a php array and a php object

  28. 28

    Json encode array with php - array() becomes "Array{...}" not "[...]"

  29. 29

    Array Pointer in PHP

뜨겁다태그

보관