Jump to content

[SOLVED] Array help


adam291086

Recommended Posts

Hello, i have an array like the one below

 

Array ( [skill 1] => 1 [Education 2] => 17 [Education 3] => 1 [job 4] => 1 [EmploymentLevel 5] => 17 [EmploymentLevel 6] => 1 [ProQualificaition 7] => 1 [sector 8] => 1 )

 

 

The value of each section within the array equals a user id. What i want to do is look at all the values and count how many times a user appears in the above query for example user 1 appears 5 time and user 17 appears 2 times. I then want to display the users information in order of occurrence in the array for example user 1 above user 17. Can someone push me in the right direction.

 

I am an able coder but have no idea how to go about this.

 

 

Link to comment
Share on other sites

I have solved the above problem but i now has another array question.

 

i Have the following code

 

foreach (array_keys($search) as $key)
{
     $data = $db->get_results("SELECT * FROM persons WHERE idUser = '".$key."'",ARRAY_A);
     print_r($data);
}

 

this generates two arrays full of database information. I want to display one lot of information and have a button to view the second bit of information, something like pagination but with multiple arrays. Is this possible, if so how?

Link to comment
Share on other sites

okay if I read/understood that right, it sounds like you are grabbing more than one page worth of info from the db and want to paginate it.  The point of pagination is that you only grab one page worth of data at a time.  Think maybe you need to back up a few steps in your process and rethink the whole pulling stuff out of the db thing.  Or else, you need to be a bit more specific.

Link to comment
Share on other sites

I am making a simple search interface that searches multiple database tables. Within the tables it looks for the users id which is a foreign key. It then does some simple stuff with the array i.e count the number of times a user appears. I then search the database for each user within that array. In this case there is two, some times there could be three or more.

 

Therefore i want a way to only show each arrays information at a time. The once the user clicks next it shows the next array info. For example

Array ( [idUser] => 2 )

Array ( [idUser] => 4 )

 

so when the page first load is shows the idUser 2 info and then on a button click shows idUser 4 info

Link to comment
Share on other sites

ok i now have this

 

foreach (array_keys($search) as $key)
{
     $data = $db->get_results("SELECT * FROM persons WHERE idUser = '".$key."'",ARRAY_A);
     $pagination[$i] = $data;
     $i = $i + 1;
}

$resultID = 1;
$nextID = $resultID + 1;
echo '<a href="search.php?id='.$nextID.'">next</a>';
echo $_GET['id'];

if (isset($_GET['id']))
{
    $resultID = $_GET['id'];
    $nextID = $_GET['id'] + 1;
    echo '<pre>';
    print_r($pagination[$resultID]);
    echo '</pre>';

}
else
{
    echo '<pre>';
    print_r($pagination[$resultID]);
    echo '</pre>';

}

 

it shows the first lot of array data but when i click next nothing is displayed when i know there should be

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.