Click here to Skip to main content
15,353,841 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more:
I am developing a Website Where I need to register users, for that I develop a simple HTML Form and use PHP to send data in MYSQL Database, its working perfectly.

But now I need display those profiles[stored in MYSQL Database] one after another
Photo                 Profile ID : 1
                      Name : MR. Abc XYz
                      Address : fghgf
                      Qualification: gjhgf

PHOTO                Profile ID :2
                     Name:  mno  pqo

PHOTO                Profile ID :3
                     Name:  bbbb hhhh

One page will contain 6-7 profile and then next 6-7 to 2nd page and so on.

This is my problem.
I know its not possible to provide Code for this problem in CodeProject, but please some knowledge or some Links will be help full for me.
Please share your valuable knowledge and please help me.
Updated 3-Sep-12 21:21pm
[no name] 3-Sep-12 14:32pm
1 down rating 1 up rating.
please don't rate
please answer or comment for any clarification
Mohibur Rashid 3-Sep-12 20:43pm
I wont rate. But I will give you a link.
Mohibur Rashid 4-Sep-12 4:40am
The point is not informing you about google. it was reminding you about searching online. Most people make a common mistake. if you search your problem you will get solution in 99.99% (its not literal) cases. break down your problems into small pieces and then search online. that was my point.
[no name] 4-Sep-12 5:42am
you are a Genius, to solve your problem through google.
great man.
why you are wasting your time in codeproject then.
go and join google.
enhzflep 4-Sep-12 7:32am
Now, now - there's no need to make a sunshine of yourself.
Mohibur's tongue-in-cheek suggestion is perfectly valid. It is unfortunate that his point appears too complex and has been lost on you.

The fact that you see an insult as a fit response to his suggestions further underscore the point.

I suggest you read a copy of Dale Carnegie's book. ;)
enhzflep 3-Sep-12 21:15pm
What exactly is your problem? (it's not clear)
Is it: obtaining 6 or 7 records?
Is it determining which 6 or 7 records?
Is it in displaying the data?
Is it in retrieving the data?

Please use google OR the time required to clearly explain your problem!
[no name] 4-Sep-12 2:51am
only the looks and display 6-7 records in a page.
enhzflep 4-Sep-12 3:10am
Following the format you've used in your question:

$sql = "select some stuff limit $firstEntryToShow $lastEntryToShow";
$result = mysql_query($sql);
while ($row = mysql_fetch_row($result))
$photoSrc = $row[0];
$profileId = $row[1];
$name = $row[2];
$address = $row[3];
$qualif = $row[4];

echo '<table>';
echo '<tbody>';
echo "<tr>";
echo "<td><img src='$photoSrc'/></td>";
echo "<td>Profile ID: $profileId<br>Name: $name<br>Address: $address<br>Qualification: $qualif</td>";
echo '</tr>';
echo '</tbody>';
echo '</table>';

Obviously, you'll need to (a) use the right sql for your situation (b) alter the code that extracts results from the query-result record-set. It's most unlikely your photo's src would be the first column in the table, for instance.
[no name] 4-Sep-12 3:19am
ok great idea. Thanks. But first 7 records in 1st page and next 7 record in 2nd page and , next 7 records in 3rd page and so one. Please help me regarding this.
enhzflep 4-Sep-12 3:33am
I already asked you that! You indicated it wasn't a problem...
Never the less, let's think about it for a sec.. - page0 will display results 0-6, page1 will display results 7-13 et, etc.
$firstEntry = $pageNumber * 7;
$lastEntry = $firstEntry + 7;

You need to look up the SQL keyword LIMIT. You'll also need to pass the desired pageNumber to the page as either a GET or a POST variable - GET would be the more appropriate - it's not a request that creates/changes data. Also, it gives the user a 'hackable' URL - a URL they can predictably hand-enter.
You can see that when you visit page 2 of Quick Answers, for instance.
Notice the &pgnum=2 part?
[no name] 4-Sep-12 3:40am
URL writing is possible in PHP like in ASP.NET.
in ASP.NET there is a concept called queryString, is there something in PHP like QueryString.
enhzflep 4-Sep-12 3:50am
No idea.
What's it used for? What's it got to do with the original question?

You *want* the url to contain data that tells you which page to display.
[no name] 4-Sep-12 4:01am
I am carrying your idea!
"?tab=active&pgnum=2" is called QueryString in ASP.NET.
is there is anything in PHP?
enhzflep 4-Sep-12 4:18am
Sure, you can get any variables passed via the URL in the $_GET array.
There is 1 entry for each variable, the value is accessed by using the variable name as an index into the $_GET array.

Using the url for Quick Answers page 2, you'd have two entries in the array. $_GET['tab'] and $_GET['pgnum']

Try this example on your server, using the following url (replace the directory name as appropriate)
You should get a page that contains the following 2 lines.

TAB = active
PAGE = 1

--------getOpts.php --------

$tab = $_GET['tab'];
$pageNum = $_GET['pgnum'];


<!doctype html>
echo "TAB = ".$tab . "<br>";
echo "PAGE = ".$pageNum . "<br>"
[no name] 4-Sep-12 5:46am
ok, got it
I need to study a little bit more.
You post your codes in solution part, so that I accept the Solution.
You gave me 100%, to start with.

1 solution

As per the comments I added earlier, there's a number of things to keep in mind here.

You need to know:
(1) Which 'page' you'd like to display
(2) How many results you'd like to display on each page.

I've chosen to display the information for each user in a single-row html table. The first cell contains an image, while the second cell contains text information.

I've used single quotes - ' wherever the string doesn't need interpreting. I've used double-quotes " whenever the string contains a php variable that should be substitued by it's value. (It's faster to use single quotes, more functional to use double quotes) - You should consider the code that outputs the image as being wrapped in double-quotes. In this case the string contains an interpreted value inside of single quotes. This will equate to single quotes wrapped around some text value.

$sql = "select some stuff limit $firstEntryToShow $lastEntryToShow";
$result = mysql_query($sql);
while ($row = mysql_fetch_row($result))
    $photoSrc = $row[0];
    $profileId = $row[1];
    $name = $row[2];
    $address = $row[3];
    $qualif = $row[4];

    echo '<table>';
    echo '<tbody>';
    echo "<tr>";
    echo "<td><img src='$photoSrc'/></td>";
    echo "<td>Profile ID: $profileId<br>Name: $name<br>Address: $address<br>Qualification: $qualif</td>";
    echo '</tr>';
    echo '</tbody>';
    echo '</table>';

You can set the $firstEntryToShow by taking a variable that specifies which page you'd like to view, and multiplying that value with the number of records your'd like to display on each page. You can then calculate $lastEntryToShow by adding $numEntriesPerPage-1 to $firstEntryToShow.

Note: the code below assumes that the url contains a variable named pgnum
$pageNumber = $_GET['pgnum'];
$numEntriesPerPage = 7;
$firstEntryToShow = $pageNumber * $numEntriesPerPage;
$lastEntryToShow = $firstEntryToShow + ($numEntriesPerPage-1);

You can use isset to see if the variable has been given.
if (isset($_GET['pgnum']))
   $pageNum = $_GET['pgnum'];
   $pageNum = 0;
[no name] 4-Sep-12 7:18am
Don't delete the comments part, its neccessary for me to build my project.
Thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900