Jump to content


displaying individual recordset via php/mysql?

  • Please log in to reply
4 replies to this topic

#1 par15h

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 24 January 2006 - 02:19 PM

ok i am having a small problem, im sure its easy to over come and i still have not been able to manage it.

so i have

Recordset1 = database for composers

now i want to show the 2nd record, from the databse composers, on the page freely, without having to use tables

- Name {Recordset1.Name}
- Age {Recordset1.Age}
- Date {Recordset1.Date}
- Time {Recordset1.Time}
- Place {Recordset1.Place}

to show the first record at the moment, it is of course:

<?php echo $row_Recordset1['Name']; ?> = "John"

now say for instance i wanted to show the second record within the database on the page?

Record 1 = John 53 12/01/06 13:45 London
Record 2 = Paul 65 15/12/05 14:56 Kent

i want to show "Paul" not "John"

does anyone know how to go about this? or needs anymore information? please do help!

thank you

#2 azuka

  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts
  • LocationNigeria

Posted 25 January 2006 - 12:28 AM

There are two ways depending on what you need.
If you need just the second recordset then make your query like

"SELECT .......................... LIMIT 2,1"

If your're going to need all the results then here's a function I wrote to return an entire recordset as an array.
function mysql_fetch_all($sql)
        $q = mysql_query($sql); 
        if (!$q)
            //perform error checking
            return false;
            $x = array();
            $i = 0;            
            while ($row = @mysql_fetch_assoc($q))
               $x[$i] = $row;
            return $x;

Calling $recordset = mysql_fetch_all("SELECT * FROM ..........") returns an array with rows starting from 0.
To access row 2 column 'Name' simply use $recordset[1]['Name']. With this function you can even loop through the recordset.

Does this answer your question?
Note: If you're unsure how to use the returned array do something like:
echo "<pre>\n";
echo "\n</pre>";

That should show you how the array is structured.
Given enough eyeballs all bugs are shallow. My Website

#3 par15h

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 26 January 2006 - 01:26 AM

ah thank you, i do not need to show all the rows no, my initial thought is just to have scattered information from say row 3 on the page somewhere,... then show another row on another part of the page.. in another part of the design on the page.

im not to good with php, but with the information i have posted could you possible help me out and write the code i would need to show just row 2, and if i wish to show row 3 on another part of the page further down the design of the site.. what i would need to write?

thank you for reply and the help!

#4 Hybrid-Halo

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 13 August 2006 - 02:09 AM

After scouring the internet, I think that this thread holds the foundations for a solution I seek hence my bumping it.

My problem is simple, I'm calling data from a phpbb install into my design. The problem arises when I'm trying to display usernames which belong only to one certain group_id. Querying both phpbb_users and phpbb_user_group WHERE group_id = 107 seems to bring up many duplicate results.

In search of a solution I created two recordsets.
1 : queries phpbb_user_group WHERE group_id = 107.
This provides the correct amount of results alongside the user_id's.
2 : queries phpbb_users for user_id and username

Now what I want to do is display data from phpbb_users where user_id's are the same as the 15 or so displayed on the first recordset.

For the record : I've had no success implementing the array function above, though that could be because I am an absolute php novice and just don't know how to go about using it. The same excuse applies as to why I'm either missing the obvious, or making no sense.

If anyone's able to help or requires more information just ask.



#5 Hybrid-Halo

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 13 August 2006 - 03:55 AM

At 5am I found the solution.

The solution (as always) was simpler than I had expected. I spent a few hours reading up on SQL SELECT's and found that I just needed to be more specific with the query so as to avoid anonymous data problems impeding properly filtering the results. For future reference, here's my new query.

`phpbb_user_group` ,
'107' =  `phpbb_user_group`.`group_id` AND
`phpbb_users`.`user_id` =  `phpbb_user_group`.`user_id`
`phpbb_users`.`user_id` ASC

Night guys.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users